AWS IAM Authenticator
SecurityAuthenticate to Kubernetes clusters with AWS IAM credentials
Release history
v0.7.22
CompareGitHub
Changelog
- ba487d9 Merge pull request #1119 from thatikondasushanth/bump-version-0.7.22
- 563afd6 Merge pull request #1118 from hakuna-matatah/patch-1
- b4655a8 clean up
- 161548f Bump version to 0.7.22
- 95642e2 Merge pull request #1117 from thatikondasushanth/bump-golangci-lint-v2.14.0
- 373e225 Bump golangci-lint to v2.14.0 for Go 1.27 support
v0.7.21
CompareGitHub
Changelog
- 2a1df46 Merge pull request #1115 from thatikondasushanth/bump-version-0.7.21
- e3adc90 Bump version to 0.7.21
- 985a2ed Merge pull request #1114 from thatikondasushanth/go-1.27.1-cve-fix
- 55d9988 Upgrade Go to 1.27.2
- de6d785 Upgrade Go to 1.27.1 and bump dependencies for CVE mitigation
- 6815fb7 Merge pull request #1108 from tanmaybaid/fix-max-token-len-1106
- 0b955b6 Raise maxTokenLenBytes to allow full-size STS session tokens
v0.7.20
CompareGitHub
Changelog
- 5ae0e8e Merge pull request #1099 from HanshalDabbiru/patch-1
- 4b9bee1 Update version.txt to 0.7.20
- 76ecb5a Merge pull request #1097 from HanshalDabbiru/ec2-metrics
- b9e03e9 removed hardcoded response code for ec2_total_responses metric
- 26f1f09 added unit tests for ec2 connection metrics
- 9a67ed0 added ec2 metrics: ec2_responses_total and ec2_connection_failures_total
v0.7.19
CompareGitHub
Changelog
- d7ce148 Merge pull request #1096 from adp-825/adpotdar/bump-version-0.7.19
- 74d3043 Bump version to 0.7.19
- 3642f9e Merge pull request #1091 from ronaldngounou/rngounou/bump-dockerfile-go-1.26.5
- 1850a06 fix: bump golang.org/x/text to v0.40.0 to remediate GO-2026-5970
- d1e04c0 fix: bump Dockerfile go version to 1.26.5 for CVEs
- 81b1dab Merge pull request #1077 from SuperQ/superq/cleaup_k8s_prereleases
- 73984a7 Cleanup k8s.io prerelease deps
- 30ce860 Merge pull request #1080 from kubernetes-sigs/dependabot/go_modules/aws-dependencies-511a6356c0
- dd5f544 chore(deps): Bump the aws-dependencies group across 2 directories with 14 updates
- af30e56 Merge pull request #1066 from SuperQ/superq/fixup_go
- 9517017 Use a replace diretive for integration tests
- d17e344 Update for Go 1.26.5
- 0946dd7 Merge pull request #1075 from adp-825/adpotdar/update-cve-1.24.4
- 74cc7be Update dependencies to fix CVE in 1.24.4
- 948d9fe Merge pull request #1067 from philljie/patch-1
- 091b6cb Add note for {{EC2PrivateDNSName}} in README
v0.7.18
CompareGitHub
Changelog
- c0e2ecd Merge pull request #1062 from CaidenBorrego/new-release
- 44fb83f Creating new release for CVE mitigation
- f13fbce Merge pull request #1057 from CaidenBorrego/caidenb-versionbump
- 2201e0a Merge remote-tracking branch 'upstream/master' into caidenb-versionbump
- 2b185f3 Bump x/net and x/sys to remediate CVEs
v0.7.17
CompareGitHub
Changelog
- 87b8124 Merge pull request #1051 from CaidenBorrego/caidenb-versionbump
- 2989192 bumping version from 0.7.16->0.7.17
- 281f3cb Merge pull request #1047 from CaidenBorrego/caidenb-reservedprefix-fix
- 1f4ef7d fix: honor reservedPrefixConfig for ConfigMap and CRD backends
- ae30094 Merge pull request #1046 from CaidenBorrego/caidenb-gorunner-bump
- 6507746 fix: reject malformed mapping ARN in userIDStrict mode for dynamic files
v0.7.13
CompareGitHub
Changelog
- d5b43a7 Merge pull request #1020 from dheeraj-coding/master
- 7e0d9a5 feat: add manual dispatch function for create-release.yml
- 9254ce4 Merge pull request #1019 from dheeraj-coding/master
- cb5b4ed fix: create-release workflow failures
- 2031d14 Merge pull request #1017 from Ganiredi/1.36-k8s-deps
- 83ee8ac Merge pull request #1018 from dheeraj-coding/master
- d4af254 fix: build failure due to stale gcb image by updating to latest
- 1a9d279 Release 0.7.13
- 1597ffc Merge pull request #1016 from Ganiredi/1.36-k8s-deps
- bd65ecc Merge branch 'master' into 1.36-k8s-deps
- 05acd16 Merge pull request #1013 from kubernetes-sigs/dependabot/go_modules/misc-dependencies-be00ae3611
- d64ea72 1.36.rc release
- e83a1d0 Merge pull request #1015 from dheeraj-coding/master
- 6639d07 fix: bump go version 1.26.2 for CVEs
- 36d5e6d chore(deps): Bump the misc-dependencies group across 3 directories with 6 updates
- baa2269 Merge pull request #1011 from kubernetes-sigs/dependabot/go_modules/observability-dependencies-9e34dd3c34
- 40ffac6 Merge pull request #1009 from kubernetes-sigs/dependabot/go_modules/misc-dependencies-b5e1eeb2d5
- 0b89317 Merge pull request #1004 from bryantbiggs/chore/fix-goreleaser-deprecations
- 6d563b7 Merge pull request #1010 from kubernetes-sigs/dependabot/go_modules/aws-dependencies-7118f1d525
- f420639 chore(deps): Bump the observability-dependencies group across 2 directories with 2 updates
- 9bb31de chore(deps): Bump the aws-dependencies group across 2 directories with 6 updates
- 66b3b5f chore(deps): Bump the misc-dependencies group across 3 directories with 2 updates
- 3785639 Merge pull request #1008 from kubernetes-sigs/dependabot/go_modules/aws-dependencies-3ce7b5fcac
- 3cda0bd chore(deps): Bump the aws-dependencies group across 2 directories with 12 updates
- 8f47ccb Merge pull request #1006 from kubernetes-sigs/dependabot/go_modules/k8s-dependencies-09346e948b
- d80a68b chore(deps): Bump the k8s-dependencies group across 3 directories with 8 updates
- 1177c2f Merge pull request #1005 from kubernetes-sigs/dependabot/go_modules/aws-dependencies-508cd0fd8e
- 35d780c chore(deps): Bump the aws-dependencies group across 2 directories with 15 updates
- 4c64cd5 fix: update Makefile goreleaser target for v2 compatibility
- 4c3b268 fix: resolve goreleaser v2 deprecations
v0.7.12
CompareGitHub
Changelog
- 8333960 Merge pull request #1000 from mengqiy/master
- af205bb Merge pull request #1002 from ronaldngounou/update-owners
- f0435eb Update OWNERS in reviewers and approvers list
- 64fd35a Release 0.7.12
- 711e472 Merge pull request #998 from bryantbiggs/chore/repo-cleanup-and-dx
- 93b1588 ci: add verify job to catch unrun gofmt and go mod tidy
- b4673af chore(lint): harden linter config and fix coverage gaps
- 0acabd1 fix(lint): add revive and unparam linters with full compliance
- a6a2882 ci: add unit test job, expand golangci config, add make update/verify
- f19a13d docs(e2e): fix Go version, remove non-existent make target, fix typo
- d8fd7c5 docs(release): remove stale ECR image update instructions and fix asset version placeholders
- d3aa58b fix: address code review findings in repo cleanup branch
- 0660793 docs: rewrite development.md as a practical local dev guide
- 8684111 chore: repo cleanup, developer experience improvements
- a05fab5 Merge pull request #999 from bryantbiggs/chore/reduce-binary-size
- 22e2233 chore: reduce binary size by 59% (80 MB → 33 MB)
- 540c0af Merge pull request #997 from bryantbiggs/deps/update-all-modules-2026-03-16
- 1d65eba fix(lint): replace deprecated NewSimpleClientset and fix embedded field selector
- dcc1916 fix(tests): address code review findings in integration test framework
- f8dba99 fix(tests): address post-refactor issues and add go workspace
- a58b4c0 refactor(tests): remove k8s.io/kubernetes dependency from test modules
- a5e321c chore: update all dependencies to latest versions
v0.7.11
GitHub
Changelog
- 7e87c37 Merge pull request #988 from dstdfx/bump-version
- 0a5ddae Bump version to 0.7.11
- f5b5be7 Merge pull request #985 from dstdfx/bump-go-version-1.25.7
- 4e2f4e9 Update go.mod for e2e/int tests
- d94bc07 Update go.mod
- 2a6d62d Merge pull request #986 from ShiriNmi1520/master
- 5b12454 Clarify README "Run the server" deployment instructions
- e96722e Bump go to 1.25.7
- 3e6556d Merge pull request #983 from eks-distro-pr-bot/eks-distro-pr-bot/go-version-bumps
- d09abb2 Creating PR to update Go version to 1.25.6
README
AWS IAM Authenticator for Kubernetes
A tool to use AWS IAM credentials to authenticate to a Kubernetes cluster. The initial work on this tool was driven by Heptio. The project receives contributions from multiple community engineers and is currently maintained by Heptio and Amazon EKS OSS Engineers.
Table of Contents
- Why do I want this?
- How do I use it?
- Kops Usage
- How does it work?
- What is a cluster ID?
- Specifying Credentials & Using AWS Profiles
- API Authorization from Outside a Cluster
- Troubleshooting
- Full Configuration Format
- Development
- Community, discussion, contribution, and support
Why do I want this?
If you are an administrator running a Kubernetes cluster on AWS, you already need to manage AWS IAM credentials to provision and update the cluster. By using AWS IAM Authenticator for Kubernetes, you avoid having to manage a separate credential for Kubernetes access. AWS IAM also provides a number of nice properties such as an out of band audit trail (via CloudTrail) and 2FA/MFA enforcement.
If you are building a Kubernetes installer on AWS, AWS IAM Authenticator for Kubernetes can simplify your bootstrap process.
You won't need to somehow smuggle your initial admin credential securely out of your newly installed cluster.
Instead, you can create a dedicated KubernetesAdmin role at cluster provisioning time and set up Authenticator to allow cluster administrator logins.
How do I use it?
Assuming you have a cluster running in AWS and you want to add AWS IAM Authenticator for Kubernetes support, you need to:
- Create an IAM role you'll use to identify users.
- Run the Authenticator server as a DaemonSet.
- Configure your API server to talk to Authenticator.
- Set up kubectl to use Authenticator tokens.
1. Create an IAM role
First, you must create one or more IAM roles that will be mapped to users/groups inside your Kubernetes cluster. The easiest way to do this is to log into the AWS Console:
- Choose the "Role for cross-account access" / "Provide access between AWS accounts you own" option.
- Paste in your AWS account ID number (available in the top right in the console).
- Your role does not need any additional policies attached.
This will create an IAM role with no permissions that can be assumed by authorized users/roles in your account. Note the Amazon Resource Name (ARN) of your role, which you will need below.
You can also do this in a single step using the AWS CLI instead of the AWS Console:
# get your account ID
ACCOUNT_ID=$(aws sts get-caller-identity --output text --query 'Account')
# define a role trust policy that opens the role to users in your account (limited by IAM policy)
POLICY=$(echo -n '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::'; echo -n "$ACCOUNT_ID"; echo -n ':root"},"Action":"sts:AssumeRole","Condition":{}}]}')
# create a role named KubernetesAdmin (will print the new role's ARN)
aws iam create-role \
--role-name KubernetesAdmin \
--description "Kubernetes administrator role (for AWS IAM Authenticator for Kubernetes)." \
--assume-role-policy-document "$POLICY" \
--output text \
--query 'Role.Arn'You can also skip this step and use:
- An existing role (such as a cross-account access role).
- An IAM user (see
mapUsersbelow). - An EC2 instance or a federated role (see
mapRolesbelow).
2. Run the server
The server is meant to run on each of your master nodes as a DaemonSet with host networking so it can expose a localhost port.
For a sample ConfigMap and DaemonSet configuration, see deploy/example.yaml.
Before applying it, update these values for your cluster:
- Replace placeholder IAM ARNs (
arn:aws:iam::000000000000:...) inconfig.yaml. - Set
clusterIDto a unique value for your cluster. - Verify the DaemonSet scheduling rules match your control-plane node labels/taints.
Then deploy it:
kubectl apply -f deploy/example.yaml
kubectl -n kube-system rollout status daemonset/aws-iam-authenticator
kubectl -n kube-system get pods -l k8s-app=aws-iam-authenticatorOnce the pod is running on a control-plane node, the aws-iam-authenticator server will create the webhook kubeconfig on the host at /etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml (or the path configured via --generate-kubeconfig).
(Optional) Pre-generate a certificate, key, and kubeconfig
If you're building an automated installer, you can also pre-generate the certificate, key, and webhook kubeconfig files easily using aws-iam-authenticator init.
This command will generate files and place them in the configured output directories.
You can run this on each master node prior to starting the API server. You could also generate them before provisioning master nodes and install them in the appropriate host paths.
If you do not pre-generate files, aws-iam-authenticator server will generate them on demand.
This works but requires that you restart your Kubernetes API server after installation.
3. Configure your API server to talk to the server
The Kubernetes API integrates with AWS IAM Authenticator for Kubernetes using a token authentication webhook.
When you run aws-iam-authenticator server, it will generate a webhook configuration file and save it onto the host filesystem.
You'll need to add a single additional flag to your API server configuration:
--authentication-token-webhook-config-file=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yamlOn many clusters, the API server runs as a static pod.
You can add the flag to /etc/kubernetes/manifests/kube-apiserver.yaml.
Make sure the host directory /etc/kubernetes/aws-iam-authenticator/ is mounted into your API server pod.
You may also need to restart the kubelet daemon on your master node to pick up the updated static pod definition:
systemctl restart kubelet.service4. Create IAM role/user to kubernetes user/group mappings
The default behavior of the server is to source mappings exclusively from the
mapUsers and mapRoles fields of its configuration file. See Full
Configuration Format below for details.
Using the --backend-mode flag, you can configure the server to source
mappings from two additional backends: an EKS-style ConfigMap
(--backend-mode=EKSConfigMap) or IAMIdentityMapping custom resources
(--backend-mode=CRD). The default backend, the server configuration file
that's mounted by the server pod, corresponds to --backend-mode=MountedFile.
You can pass a comma-separated list of these backends to have the server search
them in order. For example, with --backend-mode=EKSConfigMap,MountedFile, the
server will search the EKS-style ConfigMap for mappings then, if it doesn't
find a mapping for the given IAM role/user, the server configuration file. If a
mapping for the same IAM role/user exists in multiple backends, the server will
use the mapping in the backend that occurs first in the comma-separated list.
In this example, if a mapping is found in the EKS ConfigMap then it will be
used whether or not a duplicate or conflicting mapping exists in the server
configuration file.
Note that when setting a single backend, the server will only source from
that one and ignore the others even if they exist. For example, with
--backend-mode=CRD, the server will only source from IAMIdentityMappings
and ignore the mounted file and EKS ConfigMap.
MountedFile
This is the default backend of mappings and sufficient for most users. See Full Configuration Format below for details.
CRD (alpha)
This backend models each IAM mapping as an IAMIdentityMapping Kubernetes
Custom
Resource.
This approach enables you to maintain mappings in a Kubernetes-native way using
kubectl or the API. Plus, syntax errors (like misaligned YAML) can be more
easily caught and won't affect all mappings.
To setup an IAMIdentityMapping CRD you'll first need to apply the CRD
manifest:
kubectl apply -f deploy/iamidentitymapping.yamlWith the CRDs deployed you can then create Custom Resources which model your
IAM Identities. See
./deploy/example-iamidentitymapping.yaml:
---
apiVersion: iamauthenticator.k8s.aws/v1alpha1
kind: IAMIdentityMapping
metadata:
name: kubernetes-admin
spec:
# Arn of the User or Role to be allowed to authenticate
arn: arn:aws:iam::XXXXXXXXXXXX:user/KubernetesAdmin
# Username that Kubernetes will see the user as, this is useful for setting
# up allowed specific permissions for different users
username: kubernetes-admin
# Groups to be attached to your users/roles. For example `system:masters` to
# create cluster admin, or `system:nodes`, `system:bootstrappers` for nodes to
# access the API server.
groups:
- system:mastersEKSConfigMap
The EKS-style kube-system/aws-auth ConfigMap serves as the backend. The
ConfigMap is expected to be in exactly the same format as in EKS clusters:
https://docs.aws.amazon.com/eks/latest/userguide/add-user-role.html. This is
useful if you're migrating from/to EKS and want to keep your mappings, or are
running EKS in addition to some other AWS cluster(s) and want to have the same
mappings in each.
DynamicFile
A local file specified by cfg.dynamicfilepath can serve as the backend. The file content is expected to be in exactly the same format as the EKSConfigMap. Whenever this file content changes, authenticator will automatically reload it. This provides more flexibility on managing the ARN mappings.
Check https://github.com/kubernetes-sigs/aws-iam-authenticator/blob/master/hack/dev/authenticator_with_dynamicfile_mode.yaml about how to configure the DynamicFile mode.
Run make e2e RUNNER=kind to play with a kind cluster with DynamicFile mode enable.
5. How to configure reservedPrefixConfig for Kubernetes usernames
The aws-iam-authenticator can support reserved prefix for k8s username. If the reserved prefix is set, then the username with the reserved prefix will not be authenticated with the error "username must not begin with with the following prefixes:".
Check https://github.com/kubernetes-sigs/aws-iam-authenticator/blob/master/hack/dev/authenticator_with_dynamicfile_mode.yaml about how to configure the reserved prefix.
6. Set up kubectl to use authentication tokens provided by AWS IAM Authenticator for Kubernetes
Finally, once the server is set up you'll want to authenticate.
You will still need a kubeconfig that has the public data about your cluster (cluster CA certificate, endpoint address).
The users section of your configuration, however, should include an exec section (refer to the kubectl credential plugin docs):
# [...]
users:
- name: kubernetes-admin
user:
exec:
apiVersion: client.authentication.k8s.io/v1beta1
command: aws-iam-authenticator
args:
- "token"
- "-i"
- "REPLACE_ME_WITH_YOUR_CLUSTER_ID"
- "-r"
- "REPLACE_ME_WITH_YOUR_ROLE_ARN"
# no client certificate/key needed here!This means the kubeconfig is entirely public data and can be shared across all Authenticator users.
It may make sense to upload it to a trusted public location such as AWS S3.
Make sure you have the aws-iam-authenticator binary installed.
You can install it with go install sigs.k8s.io/aws-iam-authenticator/cmd/aws-iam-authenticator@latest.
To authenticate, run kubectl --kubeconfig /path/to/kubeconfig" [...].
kubectl will exec the aws-iam-authenticator binary with the supplied params in your kubeconfig which will generate a token and pass it to the apiserver.
The token is valid for 15 minutes (the shortest value AWS permits) and can be reused multiple times.
You can also specify session name when generating the token by including --session-name or -s parameter. This parameter cannot be used along with --forward-session-name.
You can also omit -r ROLE_ARN to sign the token with your existing credentials without assuming a dedicated role.
This is useful if you want to authenticate as an IAM user directly or if you want to authenticate using an EC2 instance role or a federated role.
Kops Usage
Clusters managed by Kops can be configured to use Authenticator. For usage instructions see the Kops documentation.
How does it work?
It works using the AWS sts:GetCallerIdentity API endpoint.
This endpoint returns information about whatever AWS IAM credentials you use to connect to it.
Client side (aws-iam-authenticator token)
We use this API in a somewhat unusual way by having the Authenticator client generate and pre-sign a request to the endpoint. We serialize that request into a token that can pass through the Kubernetes authentication system.
Server side (aws-iam-authenticator server)
The token is passed through the Kubernetes API server and into the Authenticator server's /authenticate endpoint via a webhook configuration.
The Authenticator server validates all the parameters of the pre-signed request to make sure nothing looks funny.
It then submits the request to the real https://sts.amazonaws.com server, which validates the client's HMAC signature and returns information about the user.
Now that the server knows the AWS identity of the client, it translates this identity into a Kubernetes user and groups via a simple static mapping.
This mechanism is borrowed with a few changes from Vault.
What is a cluster ID?
The Authenticator cluster ID is a unique-per-cluster identifier that prevents certain replay attacks. Specifically, it prevents one Authenticator server (e.g., in a dev environment) from using a client's token to authenticate to another Authenticator server in another cluster.
The cluster ID does need to be unique per-cluster, but it doesn't need to be a secret. Some good choices are:
- A random ID such as from
openssl rand 16 -hex - The domain name of your Kubernetes API server
The Vault documentation also explains this attack (see X-Vault-AWS-IAM-Server-ID).
Specifying Credentials & Using AWS Profiles
Credentials can be specified for use with aws-iam-authenticator via any of the methods available to the
AWS SDK for Go.
This includes specifying AWS credentials with enviroment variables or by utilizing a credentials file.
AWS named profiles are supported by aws-iam-authenticator
via the AWS_PROFILE environment variable. For example, to authenticate with credentials specified in the dev profile the AWS_PROFILE can
be exported or specified explictly (e.g., AWS_PROFILE=dev kubectl get all). If no AWS_PROFILE is set, the default profile is used.
The AWS_PROFILE can also be specified directly in the kubeconfig file
as part of the exec flow. For example, to specify
that credentials from the dev named profile should always be used by aws-iam-authenticator, your kubeconfig would include an env
key thats sets the profile:
apiVersion: v1
clusters:
- cluster:
server: ${server}
certificate-authority-data: ${cert}
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: aws
name: aws
current-context: aws
kind: Config
preferences: {}
users:
- name: aws
user:
exec:
apiVersion: client.authentication.k8s.io/v1beta1
command: aws-iam-authenticator
env:
- name: "AWS_PROFILE"
value: "dev"
args:
- "token"
- "-i"
- "mycluster"This method allows the appropriate profile to be used implicitly. Note that any environment variables set as part of the exec flow will
take precedence over what's already set in your environment.
Note for federated users:
Federated AWS users often will have a "meaningful" attribute mapped onto their assumed role, such as an email address, through the account's AWS configuration.
These assumed sessions have a few parts, the role id
and caller-specified-role-name. By default, when a federated user uses the --role option of aws-iam-authenticator to assume a new role the
caller-specified-role-name will be converted to a random token and the role id carries through to the newly assumed role.
Using aws-iam-authenticator token ... --forward-session-name will map the original caller-specified-role-name attribute onto the new STS assumed session.
This can be helpful for quickly attempting to associate "who performed action X on the K8 cluster".
Please note, this should not be considered definitive and needs to be cross referenced via the role id (which remains consistent) with CloudTrail logs
as a user could potentially change this on the client side.
API Authorization from Outside a Cluster
It is possible to make requests to the Kubernetes API from a client that is outside the cluster, be that using the
bare Kubernetes REST API or from one of the language specific Kubernetes clients
(e.g., Python). In order to do so, you must create a bearer token that
is included with the request to the API. This bearer token requires you append the string k8s-aws-v1. with a
base64 encoded string of a signed HTTP request to the STS GetCallerIdentity Query API. This is then sent it in the
Authorization header of the request. Something to note though is that the IAM Authenticator explicitly omits
base64 padding to avoid any = characters thus guaranteeing a string safe to use in URLs. Below is an example in
Python on how this token would be constructed:
import base64
import boto3
import re
from botocore.signers import RequestSigner
def get_bearer_token(cluster_id, region):
STS_TOKEN_EXPIRES_IN = 60
session = boto3.session.Session()
client = session.client('sts', region_name=region)
service_id = client.meta.service_model.service_id
signer = RequestSigner(
service_id,
region,
'sts',
'v4',
session.get_credentials(),
session.events
)
params = {
'method': 'GET',
'url': 'https://sts.{}.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15'.format(region),
'body': {},
'headers': {
'x-k8s-aws-id': cluster_id
},
'context': {}
}
signed_url = signer.generate_presigned_url(
params,
region_name=region,
expires_in=STS_TOKEN_EXPIRES_IN,
operation_name=''
)
base64_url = base64.urlsafe_b64encode(signed_url.encode('utf-8')).decode('utf-8')
# remove any base64 encoding padding:
return 'k8s-aws-v1.' + re.sub(r'=*', '', base64_url)
# If making a HTTP request you would create the authorization headers as follows:
headers = {'Authorization': 'Bearer ' + get_bearer_token('my_cluster', 'us-east-1')}
Troubleshooting
If your client fails with an error like could not get token: AccessDenied [...], you can try assuming the role with the AWS CLI directly:
# AWS CLI version of `aws-iam-authenticator token -r arn:aws:iam::ACCOUNT:role/ROLE`:
$ aws sts assume-role --role-arn arn:aws:iam::ACCOUNT:role/ROLE --role-session-name testIf that fails, there are a few possible problems to check for:
Make sure your base AWS credentials are available in your shell (
aws sts get-caller-identitycan help troubleshoot this).Make sure the target role allows your source account access (in the role trust policy).
Make sure your source principal (user/role/group) has an IAM policy that allows
sts:AssumeRolefor the target role.Make sure you don't have any explicit deny policies attached to your user, group, or in AWS Organizations that would prevent the
sts:AssumeRole.Try simulating the
sts:AssumeRolecall in the Policy Simulator.
Full Configuration Format
The client and server have the same configuration format. They can share the same exact configuration file, since there are no secrets stored in the configuration.
# a unique-per-cluster identifier to prevent replay attacks (see above)
clusterID: my-dev-cluster.example.com
# default IAM role to assume for `aws-iam-authenticator token`
defaultRole: arn:aws:iam::000000000000:role/KubernetesAdmin
# server listener configuration
server:
# localhost port where the server will serve the /authenticate endpoint
port: 21362 # (default)
# state directory for generated TLS certificate and private keys
stateDir: /var/aws-iam-authenticator # (default)
# output `path` where a generated webhook kubeconfig will be stored.
generateKubeconfig: /etc/kubernetes/aws-iam-authenticator.kubeconfig # (default)
# role to assume before querying EC2 API in order to discover metadata like EC2 private DNS Name
ec2DescribeInstancesRoleARN: arn:aws:iam::000000000000:role/DescribeInstancesRole
# AWS region for EC2 DescribeInstances and token verification. If unset, the region is looked
# up from the EC2 Instance Metadata Service (IMDS) at startup. Also settable with `--region`.
region: us-west-2
# AWS Account IDs to scrub from server logs. (Defaults to empty list)
scrubbedAccounts:
- "111122223333"
- "222233334444"
# each mapRoles entry maps an IAM role to a username and set of groups
# Each username and group can optionally contain template parameters:
# 1) "{{AccountID}}" is the 12 digit AWS ID.
# 2) "{{SessionName}}" is the role session name, with `@` characters
# transliterated to `-` characters.
# 3) "{{SessionNameRaw}}" is the role session name, without character
# transliteration (available in version >= 0.5).
mapRoles:
# statically map arn:aws:iam::000000000000:role/KubernetesAdmin to cluster admin
- rolearn: arn:aws:iam::000000000000:role/KubernetesAdmin
username: kubernetes-admin
groups:
- system:masters
# map EC2 instances in my "KubernetesNode" role to users like
# "aws:000000000000:instance:i-0123456789abcdef0". Only use this if you
# trust that the role can only be assumed by EC2 instances. If an IAM user
# can assume this role directly (with sts:AssumeRole) they can control
# SessionName.
- rolearn: arn:aws:iam::000000000000:role/KubernetesNode
username: aws:{{AccountID}}:instance:{{SessionName}}
groups:
- system:bootstrappers
- aws:instances
# map nodes that should conform to the username "system:node:<private-DNS>". This
# requires the authenticator to query the EC2 API in order to discover the private
# DNS of the EC2 instance originating the authentication request.
# {{EC2PrivateDNSName}} is resolved by using the session name as an EC2 instance
# ID and calling ec2:DescribeInstances. Note that if this role is assumed directly
# by an IAM User (not via federation), the user can set the session name to any
# instance ID, resolving another instance's private DNS and impersonating that node.
# Optionally, you may specify a role that should be assumed before querying the EC2 API with the
# key "server.ec2DescribeInstancesRoleARN" (see above).
- rolearn: arn:aws:iam::000000000000:role/KubernetesNode
username: system:node:{{EC2PrivateDNSName}}
groups:
- system:nodes
- system:bootstrappers
# map federated users in my "KubernetesAdmin" role to users like
# "admin:alice-example.com". The SessionName is an arbitrary role name
# like an e-mail address passed by the identity provider. Note that if this
# role is assumed directly by an IAM User (not via federation), the user
# can control the SessionName.
- rolearn: arn:aws:iam::000000000000:role/KubernetesAdmin
username: admin:{{SessionName}}
groups:
- system:masters
# map federated users in my "KubernetesOtherAdmin" role to users like
# "alice-example.com". The SessionName is an arbitrary role name
# like an e-mail address passed by the identity provider. Note that if this
# role is assumed directly by an IAM User (not via federation), the user
# can control the SessionName. Note that the "{{SessionName}}" macro is
# quoted to ensure it is properly parsed as a string.
- rolearn: arn:aws:iam::000000000000:role/KubernetesOtherAdmin
username: "{{SessionName}}"
groups:
- system:masters
# If unalterable identification of an IAM User is desirable, you can map against
# AccessKeyID.
- rolearn: arn:aws:iam::000000000000:role/KubernetesOtherAdmin
username: "admin:{{AccessKeyID}}"
groups:
- system:masters
# each mapUsers entry maps an IAM user to a static username and set of groups
mapUsers:
# map user IAM user Alice in 000000000000 to user "alice" in group "system:masters"
- userarn: arn:aws:iam::000000000000:user/Alice
username: alice
groups:
- system:masters
# automatically map IAM ARN from these accounts to username.
# NOTE: Always use quotes to avoid the account numbers being recognized as numbers
# instead of strings by the yaml parser.
mapAccounts:
- "012345678901"
- "456789012345"
# source mappings from this file (mapUsers, mapRoles, & mapAccounts)
backendMode:
- MountedFileDevelopment
See the development page.
Community, discussion, contribution, and support
Learn how to engage with the Kubernetes community on the community page.
You can reach the maintainers of this project at:
Code of conduct
Participation in the Kubernetes community is governed by the Kubernetes Code of Conduct.