Skip to content

[WIP] feat: default to kubelet identity when AzureStorageIdentityClientID is empty for MSI auth#2430

Open
andyzhangx wants to merge 4 commits into
kubernetes-sigs:masterfrom
andyzhangx:default-kubelet-identity-msi
Open

[WIP] feat: default to kubelet identity when AzureStorageIdentityClientID is empty for MSI auth#2430
andyzhangx wants to merge 4 commits into
kubernetes-sigs:masterfrom
andyzhangx:default-kubelet-identity-msi

Conversation

@andyzhangx
Copy link
Copy Markdown
Member

What type of PR is this?
/kind feature

What this PR does / why we need it:
When AzureStorageAuthType is set to MSI but AzureStorageIdentityClientID is not specified, the driver now:

  1. Defaults to the kubelet identity (UserAssignedIdentityID from cloud config) — this is the built-in managed identity bound to the AKS agent node pool (named {cluster-name}-agentpool)
  2. Returns a clear error if the kubelet identity is also not available, instead of silently proceeding and failing at mount time with a cryptic error

This improves the user experience for the common case where users set AzureStorageAuthType: MSI in their PV/StorageClass but forget to specify the identity client ID — the driver will automatically use the kubelet identity if available.

How does this PR make you feel?
Less cryptic mount failures 🎉

Does this PR introduce a user-facing change?

When AzureStorageAuthType is set to MSI and AzureStorageIdentityClientID is not specified, the driver defaults to the kubelet identity. If no identity is available, a clear error is returned.

…s empty for MSI auth

When AzureStorageAuthType is set to MSI but AzureStorageIdentityClientID is not
specified, the driver now defaults to the kubelet identity (UserAssignedIdentityID
from cloud config). If the kubelet identity is also not available, the driver
returns a clear error instead of silently proceeding and failing at mount time.
@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Apr 27, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 27, 2026
@k8s-ci-robot k8s-ci-robot requested review from cvvz and feiskyer April 27, 2026 13:52
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds stricter MSI-auth identity selection in GetAuthEnv to improve failure clarity when an identity isn’t explicitly provided, aligning behavior with a “default to kubelet identity” expectation in AKS-style setups.

Changes:

  • Default MSI mounts to UserAssignedIdentityID from cloud config when no AZURE_STORAGE_IDENTITY_* env is already set.
  • Return an early, clearer error when MSI is selected but neither an explicit identity nor a kubelet identity is available.
  • Add unit tests covering the new defaulting and error behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/blob/blob.go Changes MSI auth env construction: default to kubelet identity or return a clearer error when missing.
pkg/blob/blob_test.go Adds tests validating kubelet-identity defaulting and the new “no identity available” error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/blob/blob.go Outdated
Comment thread pkg/blob/blob.go Outdated
Comment thread pkg/blob/blob_test.go
Comment thread pkg/blob/blob.go Outdated
@andyzhangx andyzhangx requested a review from Copilot April 27, 2026 14:20
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/blob/blob.go
Comment on lines +757 to 759
if strings.EqualFold(azureStorageAuthType, storageAuthTypeMSI) {
// check whether authEnv contains a non-empty AZURE_STORAGE_IDENTITY_ value
containsIdentityEnv := false
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

azureStorageAuthType is compared using == storageAuthTypeMSI, but docs/examples commonly set AzureStorageAuthType: MSI (uppercase). This means the MSI-specific identity defaulting/error path won’t run for those values. Use strings.EqualFold(azureStorageAuthType, storageAuthTypeMSI) here (consistent with the earlier secret-handling check) and add/adjust a unit test to cover uppercase MSI.

Copilot uses AI. Check for mistakes.
Comment thread pkg/blob/blob.go
Comment on lines +771 to +774
if !containsIdentityEnv {
if d.cloud != nil && d.cloud.Config.AzureAuthConfig.UserAssignedIdentityID != "" {
klog.V(2).Infof("MSI auth: AzureStorageIdentityClientID not specified, default to kubelet identity (%s)",
d.cloud.Config.AzureAuthConfig.UserAssignedIdentityID)
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes MSI auth fail fast when neither AzureStorageIdentityClientID nor cloud.Config.AzureAuthConfig.UserAssignedIdentityID is set. That can be a breaking behavior change for clusters that rely on system-assigned MSI/IMDS (where omitting the client ID can still be valid). If the intention is to preserve IMDS fallback, consider logging a warning and continuing instead of returning an error; otherwise, please update the public docs/parameters to reflect that an identity client ID (explicit or kubelet) is now required for AzureStorageAuthType=MSI.

Copilot uses AI. Check for mistakes.
Comment thread pkg/blob/blob_test.go
_, _, _, _, _, err := d.GetAuthEnv(context.TODO(), volumeID, "", attrib, secret) //nolint:dogsled
assert.NoError(t, err) // should not error, falls back to IMDS
}

Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new MSI defaulting behavior isn’t covered for two important inputs that occur in docs/config: (1) AzureStorageAuthType: MSI (uppercase), and (2) AzureStorageIdentityClientID present but empty/whitespace. Adding targeted unit tests for these cases will prevent regressions and will catch the current case-sensitivity/empty-value pitfalls.

Suggested change
func TestGetAuthEnvMSIDefaultsToKubeletIdentityWhenClientIDWhitespace(t *testing.T) {
d := NewFakeDriver()
d.cloud = &storage.AccountRepo{}
d.cloud.Config.AzureAuthConfig = azclient.AzureAuthConfig{
UserAssignedIdentityID: "kubelet-identity-client-id",
}
attrib := map[string]string{
containerNameField: "containername",
storageAccountField: "accountname",
storageAuthTypeField: storageAuthTypeMSI,
storageIdentityClientIDField: " ",
}
secret := map[string]string{
accountNameField: "accountname",
accountKeyField: "testkey",
}
volumeID := "rg#accountname#containername"
_, _, _, _, authEnv, err := d.GetAuthEnv(context.TODO(), volumeID, "", attrib, secret) //nolint:dogsled
assert.NoError(t, err)
found := false
for _, env := range authEnv {
if env == "AZURE_STORAGE_IDENTITY_CLIENT_ID=kubelet-identity-client-id" {
found = true
break
}
}
assert.True(t, found, "Should default to kubelet identity when AzureStorageIdentityClientID is empty or whitespace")
}

Copilot uses AI. Check for mistakes.
@andyzhangx
Copy link
Copy Markdown
Member Author

/retest

1 similar comment
@andyzhangx
Copy link
Copy Markdown
Member Author

/retest

@andyzhangx andyzhangx changed the title feat: default to kubelet identity when AzureStorageIdentityClientID is empty for MSI auth [WIP] feat: default to kubelet identity when AzureStorageIdentityClientID is empty for MSI auth Apr 28, 2026
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants