-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for container credentials method (#189)
Prior this change, the webhook expects the IAM Role ARN to be specified during pod admission. The webhook mutates the pod spec by injecting `AWS_ROLE_ARN` and `AWS_WEB_IDENTITY_TOKEN_FILE` env vars, which will instruct the AWS SDK to get credentials via the [AssumeRoleWithWebIdentity](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html#cli-configure-role-oidc) method. This PR introduces a new method that utilizes [AWS SDK Containers Credential Provider](https://docs.aws.amazon.com/sdkref/latest/guide/feature-container-credentials.html). This method mutates the pod spec by injecting `AWS_CONTAINER_CREDENTIALS_FULL_URI` and `AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE` env vars, which will instruct the AWS SDK to get credentials through the specified HTTP endpoint. To enable this new method, user must provide a config file by setting the argument `--watch-config-file=<path>`. Pod will use this method if its namespace & serviceAccount are listed in the config file. The config file should be a JSON file with the following format: ``` { "identities": [ { "namespace": "foo", "serviceAccount": "bar" } ] } ``` *Testing:* - New unit tests - Manual testing with the below First, the webhook is configured to use the following config file: ``` { "identities": [ { "namespace": "foo", "serviceAccount": "bar" } ] } ``` Second, apply the following yaml: ``` apiVersion: v1 kind: Namespace metadata: name: "foo" --- apiVersion: v1 kind: ServiceAccount metadata: name: "bar" namespace: foo automountServiceAccountToken: false --- apiVersion: v1 kind: Pod metadata: name: test-pod-2 namespace: foo spec: serviceAccountName: bar containers: - name: test-container image: public.ecr.aws/eks-distro-build-tooling/builder-base:latest command: [ "/bin/bash", "-c", "--" ] args: [ "while true; do sleep 5; done" ] --- ``` Lastly, check mutated pod spec: ``` spec: containers: - args: - while true; do sleep 5; done command: - /bin/bash - -c - -- env: - name: AWS_DEFAULT_REGION value: us-west-2 - name: AWS_REGION value: us-west-2 - name: AWS_CONTAINER_CREDENTIALS_FULL_URI value: http://169.254.170.23/v1/credentials - name: AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE value: /var/run/secrets/eks.amazonaws.com/serviceaccount/token image: public.ecr.aws/eks-distro-build-tooling/builder-base:latest imagePullPolicy: Always name: test-container ... volumeMounts: - mountPath: /var/run/secrets/eks.amazonaws.com/serviceaccount name: aws-iam-token readOnly: true ... volumes: - name: aws-iam-token projected: defaultMode: 420 sources: - serviceAccountToken: audience: pods.eks.amazonaws.com expirationSeconds: 86400 path: token ```
- Loading branch information
Showing
18 changed files
with
1,148 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.