Skip to content

feat: try identity binding before workload identity for Azure Key Vault - #3144

Merged
fseldow merged 2 commits into
mainfrom
xinhl/akv-identity-binding-first
Dec 3, 2026
Merged

fseldow merged 2 commits into
mainfrom
xinhl/akv-identity-binding-first

Conversation

@fseldow

@fseldow fseldow commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

The Azure Key Vault key provider used only the workload identity → managed identity chain. On clusters that use Kubernetes identity binding, it could not get a token through identity binding.

This PR makes the AKV provider try identity binding first, then fall back to the existing chain:

  1. Identity binding: used when the platform injects its config (AZURE_KUBERNETES_SNI_NAME / AZURE_ACR_IDENTITY_BINDING_SNI_NAME, etc., read by LoadIdentityBindingConfigFromEnv).
  2. Workload identity
  3. Managed identity

Changes

  • internal/cloudprovider/azure/tokencredential.go: add CreateCredentialChainPreferIdentityBinding and a fallbackCredential. azidentity.ChainedTokenCredential only moves to the next source when it gets a credentialUnavailableError, which a custom credential can't return. So the new credential falls back to the workload identity / managed identity chain on any identity binding error. If both fail, the returned error includes both errors.
  • If the identity binding config is missing, invalid, or the credential can't be built (for example, no client ID), the provider logs a warning and uses the existing chain. Behavior on clusters without identity binding is unchanged.
  • internal/verifier/keyprovider/azurekeyvault/register.go: use the new chain.
  • The ACR credential provider is unchanged. There, identity binding stays opt-in and exclusive.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Unit tests for fallbackCredential (primary succeeds, falls back, both fail) and for CreateCredentialChainPreferIdentityBinding (no config, no SNI, can't build the IB credential, IB first).
  • go test ./internal/cloudprovider/azure/... ./internal/verifier/keyprovider/azurekeyvault/... and go vet pass.

Checklist

  • Does the affected code have corresponding tests?
  • Are the changes documented, not just with inline documentation, but also with conceptual documentation such as an overview of a new feature, or task-based documentation like a tutorial? Consider if this change should be announced on your project blog.

When the pod has identity binding configured, the Azure Key Vault key provider now tries the identity binding credential first and falls back to the existing workload identity and managed identity chain if it fails.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xinhe Li <xinhl@microsoft.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 08:29
@github-actions github-actions Bot added the v2 label Nov 26, 2026
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.71%. Comparing base (a13fe7b) to head (8c8453d).

Files with missing lines Patch % Lines
internal/cloudprovider/azure/tokencredential.go 90.32% 2 Missing and 1 partial ⚠️
...nal/verifier/keyprovider/azurekeyvault/register.go 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3144      +/-   ##
==========================================
- Coverage   86.76%   86.71%   -0.05%     
==========================================
  Files          56       56              
  Lines        2977     3012      +35     
==========================================
+ Hits         2583     2612      +29     
- Misses        301      305       +4     
- Partials       93       95       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

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.

🟡 Changes recommended

An unbounded Azure token-proxy request can hang provider initialization indefinitely, preventing fallback to working workload or managed identity credentials.

1 open issue
What changed in this PR

This PR adds identity-binding authentication to the Azure Key Vault key provider, preferring it over the existing workload identity and managed identity chain. ACR authentication remains unchanged.

Changes:

  • Load identity-binding configuration when initializing the Key Vault provider.
  • Fall back to the existing credential chain when identity binding is unavailable or token acquisition fails.
  • Add unit tests for credential selection, fallback behavior, and combined errors.
File Description
internal/​verifier/​keyprovider/​azurekeyvault/​register.go Load identity-binding configuration and use the new credential chain.
internal/​cloudprovider/​azure/​tokencredential.go Add identity-binding-first credential construction and token fallback.
internal/​cloudprovider/​azure/​tokencredential_test.go Test credential selection and token fallback outcomes.

Review effort: Balanced

…allback

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xinhe Li <xinhl@microsoft.com>

@charleswool charleswool left a comment

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.

LGTM

@fseldow
fseldow merged commit 1f08198 into main Dec 3, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants