feat: Support `tokenAttributes` for kubelet image credential providers (KEP-4412 service account tokens)
What I'd like:
Add an optional token-attributes table to settings.kubernetes.credential-providers.<name> so Bottlerocket can render the upstream tokenAttributes block in the kubelet CredentialProviderConfig. This enables KEP-4412 (kubelet passes the pod's ServiceAccount token to the credential provider plugin), which is beta and on by default since Kubernetes 1.34.
Proposed user data:
[settings.kubernetes.credential-providers.ecr-credential-provider]
enabled = true
image-patterns = ["*.dkr.ecr.*.amazonaws.com"]
[settings.kubernetes.credential-providers.ecr-credential-provider.token-attributes]
service-account-token-audience = "sts.amazonaws.com"
cache-type = "ServiceAccount"
require-service-account = false
optional-service-account-annotation-keys = ["eks.amazonaws.com/ecr-role-arn"]Expected rendering in /etc/kubernetes/kubelet/credential-provider-config.yaml:
- name: ecr-credential-provider
matchImages:
- "*.dkr.ecr.*.amazonaws.com"
defaultCacheDuration: "12h"
apiVersion: credentialprovider.kubelet.k8s.io/v1
env:
- name: HOME
value: '/root'
tokenAttributes:
serviceAccountTokenAudience: sts.amazonaws.com
cacheType: ServiceAccount
requireServiceAccount: false
optionalServiceAccountAnnotationKeys:
- eks.amazonaws.com/ecr-role-arnSetting to upstream field mapping:
| Setting | Upstream field | Required when table is set |
|---|---|---|
service-account-token-audience |
serviceAccountTokenAudience |
yes |
cache-type (Token | ServiceAccount) |
cacheType |
yes |
require-service-account |
requireServiceAccount |
yes |
required-service-account-annotation-keys |
requiredServiceAccountAnnotationKeys |
no |
optional-service-account-annotation-keys |
optionalServiceAccountAnnotationKeys |
no |
Suggested behavior:
- Validation in the settings API, mirroring kubelet's own checks: mandatory fields present,
cache-typeis one of the two allowed values, annotation keys are valid qualified names, and required/optional key lists do not overlap. Kubelet refuses to start on an invalidCredentialProviderConfig, so bad input should be rejected atapiclient set/ user data time rather than producing a node that never becomes Ready. - Variants: Kubernetes 1.34+ (feature is beta/default-on). For 1.33 either reject the setting or document that the
KubeletServiceAccountTokenForCredentialProvidersfeature gate must be enabled. - Backward compatible: when
token-attributesis absent, output is unchanged.
Any alternatives you've considered:
Where the gap is today:
- Settings model (
bottlerocket-settings-sdk,bottlerocket-settings-models/modeled-types/src/kubernetes.rs):CredentialProvideronly hasenabled,image_patterns,cache_duration,environment. - Template (
bottlerocket-core-kit,packages/kubernetes-1.3{4,5,6}/credential-provider-config-yaml): only rendersname,matchImages,defaultCacheDuration,apiVersion,env.
Everything else is already in place: the kubernetes-1.35 variant ships ecr-credential-provider 1.35.2, which supports service account tokens including fallback to the node role when the annotation is absent, and kubelet already gets --image-credential-provider-config / --image-credential-provider-bin-dir. Only the settings model and template are missing.
Workarounds considered, none viable:
- Bootstrap container patching the rendered file. Bootstrap containers run as
control_t, which is excluded fromtrusted_s, and onlytrusted_smay mutateetc_t. Writing to/.bottlerocket/rootfs/etc/kubernetes/kubelet/credential-provider-config.yamlis denied, and withessential = truethe node fails to boot. - Superpowered host container.
super_tcan write/etc, but host containers start concurrently with kubelet, so this requires restarting kubelet after patching, and any settings change re-renders the file and silently drops the patch. Not suitable for production. - Custom variant with a patched template. Works, but means maintaining a fork just for this.
On EKS, AL2023 nodes support this today by writing the CredentialProviderConfig through user data. Bottlerocket is currently the only EKS-optimized AMI family where it can't be enabled.
Use case: per-pod Amazon ECR pull permissions on EKS 1.35, where each pod's ServiceAccount annotation eks.amazonaws.com/ecr-role-arn selects an IAM role assumed via AssumeRoleWithWebIdentity, and ECR repository policies isolate teams sharing nodes.
Source: bottlerocket-os/bottlerocket