Skip to content

feat(credential-provider): support k8s service account token #8836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mainred
Copy link
Contributor

@mainred mainred commented Apr 8, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

kubernetes/enhancements#4412

Which issue(s) this PR fixes:

Fixes #8837

Tests I have been done

On a 1.33.0 cluster, I enabled workload identity on AKS cluster, and granted the identity, linked to the service account, permission to acrpull access.
I used the projected service account token azure-identity-token and get access token successfully

echo "{\"kind\":\"CredentialProviderRequest\",\"apiVersion\":\"credentialprovider.kubelet.k8s.io/v1\",\"image\":\"qingchuanhao.azurecr.io/nginx:v1\",\"serviceAccountToken\":\"<azure-identity-token>\",\"serviceAccountAnnotations\":{\"azure.workload.identity/client-id\": \"a202f4e5-8b33-48ec-8c0d-f1d25e8b4290\", \"azure.workload.identity/tenant-id\": \"72f988bf-86f1-41af-91ab-2d7cd011db47\"}}"| /var/lib/kubelet/credential-provider/acr-credential-provider /etc/kubernetes/azure.json

{"kind":"CredentialProviderResponse","apiVersion":"credentialprovider.kubelet.k8s.io/v1","cacheKeyType":"Registry","cacheDuration":"5m0s","auth":{"*.azurecr.*":{"username":"","password":""},"qingchuanhao.azurecr.io":{"username":"00000000-0000-0000-0000-000000000000","password":"<acces token>"}}}

I then use the token the login the acr and pull the acr image successfully

docker login qingchuanhao.azurecr.io -u 00000000-0000-0000-0000-000000000000 -p <access-tokn>

apiVersion: kubelet.config.k8s.io/v1
kind: CredentialProviderConfig
providers:
  - name: acr-credential-provider
    matchImages:
      - "*.azurecr.io"
      - "*.azurecr.cn"
      - "*.azurecr.de"
      - "*.azurecr.us"
    defaultCacheDuration: "10m"
    apiVersion: credentialprovider.kubelet.k8s.io/v1
    tokenAttributes:
      serviceAccountTokenAudience: api://AzureADTokenExchange
      # requireServiceAccount is set to true, so the plugin will only be invoked if the pod has a service account
      requireServiceAccount: true
      requiredServiceAccountAnnotationKeys:
      - azure.workload.identity/client-id
    args:
      - /etc/kubernetes/azure.json

Special notes for your reviewer:

Does this PR introduce a user-facing change?

feat(credential-provider): support k8s service account token

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@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. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 8, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mainred
Once this PR has been reviewed and has the lgtm label, please assign nilo19 for approval. For more information see the Code Review Process.

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

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

@github-actions github-actions bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Apr 8, 2025
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 8, 2025
@aramase
Copy link
Member

aramase commented May 23, 2025

@mainred any update on this PR?

@mainred mainred force-pushed the ksa-token-credential-provider branch from bff6efe to 552713b Compare June 26, 2025 07:54
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 26, 2025
@mainred mainred marked this pull request as ready for review June 26, 2025 07:54
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 26, 2025
@mainred mainred force-pushed the ksa-token-credential-provider branch from 0419296 to d11ecf3 Compare June 26, 2025 09:39
@mainred
Copy link
Contributor Author

mainred commented Jun 26, 2025

@aramase, I have updated the PR description with my test and setup.
I think we need only client ID annotation, for the other information, we can get config file. cross-tenant is not supported before this change.
I tried to skip passing config file but considering 1. config file must be there for other node components like kubelet, 2 we may need the authority host from the config, I keep using config file as a managed solution. We can provide all the required info in the pod annotations though, but not sure how we'll add these annotations from another component like azure-workload-identity webhook?

@coveralls
Copy link

Coverage Status

coverage: 74.425% (-0.2%) from 74.648%
when pulling b7fedab on mainred:ksa-token-credential-provider
into c811ba8 on kubernetes-sigs:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

k8s service account token for credential provider
4 participants