

# Write attestation policies

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

An attestation policy decides which workloads can receive an identity. It's attached to a template, and AWS Security Token Service (AWS STS) evaluates it each time the service that runs the workload requests an identity for it: when the workload starts, and on Amazon EKS each time the pod's credentials refresh. If the policy doesn't allow the request, AWS STS issues no identity.

Separately, a person who assigns a template to a resource needs permission to pass it. This page describes both.

## How an attestation policy works
<a name="wi-ap-how"></a>

When a workload starts, the service that runs it calls sts:IssueWorkloadIdentityContext with the template reference and an attestation document of facts about the workload. AWS STS checks the policy against:
+ The calling service, in the Principal element
+ The source account, organization, and resource that the service reports
+ The attested facts, as `aws:WorkloadAttestation/...` condition keys

An attestation policy is an IAM resource-based policy in the standard IAM policy language.

## Policy structure
<a name="wi-ap-structure"></a>

```json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "pods.eks.amazonaws.com" },
    "Action": "sts:IssueWorkloadIdentityContext",
    "Condition": {
      "StringEquals": {
        "aws:SourceAccount": "111122223333",
        "aws:WorkloadAttestation/aws/eks/ClusterName": "prod-cluster-1",
        "aws:WorkloadAttestation/aws/eks/Namespace": "payments",
        "aws:WorkloadAttestation/aws/eks/ServiceAccount": "settlement"
      }
    }
  }]
}
```


| Element | Rule | 
| --- | --- | 
| Principal | The attesting service. On a template, name exactly one service. | 
| Action | sts:IssueWorkloadIdentityContext | 
| Resource | Omit it. IAM sets it to the template that the policy is attached to. | 
| Condition | Only the keys in the next table. | 

### Principals
<a name="wi-ap-principals"></a>


| Service | Principal | 
| --- | --- | 
| Amazon Elastic Kubernetes Service (Amazon EKS) | `pods.eks.amazonaws.com` | 
| AgentCore runtime, a capability of Amazon Bedrock AgentCore, and AgentCore Gateway, a capability of Amazon Bedrock AgentCore | `bedrock-agentcore.amazonaws.com` | 

### Condition keys you can use
<a name="wi-ap-condition-keys"></a>

An attestation policy can use only keys that describe what the attesting service proved. It can't use keys that a caller supplies. IAM checks this when you write the policy.


| Key | Value | 
| --- | --- | 
| `aws:SourceAccount` | The account where the workload runs | 
| `aws:SourceOrgID` | The organization of that account | 
| `aws:SourceOrgPaths` | The organizational unit (OU) path of that account | 
| `aws:SourceArn` | The resource that runs the workload, such as a cluster or runtime | 
| `aws:ResourceAccount` | The account that owns the template | 
| `aws:ResourceTag/<key>` | A tag on the template itself | 
| `aws:WorkloadAttestation/<tier>/<provider>/<key>` | A fact about the workload | 

A condition can use a fact that doesn't appear in the identifier, such as the cluster ARN. If the template's path pattern uses a fact that isn't present at runtime, issuance fails. In the attestation policy, a condition on a missing fact doesn't match, so the request is denied, unless the condition uses an ...IfExists operator such as StringEqualsIfExists.

### Attestation keys and tiers
<a name="attestation-keys-and-tiers"></a>

The middle part of each `aws:WorkloadAttestation` key shows who vouched for the fact. Every key starts with `aws/`, which means that an AWS control plane reported the fact and the workload can't change it.

Available keys:


| Service | Keys | 
| --- | --- | 
| Amazon EKS | `aws/eks/ClusterName`, `aws/eks/Namespace`, `aws/eks/ServiceAccount`, `aws/eks/ClusterArn`, `aws/eks/PodName`, `aws/eks/PodUid`, `aws/eks/NodeName` | 
| AgentCore runtime | `aws/bedrock-agentcore/RuntimeId`, `aws/bedrock-agentcore/RuntimeName`, `aws/bedrock-agentcore/RuntimeVersion`, `aws/bedrock-agentcore/RuntimeSessionId` | 
| AgentCore Gateway | `aws/bedrock-agentcore/GatewayId`, `aws/bedrock-agentcore/GatewayName` | 

Key names aren't case-sensitive, so `aws:workloadattestation/aws/eks/clustername` matches the same fact as `aws:WorkloadAttestation/aws/eks/ClusterName`. Write the tier and provider in lowercase and the key in PascalCase, as shown. Values are case-sensitive.

## Example attestation policies
<a name="wi-ap-examples"></a>

### Any pod in one EKS cluster in one account
<a name="wi-ap-example-eks-cluster"></a>

```json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "pods.eks.amazonaws.com" },
    "Action": "sts:IssueWorkloadIdentityContext",
    "Condition": {
      "StringEquals": { "aws:SourceAccount": "111122224444" },
      "ArnEquals": { "aws:SourceArn": "arn:aws:eks:us-east-1:111122224444:cluster/prod-cluster-1" }
    }
  }]
}
```

### Only production namespaces, in any account in an OU
<a name="wi-ap-example-ou"></a>

The console doesn't offer the `aws:SourceOrgPaths` condition. Use the AWS CLI or API to add this condition.

```json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "pods.eks.amazonaws.com" },
    "Action": "sts:IssueWorkloadIdentityContext",
    "Condition": {
      "StringEquals": { "aws:SourceOrgID": "o-a1b2c3d4e5" },
      "ForAnyValue:StringLike": { "aws:SourceOrgPaths": "o-a1b2c3d4e5/r-ab12/ou-ab12-prod1234/*" },
      "StringLike": { "aws:WorkloadAttestation/aws/eks/Namespace": "prod-*" }
    }
  }]
}
```

### One AgentCore runtime, any version
<a name="wi-ap-example-runtime"></a>

```json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "bedrock-agentcore.amazonaws.com" },
    "Action": "sts:IssueWorkloadIdentityContext",
    "Condition": {
      "StringEquals": {
        "aws:SourceAccount": "444455556666",
        "aws:WorkloadAttestation/aws/bedrock-agentcore/RuntimeId": "claims_processor-a1b2c3d4e5"
      }
    }
  }]
}
```

## Add, replace, or remove an attestation policy
<a name="wi-ap-manage"></a>

### Console
<a name="wi-ap-manage-console"></a>

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

1. On the **Attestation** tab, choose **Edit**, or choose **Add policy** if it has none.

1. Choose where the workload is hosted, and add or change conditions in the visual editor. To view the policy as JSON, choose **JSON**.

1. Choose **Save changes**.

To remove the policy, open the **Attestation** tab, and then choose **Remove**.

### AWS CLI
<a name="wi-ap-manage-cli"></a>

```bash
aws iam put-workload-identity-template-attestation-policy \
  --workload-identity-template-arn arn:aws:iam::111122223333:workload-identity-template/eks-prod-1 \
  --attestation-policy file://attestation-policy.json
aws iam get-workload-identity-template-attestation-policy \
  --workload-identity-template-arn arn:aws:iam::111122223333:workload-identity-template/eks-prod-1
aws iam delete-workload-identity-template-attestation-policy \
  --workload-identity-template-arn arn:aws:iam::111122223333:workload-identity-template/eks-prod-1
```

A put replaces the whole policy. IAM checks that the policy's principal can present every placeholder in the path pattern.

### AWS API
<a name="wi-ap-manage-api"></a>

IAM API Reference: `PutWorkloadIdentityTemplateAttestationPolicy` and the matching Get and Delete operations

## Permission to assign a template
<a name="wi-ap-pass"></a>

Before a service such as Amazon EKS stores a template on one of its resources, it checks that you're allowed to pass it. This works like iam:PassRole. The caller's identity-based policy must allow iam:PassWorkloadIdentityTemplate on the template, with iam:PassedToService set to the service's principal.

The template must be in the caller's account, or be an organization-level template. For an organization-level template, AWS STS checks at each issuance that the account where the workload runs is in the template's organization.

```json
{
  "Effect": "Allow",
  "Action": "iam:PassWorkloadIdentityTemplate",
  "Resource": "arn:aws:iam::444455556666:workload-identity-template/agentcore-runtimes",
  "Condition": { "StringEquals": { "iam:PassedToService": "bedrock-agentcore.amazonaws.com" } }
}
```

The check runs once, when you save the resource. If you later remove the permission, resources that are already configured keep their template. To stop a workload from receiving the identity, change the attestation policy or delete the template, as described in [Stop issuing an identity and deny its access](#wi-ap-revoke).

**The attestation policy protects the identity**  
The pass check is a configuration-time control. The attestation policy is what protects the identity at runtime.

## Stop issuing an identity and deny its access
<a name="wi-ap-revoke"></a>

You do this in two ways. Changing the attestation policy stops AWS STS from issuing the identity to new instances of a workload. A Deny on the identifier takes access away from a workload that already carries it. Use both when you need an identity cut off quickly.


| To | Do this | Effect | 
| --- | --- | --- | 
| Stop issuing the identity to new instances of a workload | Change the template's attestation policy to exclude the workload, or delete the policy to exclude every workload | A new instance receives no identity. On Amazon EKS, a new pod for that service account gets no AWS credentials, JWT-SVIDs, or X.509-SVIDs. Other workloads under the template are unaffected. | 
| Deny all access for the identity | Add a Deny on all actions to the workload's role, with conditions on the workload's identifier and provider | The workload's AWS calls fail, and it gets no new JWT-SVIDs or X.509-SVIDs. Other workloads that use the role are unaffected. | 
| Deny new JWT-SVIDs for the identity | Add a Deny on sts:GetWebIdentityToken to the workload's role, with the same conditions | The workload gets no new JWT-SVIDs. Its AWS calls and certificates continue. | 
| Stop issuing every identity under a template | Delete the template | AWS STS issues no new identities, and no service can refresh a session. Sessions that were already issued can't get new JWT-SVIDs or X.509-SVIDs. | 
| Remove one resource's association | Remove the template from the resource, in that service | Workloads that start after the change don't receive the identity. On Amazon EKS, the change applies to pods created after it, so restart running pods to remove the identity from them. | 

The first three controls typically take effect within a minute.

A put replaces the whole attestation policy. Read the current policy first, and keep the statements for the workloads that stay.

### What a running workload keeps
<a name="wi-ap-revoke-running"></a>

Changing the attestation policy doesn't take the identity away from a workload that is already running. On Amazon EKS, a running pod keeps its credentials and keeps getting JWT-SVIDs until EKS renews its role session. That can take up to 6 hours, or 59 minutes when the Pod Identity association uses a target role. For more information, see the Amazon EKS User Guide. To apply the change to running pods sooner, restart them. On a service that refreshes sessions without attesting the workload again, a running workload continues until you delete the template.

No control cancels a credential that the workload already holds:
+ An X.509 SPIFFE Verifiable Identity Document (X.509-SVID) stays valid until it expires. On Amazon EKS, X.509-SVIDs are valid for 12 hours during the preview. Certificates can't be revoked.
+ A JSON Web Token SPIFFE Verifiable Identity Document (JWT-SVID) stays valid until it expires, up to 1 hour.

Relying parties keep accepting both for that time, because your provider's keys stay in its trust bundle. Keep certificate and token durations short where the service lets you set them. For how long keys stay published, see [Configure signing and the trust bundle](workload-identity-signing-trust-bundle.md) and [Delete a provider](workload-identity-manage-providers.md#wi-mp-delete).

### Deny an identity on its role
<a name="wi-ap-revoke-deny"></a>

Add this statement to an inline policy on the workload's role. It applies only to sessions that carry this identifier from this provider.

```json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "DenyCheckoutIdentity",
    "Effect": "Deny",
    "Action": "*",
    "Resource": "*",
    "Condition": {
      "StringEquals": {
        "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"
      }
    }
  }]
}
```

To deny only new JWT-SVIDs, change `"Action": "*"` to `"Action": "sts:GetWebIdentityToken"`. To restore access, remove the statement.

To stop every session of a role at once, revoke them on the IAM role. In the IAM console, choose **Revoke active sessions** on the role. IAM adds a policy that denies sessions issued before that time, using `aws:TokenIssueTime`. This affects every workload that uses the role. For more information, see Revoke IAM role temporary security credentials.