Skip to main content

AWS CLI authentication

authentik: 2025.12.0+

You can use the authentik Agent to authenticate to the AWS CLI with authentik credentials. The Agent exchanges them for temporary AWS credentials through one of two federation methods:

  • SAML federation: reuses the SAML application and provider from the AWS Classic IAM integration. The Agent calls AWS STS AssumeRoleWithSAML.
  • OIDC federation: uses a dedicated OAuth2/OpenID Connect application and provider for AWS. The Agent calls AWS STS AssumeRoleWithWebIdentity.

Both methods also work for Amazon EKS.

Version compatibility

SAML federation requires authentik 2026.11 or later. authentik Agent 0.72.5 or later is required for SAML federation and aws-eks authentication.

Prerequisites​

Both federation methods use the Agent's authentik-cli provider. SAML federation reuses your AWS SAML provider instead of adding a second OAuth2/OpenID Connect provider.

authentik configuration​

Allow token exchange to the SAML provider​

If you already use authentik for AWS Classic IAM console SSO, reuse that application and provider. Otherwise, complete the AWS Classic IAM integration guide first, including its AWS role and role session name property mappings. This method does not use AWS IAM Identity Center.

Allow the Agent's provider to exchange its tokens for a SAML response from the AWS SAML provider:

  1. Log in to authentik as an administrator and open the authentik Admin interface.
  2. Navigate to Applications > Providers and edit the authentik-cli OAuth2 provider used by the Agent.
  3. Under Protocol settings > Grant Types, select Token exchange and keep the existing grant types selected.
  4. Click Save Changes.
  5. Edit the AWS SAML provider.
  6. Expand Machine-to-Machine authentication settings and add the authentik-cli provider to Federated OAuth2/OpenID Providers.
  7. Click Save Changes.

The SAML application's bindings must allow the user.

AWS configuration​

Configure the IAM role for SAML federation​

  1. Reuse an IAM role from your AWS Classic IAM integration, or create an IAM role for SAML federation.
  2. Verify the role trust policy. It must trust the IAM SAML identity provider for sts:AssumeRoleWithSAML.
  3. Bind the user to the application entitlement whose name matches this role. The user's SAML assertion only includes roles from their entitlements.
  4. Take note of the role ARN and the SAML identity provider ARN. You need both for the AWS CLI configuration.

The role's permissions policies decide what the user can do in AWS.

AWS CLI configuration​

On the device where you run the AWS CLI, configure the default profile in ~/.aws/config to get temporary credentials from the authentik Agent through an external credential process. If ak is not on your PATH, use its full path in credential_process.

~/.aws/config
[default]
region = <region>
credential_process = ak auth aws --audience <application_slug> --principal-arn arn:aws:iam::<account_id>:saml-provider/<saml_provider_name> --role-arn arn:aws:iam::<account_id>:role/<role_name> --region <region>
SettingValue
--audienceSlug or UUID of the authentik SAML application.
--principal-arnARN of the SAML identity provider in AWS IAM.
--role-arnARN of the IAM role to assume. It must match a role and provider pair in the user's SAML assertion.
--regionAWS region that the Agent uses for STS.
regionDefault AWS region that the AWS CLI uses for this profile.

These settings are independent: region sets the AWS CLI's default region, while --region selects the region for the Agent's STS requests. The examples use the same value for both.

--audience identifies the authentik application. It is not the SAML provider's Audience setting, which is urn:amazon:webservices for AWS.

To verify, run:

aws sts get-caller-identity

The command outputs the assumed role:

{
"UserId": "<role_id>:<session_name>",
"Account": "<account_id>",
"Arn": "arn:aws:sts::<account_id>:assumed-role/<role_name>/<session_name>"
}

With SAML federation, the session name comes from the RoleSessionName property mapping. With OIDC federation, it is the user's preferred_username. This command checks that the Agent can get credentials, not that the role can access any AWS resources.

Amazon EKS authentication​

ak auth aws-eks is a kubectl exec credential plugin that authenticates to Amazon EKS through AWS IAM. Unlike ak auth kubectl, it does not require OIDC configuration on the Kubernetes API server.

The command gets AWS credentials through SAML or OIDC federation, the same way as ak auth aws, and returns an EKS token to kubectl. It does not use the AWS CLI profile.

Authorize the IAM role in EKS​

An IAM role does not have Kubernetes permissions by default. Grant the role access to the cluster with an EKS access entry, which requires the cluster's authentication mode to be API or API_AND_CONFIG_MAP. Associate an EKS access policy, or Kubernetes groups with RBAC permissions, that grants only what the user needs. If the cluster uses ConfigMap authentication, you can map the role in the aws-auth ConfigMap instead.

Use the IAM role ARN, arn:aws:iam::<account_id>:role/<role_name>, not an STS assumed-role ARN.

Configure kubectl for EKS​

  1. Complete the authentik configuration and AWS configuration for your federation method.

  2. Add a user to your kubeconfig, usually ~/.kube/config. This example uses SAML federation:

    users:
    - name: authentik-eks
    user:
    exec:
    apiVersion: client.authentication.k8s.io/v1
    command: ak
    args:
    - auth
    - aws-eks
    - --audience=<application_slug>
    - --principal-arn=arn:aws:iam::<account_id>:saml-provider/<saml_provider_name>
    - --role-arn=arn:aws:iam::<account_id>:role/<role_name>
    - --region=<region>
    - --cluster=<cluster_name>
    interactiveMode: IfAvailable

    Set --cluster to the EKS cluster name and --region to the cluster's AWS region. The other arguments are the same as in the AWS CLI configuration. For OIDC federation, replace --audience and --principal-arn with --client-id=authentik-aws-cli.

    The client.authentication.k8s.io/v1 exec credential plugin API requires interactiveMode.

  3. Add a context that pairs the authentik-eks user with the EKS cluster, and switch to it. If your kubeconfig has no entry for the cluster yet, add one with the cluster's API server endpoint and certificate authority data from the EKS console or aws eks describe-cluster.

  4. To verify, run a command that the role's cluster permissions allow, for example:

    kubectl get namespaces