Skip to content

feat: make the credentials Secret optional for workload identity - #131

Open
blacksoxx wants to merge 1 commit into
upbound:mainfrom
blacksoxx:workload-identity-optional-credentials
Open

blacksoxx wants to merge 1 commit into
upbound:mainfrom
blacksoxx:workload-identity-optional-credentials

Conversation

@blacksoxx

Copy link
Copy Markdown

Description of your changes

With workload identity the AKS webhook injects AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_FEDERATED_TOKEN_FILE and the projected token volume into any pod that carries the azure.workload.identity/use label and runs with an annotated service account, and azidentity.NewWorkloadIdentityCredential falls back to those variables when its options are empty. The function already passed empty options when the keys were absent, but it still required the azure-creds Secret to be present, and the README told users to set federatedTokenFile and to mount the token volume themselves.

getCreds now treats the Secret as optional when identity.type is AzureWorkloadIdentityCredentials; it stays required for service principal credentials, where nothing else can supply the secret. The README marks the Secret and its keys as optional with their environment variable defaults, and the DeploymentRuntimeConfig example is reduced to the label and the service account annotation the webhook needs.

Fixes #117

I have:

TestIdentityType gains a workload identity case without any credentials, which now reaches the identity provider instead of failing on the missing Secret (on main it fails with failed to get azure-creds credentials), and a service principal case without credentials that pins the unchanged fatal. go test ./... and the repository's golangci-lint configuration are clean; the input type did not change, so nothing was regenerated. Not run on an AKS cluster.

The AKS workload identity webhook injects AZURE_CLIENT_ID,
AZURE_TENANT_ID, AZURE_FEDERATED_TOKEN_FILE and the token volume, and the
Azure SDK falls back to them when the options are empty, but the function
still required the azure-creds Secret to exist. It is now optional for
identity.type AzureWorkloadIdentityCredentials and the README describes
the Secret, its keys and the DeploymentRuntimeConfig as the webhook
leaves them.

Signed-off-by: Youssef Omar Bouden <youssef.bouden2002@gmail.com>
Comment thread README.md
"federatedTokenFile": "/var/run/secrets/azure/tokens/azure-identity-token"
"clientId": "your-client-id", # optional, defaults to AZURE_CLIENT_ID
"tenantId": "your-tenant-id", # optional, defaults to AZURE_TENANT_ID
"federatedTokenFile": "/var/run/secrets/azure/tokens/azure-identity-token" # optional, defaults to AZURE_FEDERATED_TOKEN_FILE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now that the DRC no longer mounts /var/run/secrets/azure/tokens, this federatedTokenFile only resolves on webhook versions before v1.6.0 (which moved the token), and a set key overrides AZURE_FEDERATED_TOKEN_FILE.
Please drop this line and the trailing comma on tenantId.
Optional, since it predates this PR: the # notes make the JSON invalid, so moving them out of the block would make it copy-pasteable.

Comment thread fn_test.go
},
},
},
"AzureWorkloadIdentityCredentialsWithoutSecret": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This case doesn't reach the identity provider: MockGraphQuery ignores the creds and returns that error text itself, so the nil-creds AZURE_* fallback in initializeWorkloadIdentityProvider is untested.
Could you add a direct test: t.Setenv AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_FEDERATED_TOKEN_FILE, call (&GraphQuery{}).initializeWorkloadIdentityProvider(nil) and expect no error?

@jakubramut

jakubramut commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

hello @blacksoxx,
Thank you for the PR, please find my comments below:

example/secrets/azure-workload-identity-creds.yaml still sets federatedTokenFile to the pre-v1.6.0 webhook path, which #117 calls unnecessary and the new DRC no longer mounts. Could you remove the key, or the Secret together with the credentials block in example/identity-type-workload-identity.yaml, so "Fixes #117" holds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify Workload Identity configuration

2 participants