View a markdown version of this page

Create workload identity templates - AWS Identity and Access Management

Create workload identity templates

Preview release

Agent and workload identity is in preview release for AWS Identity and Access Management (IAM) and is subject to change.

A template builds a unique identifier for every workload in a group from facts that the attesting service reports. You create a template in one of two ways:

  • From a template definition. An AWS service publishes a definition with the path pattern and attestation policy already written. You supply a name and a provider. This is the recommended path.

  • With a custom path pattern. You write the pattern and the attestation policy yourself.

Template definitions

Definition

Use with

Example identifier

eks.amazonaws.com/org-provider-account-template-default:1

Organization-level provider, template in a member account

spiffe://corp.example.com/111122223333/us-west-2/eks/cluster-1/ns/payments/sa/checkout-sa

eks.amazonaws.com/account-provider-default:1

Account-level provider

spiffe://111122223333.aws.internal/us-west-2/eks/cluster-1/ns/payments/sa/checkout-sa

eks.amazonaws.com/account-provider-mesh:1

Account-level provider, for an Amazon EKS cluster under a service mesh, such as Istio

spiffe://eks-cluster-1.us-west-2.111122223333.aws.internal/ns/payments/sa/checkout-sa

bedrock-agentcore.amazonaws.com/runtime/org-provider-account-template-default:1

Organization-level provider, template in a member account

spiffe://corp.example.com/111122223333/us-west-2/bedrock-agentcore/runtime/claims_processor/claims_processor-a1b2c3d4e5

bedrock-agentcore.amazonaws.com/runtime/org-provider-account-template-session:1

Organization-level provider, template in a member account, one identity for each runtime session

spiffe://corp.example.com/111122223333/us-west-2/bedrock-agentcore/runtime/claims_processor/claims_processor-a1b2c3d4e5/<session-id>

bedrock-agentcore.amazonaws.com/runtime/account-provider-default:1

Account-level provider

spiffe://111122223333.aws.internal/us-west-2/bedrock-agentcore/runtime/claims_processor/claims_processor-a1b2c3d4e5

bedrock-agentcore.amazonaws.com/runtime/account-provider-session:1

Account-level provider, one identity for each runtime session

spiffe://111122223333.aws.internal/us-west-2/bedrock-agentcore/runtime/claims_processor/claims_processor-a1b2c3d4e5/<session-id>

bedrock-agentcore.amazonaws.com/gateway/org-provider-account-template-default:1

Organization-level provider, template in a member account

spiffe://corp.example.com/111122223333/us-west-2/bedrock-agentcore/gateway/payments-tools/payments-tools-a1b2c3d4e5

bedrock-agentcore.amazonaws.com/gateway/account-provider-default:1

Account-level provider

spiffe://111122223333.aws.internal/us-west-2/bedrock-agentcore/gateway/payments-tools/payments-tools-a1b2c3d4e5

All definition ARNs start with arn:aws:iam::aws:workload-identity-template-definition/. For one template that serves your whole organization, there's no definition. Create it in the IAM console, which fills in the path pattern with the account ID as its first segment.

For details about each definition, see Amazon EKS and Amazon Bedrock AgentCore.

Where the account ID goes. A cluster, runtime, or gateway name or ID is unique only within one account and Region, so the account ID appears in every identifier exactly once. Where it goes depends on how you set up the provider and template:

Setup

Where the account ID goes

Example identifier (AgentCore runtime, a capability of Amazon Bedrock AgentCore)

One template for the whole organization, under an organization-level provider

First segment of the path pattern

spiffe://corp.example.com/111122223333/us-west-2/bedrock-agentcore/runtime/claims_processor/claims_processor-a1b2c3d4e5

A template in each member account, under an organization-level provider

Path prefix

spiffe://corp.example.com/111122223333/us-west-2/bedrock-agentcore/runtime/claims_processor/claims_processor-a1b2c3d4e5

Account-level provider

Trust domain

spiffe://111122223333.aws.internal/us-west-2/bedrock-agentcore/runtime/claims_processor/claims_processor-a1b2c3d4e5

Because the first two produce the same identifier, you can move between a central template and per-account templates without changing identifiers.

Create a template from a definition

You need iam:CreateWorkloadIdentityTemplate and iam:PutWorkloadIdentityTemplateAttestationPolicy, because the definition writes an attestation policy for you. Under an organization-level provider, you also need iam:AssociateWorkloadIdentityTemplate on the provider.

Console

  1. In the IAM console navigation pane, choose Agent and workload identity, and then choose Templates for your provider. In a member account, choose your organization's provider.

  2. Choose Add templates.

  3. On the card for the service, such as Amazon EKS, Amazon Bedrock AgentCore Runtime, or Amazon Bedrock AgentCore Gateway, choose Add.

  4. Keep or change the prefilled Name, and optionally enter a Description. A name can have up to 128 letters, digits, underscores (_), and hyphens (-), and must be unique in your account. A description can have up to 1,000 characters.

  5. Review the Identity path and the generated Attestation policy. In a member account, the path starts with your account ID. The console shows each placeholder in a short form, such as {aws/eks/Namespace} for {aws:WorkloadAttestation/aws/eks/Namespace}.

  6. Choose Add template.

To create a template for an EKS cluster under a service mesh, use the service mesh setup instead. For more information, see Amazon EKS.

The Amazon EKS and AgentCore consoles can also create a template for you from their own definitions. For more information, see Use agent and workload identity with AWS services.

AWS CLI

aws iam create-workload-identity-template \ --template-definition '{ "TemplateDefinitionArn": "arn:aws:iam::aws:workload-identity-template-definition/eks.amazonaws.com/account-provider-default:1", "ReplacementValues": { "Name": { "Values": ["eks-prod-1"] }, "WorkloadIdentityProviderArn": { "Values": ["arn:aws:iam::111122223333:workload-identity-provider/payments-prod"] } } }'

On this path, pass everything inside ReplacementValues, including Name, WorkloadIdentityProviderArn, and, for an org-provider-account-template-* definition, PathPrefix. To tag the template, use the top-level --tags parameter. ReplacementValues doesn't take tags. Tag keys must use a single casing. If a key differs from another key only in case, such as env and ENV, IAM rejects the request with InvalidInput (InvalidInputException in the SDKs). The definition fixes the attestation policy. IAM fills in your account or organization from the request, and you can't override it.

The response returns the path pattern and attestation policy that IAM wrote:

{ "Arn": "arn:aws:iam::111122223333:workload-identity-template/eks-prod-1", "PathPattern": "{aws:RequestedRegion}/eks/{aws:WorkloadAttestation/aws/eks/ClusterName}/ns/{aws:WorkloadAttestation/aws/eks/Namespace}/sa/{aws:WorkloadAttestation/aws/eks/ServiceAccount}", "AttestationPolicy": "{ ... \"Principal\": { \"Service\": \"pods.eks.amazonaws.com\" } ... \"aws:SourceAccount\": \"111122223333\" ... }" }

AWS API

IAM API Reference: CreateWorkloadIdentityTemplate

Create a template with a custom path pattern

Write your own pattern when the definitions don't fit, for example to drop the Region so an identity stays the same across Regions.

In the console, you can customize a template in these ways:

Customization

What you can do

Path prefix (optional)

Enter a prefix for every identity under the template, so that you can match it in IAM policies. It can contain letters, digits, periods (.), hyphens (-), and underscores (_), with single slashes (/) between parts and no slash at the start or end.

Reorder or remove segments

Drag a segment by its handle to move it, or choose × to remove it. Keep the Region first, and for an organization-level provider the account ID, so that identifiers stay unique across accounts and Regions.

Reset the path

Choose Reset to default to restore the definition's pattern.

Add a segment

Add an attested fact from the service, such as ClusterName for Amazon EKS, one of three AWS global condition keys (aws:SourceAccount, aws:SourceOrgID, or aws:RequestedRegion), or custom text, such as an environment name. For an account-level provider, use aws:SourceAccount. For an organization-level provider, you can add aws:SourceOrgID, but keep the account ID segment too, because the organization ID is the same in every account.

Check the result

The console shows the full identifier that the pattern produces, for example spiffe://o-a1b2c3d4e5.aws.internal/111122223333/us-east-1/eks/prod-cluster-1/ns/payments/sa/checkout-sa.

You can't change the path prefix or the path after you create the template.

Path pattern rules

  • Each segment is either plain text or exactly one placeholder. {aws:WorkloadAttestation/aws/eks/ClusterName}-123 isn't allowed, and neither are two placeholders in one segment.

  • A placeholder names an attestation key of the service in your attestation policy, such as {aws:WorkloadAttestation/aws/eks/Namespace}. It can also name an AWS global condition key that AWS Security Token Service (AWS STS) fills from the request, such as {aws:SourceAccount} or {aws:RequestedRegion}. In the IAM console, a path segment in a template for Amazon EKS, AgentCore runtime, or AgentCore Gateway can use only aws:SourceAccount, aws:SourceOrgID, and aws:RequestedRegion.

  • The pattern must contain at least one placeholder. A pattern without one would give every workload the same name.

  • Keys that describe the caller rather than the workload, such as {aws:userid}, aren't allowed.

  • {aws:WorkloadAttestation/aws/eks/ClusterArn} can't be used in a path pattern. To match a cluster ARN, use aws:WorkloadAttestation/aws/eks/ClusterArn in the attestation policy instead.

  • Every placeholder must be a key that the service named in the attestation policy can present. Otherwise, IAM rejects the policy.

At runtime, if an attested value that the pattern uses is missing, issuance fails with InvalidAttestationDocument (reason unresolvedTemplateVariable). If a value contains a slash or breaks the segment rule, issuance fails with InvalidWorkloadIdentityConfiguration (reason unrenderableTemplate). A template that's valid when you create it can still fail with reason identifierTooLarge if attested values make the identifier longer than 256 characters.

Keep identifiers unique

If you remove segments that keep workloads apart, such as the account, Region, or cluster, workloads in different places receive the same identifier and share its access. Make sure the remaining segments are unique.

Console

  1. In the IAM console navigation pane, choose Agent and workload identity, choose Templates for your provider, and then choose Add templates.

  2. On the card for the service, choose Add.

  3. Enter a Name and, optionally, a Description.

  4. For Identity path, enter the path pattern. To change the path, choose Edit next to Identity path, update the path, and then choose Save. You can't change the path after you create the template.

  5. For Attestation policy, enter the policy. To change it, choose Edit next to Attestation policy, update the policy, and then choose Save. You can also edit the attestation policy after you create the template. For examples, see Write attestation policies.

  6. Choose Add template.

AWS CLI

aws iam create-workload-identity-template \ --workload-identity-provider-arn arn:aws:iam::o-a1b2c3d4e5:workload-identity-provider/corp-example-prod \ --resource-scope ORGANIZATION \ --name eks-payments \ --path-prefix retail-payments \ --path-pattern 'eks/{aws:WorkloadAttestation/aws/eks/ClusterName}/ns/{aws:WorkloadAttestation/aws/eks/Namespace}/sa/{aws:WorkloadAttestation/aws/eks/ServiceAccount}' \ --attestation-policy file://attestation-policy.json

This example has no account ID or Region in the pattern. Because the template has organization scope, workloads in every member account and Region with the same cluster, namespace, and service account names receive the same identifier. To keep them apart, start the pattern with {aws:SourceAccount}/{aws:RequestedRegion}/.

Creating a template needs iam:CreateWorkloadIdentityTemplate. Under an organization-level provider, it also needs iam:AssociateWorkloadIdentityTemplate on the provider. To pass an attestation policy with the create, you also need iam:PutWorkloadIdentityTemplateAttestationPolicy. If you omit the policy, IAM creates the template, but it issues nothing until you add one.

AWS API

IAM API Reference: CreateWorkloadIdentityTemplate

Create a template from a member account

Under an organization-level provider, a member account creates templates in its own account. The template has a member-account ARN and references the organization's provider.

The caller needs:

  • iam:CreateWorkloadIdentityTemplate in its own account

  • iam:AssociateWorkloadIdentityTemplate on the provider, which the provider's resource policy must allow for that account and path prefix

  • iam:PutWorkloadIdentityTemplateAttestationPolicy, if it passes or a definition writes an attestation policy

aws iam create-workload-identity-template \ --workload-identity-provider-arn arn:aws:iam::o-a1b2c3d4e5:workload-identity-provider/corp-example-prod \ --resource-scope ACCOUNT \ --name eks-checkout \ --path-prefix 111122224444 \ --path-pattern '{aws:RequestedRegion}/eks/{aws:WorkloadAttestation/aws/eks/ClusterName}/ns/{aws:WorkloadAttestation/aws/eks/Namespace}/sa/{aws:WorkloadAttestation/aws/eks/ServiceAccount}' \ --attestation-policy file://attestation-policy.json

Two templates with the same path prefix and path pattern can't exist under one provider. If another account already created one, the call fails with EntityAlreadyExists.

View and delete templates

aws iam list-workload-identity-templates \ --workload-identity-provider-arn arn:aws:iam::o-a1b2c3d4e5:workload-identity-provider/corp-example-prod \ --resource-scope ACCOUNT \ --filter 'service_principal = "pods.eks.amazonaws.com"' aws iam get-workload-identity-template \ --workload-identity-template-arn arn:aws:iam::111122223333:workload-identity-template/eks-prod-1 aws iam delete-workload-identity-template \ --workload-identity-template-arn arn:aws:iam::111122223333:workload-identity-template/eks-prod-1

The filter returns templates whose attestation policy names that service. get-workload-identity-template doesn't return the attestation policy. Read it with get-workload-identity-template-attestation-policy. In the console, open the template and choose Delete template to delete it. To delete a template that references an organization-level provider, you also need iam:DisassociateWorkloadIdentityTemplate on the provider.

IAM doesn't store the identities that a template builds as records, so you can't list them. To find them, search AWS CloudTrail. For more information, see Logging and monitoring agent and workload identity.

AWS API

IAM API Reference: ListWorkloadIdentityTemplates, GetWorkloadIdentityTemplate, DeleteWorkloadIdentityTemplate