View a markdown version of this page

Authenticate to an external system from Amazon EKS with IAM for agents - Amazon EKS

Help improve this page

To contribute to this user guide, choose the Edit this page on GitHub link that is located in the right pane of every page.

Authenticate to an external system from Amazon EKS with IAM for agents

This walkthrough shows a workload in Amazon EKS authenticating to a system outside AWS using only its AWS-issued identity, with no static API key stored in the cluster. The external system here is any API or SaaS platform that accepts a SPIFFE identity delivered as a JWT-SVID and validated through standard OIDC federation. The calling workload does not need to be in a service mesh. A common case is an agent running in EKS that calls an external model or tool API directly, authenticating with its own workload identity rather than a shared key.

Note

IAM for agents is in preview release for Amazon EKS and is subject to change. It is available in all commercial AWS Regions except Middle East (Bahrain) (me-south-1) and Middle East (UAE) (me-central-1).

Why use this

Teams that call an external API often give every workload a long-lived API key. Long-lived keys spread into secret stores, environment variables, and CI systems. They are the credential most likely to leak and the hardest to rotate.

Identity federation removes them. The workload presents a short-lived identity token from its own identity provider, and the external system exchanges it for a short-lived access token scoped to that workload. With IAM for agents, the workload already has a per-workload SPIFFE identity issued by AWS, so it can present that identity directly. The platform team registers the provider with the external system once and writes a rule that allows a specific workload identity. Access becomes an attribute of the workload’s identity rather than a secret that it holds. The result is no static keys in the cluster, per-workload attribution of usage, and revocation by policy rather than by key rotation.

This pattern matters most for agentic workloads. An agent that calls an external model API is exactly where a leaked static key is most dangerous and where per-workload attribution is most valuable.

How the flow fits together

The workload and the external system meet at a standard JWT-SVID. IAM for agents issues one, and the external system consumes one through OIDC federation. The steps below assume that a Pod Identity association already exists for the workload, with workloadIdentityConfig enabled.

The following diagram shows the steps from requesting the token to calling the API.

The workload calls GetWebIdentityToken on STS and receives a new JWT-SVID, then presents it to the external system. The external system fetches the provider’s signing keys and returns a short-lived access token, which the workload uses to call the API.

Step 1: The workload has its SPIFFE identity

When the pod starts, EKS attests it and AWS issues its SPIFFE ID, rendered from the template’s path pattern. This flow does not involve a service mesh, so it uses the default template, which keeps the cluster, Region, and account in the path:

spiffe://acme.prod/111122223333/us-west-2/eks/cluster-1/ns/inference/sa/agent-worker

Any template works for external federation, because the external system matches on the SPIFFE ID in the sub claim, not on any particular path shape. If the same workload also runs in a service mesh, it carries the mesh-template identity instead (spiffe://<trust domain>/ns/<namespace>/sa/<service account>), and it federates the same way. Use whichever template the workload already has.

Step 2: The workload gets a JWT-SVID for the external audience

The workload requests its identity as a JWT-SVID from AWS STS through the AWS SDK, naming the external system as the audience. For example, if the external system expects the audience https://api.example.com, that value appears in the token’s aud claim.

Some external systems accept each token only once. In that case, the workload needs a new JWT-SVID each time it authenticates. Getting the token through the AWS SDK does this, because each call to the GetWebIdentityToken operation of AWS STS, with the token type set to JWT_SVID, the audience set to the external system’s audience, and a signing algorithm that the external system accepts, returns a new token. For a system that accepts each token only once, don’t fetch the token from the EKS Pod Identity agent. The Pod Identity agent caches JWT-SVIDs for each audience and returns the same token to repeated requests, which such a system rejects after its first use. For more information, see The credentials: how the identity is delivered.

The workload’s IAM role must allow sts:GetWebIdentityToken.

The returned JWT-SVID is a signed JWT whose sub is the workload’s SPIFFE ID and whose aud is the external audience:

{ "iss": "https://<issuer-id>.workloads.tokens.sts.global.api.aws", "sub": "spiffe://acme.prod/111122223333/us-west-2/eks/cluster-1/ns/inference/sa/agent-worker", "aud": "https://api.example.com", "iat": 1790000000, "exp": 1790003600, "jti": "<unique token ID>" }

The iss value is the provider’s OIDC issuer URL. <issuer-id> is the identifier assigned to your provider. The external system fetches the provider’s signing keys from this issuer through OIDC discovery.

Step 3: Configure the external system to trust your provider (one time)

The platform team registers the provider’s issuer with the external system and writes a rule that allows the workload. The exact steps and field names depend on the external system, so follow its documentation. In general, you give the external system the following.

  • The provider’s issuer URL. This is the iss value from Step 2. The external system fetches /.well-known/openid-configuration from the issuer URL and follows jwks_uri to retrieve the signing keys, so you do not register or rotate keys yourself.

  • A rule that matches the workload. The rule matches on the workload’s SPIFFE ID, which is the sub claim, and on the audience.

  • A target for the rule. This is what the matching workload is allowed to act as in the external system, for example a service account or a role.

The following examples show the general shape of a registration and a rule. The field names are placeholders and don’t belong to any particular system.

{ "issuer_url": "https://<issuer-id>.workloads.tokens.sts.global.api.aws", "keys": "discovery" }
{ "match": { "subject": "spiffe://acme.prod/111122223333/us-west-2/eks/cluster-1/ns/inference/sa/agent-worker", "audience": "https://api.example.com" }, "target": "<service account or role in the external system>" }

Scope the rule to the narrowest subject that the workload allows, and always require an audience so that tokens minted for other relying parties are rejected.

Step 4: Present the token and call the API

The workload presents its JWT-SVID to the external system, either as a bearer token or to a token-exchange endpoint, depending on the system. The system validates the signature against the issuer’s keys and matches its rule on sub and aud. It then either accepts the request or returns a short-lived access token that the workload uses to call the API. No static API key is stored in the cluster. For the exact request, see the external system’s documentation.

How this maps to the identity model

  • The SPIFFE ID in Step 1 is the identity that the product issues. The JWT-SVID in Step 2 is one of its delivery forms, alongside decorated SigV4 for AWS and X.509-SVIDs for mutual TLS. This flow uses the JWT-SVID form because the external system accepts JWT-SVIDs over OIDC federation.

  • The external system needs nothing beyond standard OIDC federation. It trusts the provider’s issuer and matches a rule on the workload’s SPIFFE ID and the audience.

  • The identity is additive to Pod Identity. The same workload continues to use its IAM role for AWS access while presenting its SPIFFE identity to the external system.

Note

An external system must support identity federation and be configured to trust your provider before it can accept the workload’s identity. A workload’s identity is not accepted automatically simply because it is presented.