

# Control access with agent and workload identity

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

When a workload with an agent or workload identity calls an AWS service, the resource sees which workload is calling, not only which role it used. You allow or deny access by workload. For example, an Amazon S3 bucket can let one workload read it, even when other workloads use the same role.

The identity arrives as condition keys on the workload's role session. Most policies need two: `aws:OriginIdentity/Subject`, the workload's identifier, and `aws:OriginIdentity/Issuer`, your provider's ARN. The same keys decide which workloads can get a JSON Web Token SPIFFE Verifiable Identity Document (JWT-SVID) or X.509 SPIFFE Verifiable Identity Document (X.509-SVID), the credentials a workload uses to prove its identity outside AWS. For the full list of keys, see [Condition keys for agent and workload identity](workload-identity-condition-keys.md) and AWS global condition context keys.


| Policy | Where | Decides | 
| --- | --- | --- | 
| Attestation policy | Template | Which workloads can receive the identity. See [Write attestation policies](workload-identity-attestation-policies.md). | 
| Pass permission in an identity-based policy | The person who configures the resource | Who can assign a template to a resource. See [Permission to assign a template](workload-identity-attestation-policies.md#wi-ap-pass). | 
| Role trust policy | IAM role | Whether the service that runs the workload can assume the role. Agent and workload identity needs no change to it. | 
| Resource-based policy | Amazon S3 bucket, AWS Key Management Service (AWS KMS) key, Amazon Simple Queue Service (Amazon SQS) queue, and others | Whether a specific workload can access the resource | 
| Identity-based policy or service control policy (SCP) | IAM role, user, or organization | Who can manage workload identity resources, and which external credentials a workload can request | 

**Match the subject and issuer together**  
An identifier is unique only within its provider. In every resource-based policy, match `aws:OriginIdentity/Subject` together with `aws:OriginIdentity/Issuer`. Use string condition operators, such as `StringEquals` and `StringNotEquals`, for both keys, even though the issuer of an agent or workload identity is an ARN. `aws:OriginIdentity/Issuer` also carries issuers that aren't ARNs, and a statement that uses an ARN condition operator might not take effect when the value isn't an ARN.

An agent or workload identity isn't an IAM principal. Name it in the Condition element, not the Principal element.

**Topics**
+ [Role trust policies](#wi-ca-role-trust)
+ [Resource-based policies](#wi-ca-resource-based)
+ [Identity-based policies for managing agent and workload identity](#wi-ca-manage)
+ [Identity-based policies for external credentials](#wi-ca-external-creds)
+ [Condition keys for agent and workload identity](workload-identity-condition-keys.md)

## Role trust policies
<a name="wi-ca-role-trust"></a>

The role's trust policy doesn't change. It already lets the service that runs the workload assume the role, such as `pods.eks.amazonaws.com` for EKS Pod Identity. AWS Security Token Service (AWS STS) attaches the identity without an `sts:SetContext` statement or any new condition. An explicit Deny on `sts:SetContext` in the trust policy still applies.

AWS STS checks the following, whatever the trust policy says:
+ It issued the context for this role.
+ The requested session isn't longer than the attesting service allowed.
+ The template still exists.

The role must be in the account where the workload runs. For an organization-level template, that account must be in the template's organization. The role can't be in a different partition.

### Optional: allow only workloads from your provider
<a name="wi-ca-role-trust-provider"></a>

To let only workloads with an identity from your provider use the role, add conditions on `sts:RequestContextProviders` to the statement that lets the service assume the role. Use `ForAllValues:StringEquals` with a `Null` check. `ForAllValues` alone also matches a request that carries no context, so the `Null` check is what requires one. Use a string condition operator, because this key can also carry the providers of trusted identity propagation contexts. With this statement, pods without an agent and workload identity can no longer use the role.

```json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "AllowOnlyPaymentsProdWorkloads",
    "Effect": "Allow",
    "Principal": { "Service": "pods.eks.amazonaws.com" },
    "Action": ["sts:AssumeRole", "sts:TagSession"],
    "Condition": {
      "ForAllValues:StringEquals": { "sts:RequestContextProviders": "arn:aws:iam::111122223333:workload-identity-provider/payments-prod" },
      "Null": { "sts:RequestContextProviders": "false" }
    }
  }]
}
```

## Resource-based policies
<a name="wi-ca-resource-based"></a>

Use `aws:OriginIdentity/Subject` and `aws:OriginIdentity/Issuer` to allow or deny a specific workload. The workload identity stays on the session when the workload assumes another role in the same account, or in another account in the same organization. When the workload assumes a role in a different organization, AWS STS drops the agent and workload identity keys, and the new session has no workload identity. If the workload's account isn't in an organization, the identity carries over only to roles in the same account.

### Allow only one workload to read a bucket, whichever role it uses
<a name="wi-ca-rb-one-workload"></a>

```json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "AllowCheckoutWorkload",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
    "Condition": {
      "StringEquals": {
        "aws:PrincipalOrgID": "o-a1b2c3d4e5",
        "aws:OriginIdentity/Subject": "spiffe://111122223333.aws.internal/us-east-1/eks/prod-cluster-1/ns/payments/sa/checkout-sa",
        "aws:OriginIdentity/Issuer": "arn:aws:iam::111122223333:workload-identity-provider/payments-prod"
      }
    }
  }]
}
```

In a policy that allows `"Principal": "*"`, also include `aws:PrincipalOrgID`, `aws:PrincipalAccount`, or `aws:PrincipalArn`. S3 Block Public Access decides whether a policy is public from a fixed list of condition keys like these, so a policy limited only by agent and workload identity keys counts as public.

### Deny workloads outside one path or from another provider
<a name="wi-ca-rb-deny"></a>

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyWorkloadsOutsidePath",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:*",
      "Resource": ["arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*"],
      "Condition": {
        "Null": { "aws:OriginIdentity/WorkloadIdentityTemplateArn": "false" },
        "StringNotLike": { "aws:OriginIdentity/Subject": "spiffe://111122223333.aws.internal/us-east-1/eks/prod-cluster-1/*" }
      }
    },
    {
      "Sid": "DenyWorkloadsFromOtherProviders",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:*",
      "Resource": ["arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*"],
      "Condition": {
        "Null": { "aws:OriginIdentity/WorkloadIdentityTemplateArn": "false" },
        "StringNotEquals": { "aws:OriginIdentity/Issuer": "arn:aws:iam::111122223333:workload-identity-provider/payments-prod" }
      }
    }
  ]
}
```

The `Null` condition limits both statements to sessions that carry an agent or workload identity. Sessions from IAM federation have no template ARN, and these statements don't deny them. The second statement is there because another provider can issue an identifier with the same path. Both statements use `s3:*`, which denies a workload that doesn't match every S3 action on the bucket.

## Identity-based policies for managing agent and workload identity
<a name="wi-ca-manage"></a>

### Allow a platform team to manage templates under one prefix
<a name="wi-ca-manage-prefix"></a>

`iam:WorkloadIdentityPathPrefix` is present on every template action except `iam:ListWorkloadIdentityTemplates`. This example limits those actions to templates under team A's path prefix. Listing templates can't be limited by prefix, so it's in its own statement.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ManageTemplatesUnderTeamPrefix",
      "Effect": "Allow",
      "Action": [
        "iam:CreateWorkloadIdentityTemplate",
        "iam:AssociateWorkloadIdentityTemplate",
        "iam:DisassociateWorkloadIdentityTemplate",
        "iam:PutWorkloadIdentityTemplateAttestationPolicy",
        "iam:GetWorkloadIdentityTemplateAttestationPolicy",
        "iam:GetWorkloadIdentityTemplate",
        "iam:DeleteWorkloadIdentityTemplate"
      ],
      "Resource": "*",
      "Condition": { "StringLike": { "iam:WorkloadIdentityPathPrefix": ["team-a", "team-a/*"] } }
    },
    {
      "Sid": "ListTemplates",
      "Effect": "Allow",
      "Action": ["iam:ListWorkloadIdentityProviders", "iam:ListWorkloadIdentityTemplates"],
      "Resource": "*"
    }
  ]
}
```

### Keep templates inside approved prefixes (SCP)
<a name="wi-ca-manage-scp"></a>

```json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "DenyTemplatesOutsideTeamPrefixes",
    "Effect": "Deny",
    "Action": "iam:CreateWorkloadIdentityTemplate",
    "Resource": "*",
    "Condition": {
      "StringNotLike": { "iam:WorkloadIdentityPathPrefix": ["team-a", "team-a/*", "team-b", "team-b/*", "platform/shared", "platform/shared/*"] }
    }
  }]
}
```

### Allow a person to assign an identity to a resource
<a name="wi-ca-manage-pass"></a>

```json
{
  "Effect": "Allow",
  "Action": "iam:PassWorkloadIdentityTemplate",
  "Resource": "arn:aws:iam::111122223333:workload-identity-template/eks-prod-1",
  "Condition": { "StringEquals": { "iam:PassedToService": "pods.eks.amazonaws.com" } }
}
```

For AgentCore, set `iam:PassedToService` to `bedrock-agentcore.amazonaws.com`.

### Permissions for using the console
<a name="wi-ca-manage-console"></a>

To manage agent and workload identity in the IAM console, a person needs the IAM actions in IAM: Manage agent and workload identity resources, plus these actions that the console uses:
+ `iam:DeleteWorkloadIdentityProviderOutboundSigner` – To delete a signer on the Outbound signer page. The example policy leaves it out on purpose.
+ `iam:ListWorkloadIdentities` – The console calls it on a provider's Provider summary page and when you delete a provider.
+ `organizations:DescribeOrganization` and `organizations:ListDelegatedAdministrators` – Without them, the console doesn't show organization-level providers, and it treats a delegated administrator account as a member account.
+ `iam:ListOrganizationsFeatures` and `iam:EnableOrganizationLevelResources` – To check and turn on organization-level IAM resources from the management account.
+ `acm-pca:ListCertificateAuthorities` and `acm-pca:DescribeCertificateAuthority` – To list the service-affiliated CAs that you can attach to a provider.
+ `acm-pca:CreateCertificateAuthority`, `acm-pca:TagCertificateAuthority`, `acm-pca:GetCertificateAuthorityCsr`, `acm-pca:IssueCertificate`, `acm-pca:GetCertificate`, and `acm-pca:ImportCertificateAuthorityCertificate` in US East (N. Virginia) us-east-1 – To create a CA with Create new on the Outbound signer page.
+ `acm-pca:DescribeCertificateAuthority`, `acm-pca:GetCertificateAuthorityCertificate`, `acm-pca:CreateCertificateAuthorityAssociation`, and `acm-pca:DeleteCertificateAuthorityAssociation` in us-east-1 – IAM makes these calls with your credentials when you create, update, or delete an X.509 signer. For more information, see [Configure signing and the trust bundle](workload-identity-signing-trust-bundle.md).

## Identity-based policies for external credentials
<a name="wi-ca-external-creds"></a>

To request a JWT-SVID or X.509-SVID, the workload's role needs permission, scoped to its own identity. A role can get a credential only for the identity that its session already carries.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "JwtSvidForOwnIdentity",
      "Effect": "Allow",
      "Action": "sts:GetWebIdentityToken",
      "Resource": "*",
      "Condition": {
        "StringLike": { "aws:OriginIdentity/Subject": "spiffe://111122223333.aws.internal/us-east-1/eks/prod-cluster-1/*" }
      }
    },
    {
      "Sid": "X509SvidForOwnIdentity",
      "Effect": "Allow",
      "Action": "sts:GetCertificate",
      "Resource": "*",
      "Condition": {
        "StringLike": { "aws:OriginIdentity/Subject": "spiffe://111122223333.aws.internal/us-east-1/eks/prod-cluster-1/*" }
      }
    }
  ]
}
```

`sts:GetWebIdentityToken` and `sts:GetCertificate` don't support resource-level permissions, so Resource is `*`. The condition allows the request only when the session's workload identity belongs to prod-cluster-1. Sessions of this role from other clusters, or without a workload identity, can't request these credentials.

A JWT-SVID never outlives the role session that requested it. An X.509-SVID lasts 12 hours by default. To issue shorter certificates, set MaxDurationSeconds in the request. On Amazon EKS, X.509-SVIDs are valid for 12 hours during the preview.

**Roles that already use outbound identity federation**  
If a role already allows `sts:GetWebIdentityToken` for outbound identity federation, it can request JWT-SVIDs for its own identity without a new grant. To restrict this, add a condition on `sts:TokenType`, whose values are AWSIdentity and JWT\_SVID. A request that doesn't set a token type is evaluated as AWSIdentity. For example, to keep a role on outbound identity federation tokens only, add `"StringEquals": { "sts:TokenType": "AWSIdentity" }` to its existing statement.

For the AWS Private Certificate Authority (AWS Private CA) permissions that the workload's role needs, see [Authenticate to services outside AWS](workload-identity-authenticate-external.md).