Skip to content

feat: support mount smb file share with workload identity token#2902

Merged
andyzhangx merged 3 commits intomasterfrom
wi-token
Feb 4, 2026
Merged

feat: support mount smb file share with workload identity token#2902
andyzhangx merged 3 commits intomasterfrom
wi-token

Conversation

@andyzhangx
Copy link
Copy Markdown
Member

What type of PR is this?
/kind feature

What this PR does / why we need it:
feat: support mount smb file share with workload identity token

Which issue(s) this PR fixes:

Fixes #

Requirements:

Special notes for your reviewer:

Release note:

none

@andyzhangx andyzhangx requested a review from Copilot December 17, 2025 02:59
@k8s-ci-robot k8s-ci-robot added 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 17, 2025
@k8s-ci-robot k8s-ci-robot requested review from cvvz and gnufied December 17, 2025 02:59
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 17, 2025
Copy link
Copy Markdown

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

This PR adds support for mounting Azure SMB file shares using workload identity tokens instead of storage account keys. This enhances security by allowing Kubernetes workloads to authenticate using federated identity credentials rather than long-lived secrets.

  • Introduces mountWithWITokenField parameter to enable workload identity token-based authentication
  • Extends GetAccountInfo to return tenantID and tokenFilePath for workload identity flows
  • Adds token parsing, validation, and file-based caching for service account tokens

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 19 comments.

Show a summary per file
File Description
pkg/azurefile/azurefile.go Core implementation: adds workload identity token handling in GetAccountInfo, including token parsing, validation, and file-based storage; extends return signature with tenantID and tokenFilePath
pkg/azurefile/utils.go Updates setCredentialCache to support both managed identity and workload identity modes via azfilesauthmanager; adds isValidTokenFileName helper for token file validation
pkg/azurefile/nodeserver.go Implements workload identity logic in NodeStageVolume and NodePublishVolume; adds useWorkloadIdentity helper to determine authentication method; configures Kerberos mount options for workload identity
pkg/azurefile/controllerserver.go Handles mountWithWITokenField parameter in CreateVolume; maps to IsSmbOAuthEnabled flag; updates GetAccountInfo call sites for new signature
pkg/azurefile/azurefile_test.go Adds test case for invalid mountWithWITokenField value validation
pkg/azurefile/utils_test.go Updates TestSetCredentialCache for new parameter handling; adds TestIsValidTokenFileName with comprehensive validation cases
pkg/azurefile/nodeserver_test.go Adds TestUseWorkloadIdentity to verify workload identity detection logic
pkg/azurefile/controllerserver_test.go Adds test for invalid mountWithWIToken parameter; includes mountWithWITokenField in comprehensive parameter test
pkg/azurefileplugin/Dockerfile Installs azfilesauth package for Kerberos authentication support via azfilesauthmanager
deploy/csi-azurefile-driver.yaml Enables requiresRepublish and configures token requests with 1-hour expiration for workload identity
test/e2e/testsuites/*.go Updates e2e tests for GetAccountInfo signature changes (adds tenantID and tokenFilePath return values)
Comments suppressed due to low confidence (2)

pkg/azurefile/utils_test.go:1398

  • The TestSetCredentialCache test only covers error cases and doesn't test the successful execution paths. It should include test cases for: (1) successful call with clientID but no token (managed identity mode), and (2) successful call with both clientID and tokenFile (workload identity mode). These tests would verify that the correct command arguments are constructed for each authentication method.
func TestSetCredentialCache(t *testing.T) {
	tests := []struct {
		desc          string
		server        string
		clientID      string
		token         string
		expectedError string
	}{
		{
			desc:          "empty server",
			server:        "",
			clientID:      "test-client-id",
			expectedError: "server must be provided",
		},
		{
			desc:          "empty clientID and token",
			server:        "test.file.core.windows.net",
			clientID:      "",
			token:         "",
			expectedError: "either clientID or tokenFile must be provided",
		},
		{
			desc:          "both empty",
			server:        "",
			clientID:      "",
			expectedError: "server must be provided",
		},
	}

	for _, test := range tests {
		_, err := setCredentialCache(test.server, test.clientID, "", test.token)
		if test.expectedError != "" {
			if err == nil {
				t.Errorf("test[%s]: expected error containing %q, got nil", test.desc, test.expectedError)
			} else if !strings.Contains(err.Error(), test.expectedError) {
				t.Errorf("test[%s]: expected error containing %q, got %v", test.desc, test.expectedError, err)
			}
		}
	}
}

pkg/azurefileplugin/Dockerfile:26

  • The azfilesauth.deb package is being downloaded from a personal GitHub repository (andyzhangx/demo) instead of an official release or trusted package repository. This creates security and reliability risks: the package could be modified or become unavailable, and there's no verification of its integrity. Consider hosting this package in an official location with proper versioning and checksums, or building it from source in the Dockerfile.
    && curl -Lso /tmp/azfilesauth.deb https://raw.githubusercontent.com/andyzhangx/demo/refs/heads/master/aks/azfilesauth_1.0-8_amd64.deb \

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

Copy link
Copy Markdown

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

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 12 out of 12 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (2)

pkg/azurefile/utils_test.go:1398

  • The test only covers error cases for setCredentialCache, but doesn't test any success scenarios. Add test cases for: (1) successful call with clientID only (for managed identity), and (2) successful call with tokenFile path (for workload identity). While these might require mocking the command execution, at minimum verify that the function constructs the correct arguments without returning an error when valid inputs are provided.
func TestSetCredentialCache(t *testing.T) {
	tests := []struct {
		desc          string
		server        string
		clientID      string
		token         string
		expectedError string
	}{
		{
			desc:          "empty server",
			server:        "",
			clientID:      "test-client-id",
			expectedError: "server must be provided",
		},
		{
			desc:          "empty clientID and token",
			server:        "test.file.core.windows.net",
			clientID:      "",
			token:         "",
			expectedError: "either clientID or tokenFile must be provided",
		},
		{
			desc:          "both empty",
			server:        "",
			clientID:      "",
			expectedError: "server must be provided",
		},
	}

	for _, test := range tests {
		_, err := setCredentialCache(test.server, test.clientID, "", test.token)
		if test.expectedError != "" {
			if err == nil {
				t.Errorf("test[%s]: expected error containing %q, got nil", test.desc, test.expectedError)
			} else if !strings.Contains(err.Error(), test.expectedError) {
				t.Errorf("test[%s]: expected error containing %q, got %v", test.desc, test.expectedError, err)
			}
		}
	}
}

pkg/azurefileplugin/Dockerfile:26

  • This Dockerfile downloads a .deb package from a personal GitHub repository (andyzhangx/demo) rather than from an official or verified source. This poses security and reliability risks: the package could be modified, deleted, or become unavailable, causing build failures in production. Consider hosting this package in an official repository, using a checksum verification, or at minimum using a specific commit hash rather than the branch reference "refs/heads/master" to ensure build reproducibility.
    && curl -Lso /tmp/azfilesauth.deb https://raw.githubusercontent.com/andyzhangx/demo/refs/heads/master/aks/azfilesauth_1.0-8_amd64.deb \

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

@andyzhangx
Copy link
Copy Markdown
Member Author

/retest

@andyzhangx andyzhangx changed the title [WIP] feat: support mount smb file share with workload identity token feat: support mount smb file share with workload identity token Dec 21, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 21, 2025
@andyzhangx andyzhangx requested a review from Copilot December 24, 2025 15:31
Copy link
Copy Markdown

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 11 out of 11 changed files in this pull request and generated 2 comments.


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

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 25, 2025

@andyzhangx I've opened a new pull request, #2919, to work on those changes. Once the pull request is ready, I'll request review from you.

fix workload idenitty token setting

getToken from service account token

feat: use new azfilesauth version

fix

fix ut

add check

add token file name check

fix

refresh WI token

set expirationSeconds: 3600

fix arm64 image build break
Copy link
Copy Markdown

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 11 out of 11 changed files in this pull request and generated 7 comments.


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

@andyzhangx andyzhangx requested a review from Copilot January 11, 2026 15:14
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 11, 2026
Copy link
Copy Markdown

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 11 out of 11 changed files in this pull request and generated 1 comment.


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

return false
}

// shouldUseServiceAccountToken determines whether a service account token
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

The function documentation is incomplete. It should fully describe what the function does. The comment should be: "shouldUseServiceAccountToken determines whether a service account token should be used for authentication based on the volume context attributes."

Suggested change
// shouldUseServiceAccountToken determines whether a service account token
// shouldUseServiceAccountToken determines whether a service account token should be used for authentication based on the volume context attributes.

Copilot uses AI. Check for mistakes.
fix

fix: copilot comments

fix
Copy link
Copy Markdown
Contributor

@mittachaitu mittachaitu left a comment

Choose a reason for hiding this comment

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

Are we going to add e2e test in different PR?

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, mittachaitu

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

@mittachaitu
Copy link
Copy Markdown
Contributor

Can we add README on how to use WorkloadIdentity?

@andyzhangx andyzhangx merged commit 4ce659a into master Feb 4, 2026
27 of 28 checks passed
@andyzhangx
Copy link
Copy Markdown
Member Author

andyzhangx commented Feb 4, 2026

Are we going to add e2e test in different PR?

@mittachaitu can you explore how to add such e2e test in aks RP?

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. kind/feature Categorizes issue or PR as related to a new feature. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants