

# Agent and workload identity for AgentCore Runtime (preview)

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

By default, every agent that uses the same execution role looks the same to AWS services, so a resource policy can only allow or deny the role. With agent and workload identity, a feature of IAM for agents, you can give your agent runtime an identity by choosing a workload identity template when you create it. The agent’s AWS calls then carry that identity, so resource owners can allow or deny one agent, and AWS CloudTrail records the agent’s identity in `userIdentity.onBehalfOf` on the `AssumeRole` event that starts its role session, so you can trace that session’s calls to the agent.

To use agent and workload identity, set `workloadIdentityTemplateArn` to the ARN of a workload identity template when you call `CreateAgentRuntime`. You need the `iam:PassWorkloadIdentityTemplate` permission to pass the template (see [Permissions](#runtime-agent-workload-identity-permissions)), and the template must be in your own account or owned by your organization. You don’t need to update your existing execution role.

The following sections show you how to choose a workload identity provider, create a template, write your agent code, create the agent runtime, and control access to your resources with the agent’s identity.

**Topics**
+ [How it works](#runtime-agent-workload-identity-how-it-works)
+ [Before you begin](#runtime-agent-workload-identity-prerequisites)
+ [Choose a workload identity provider](#runtime-agent-workload-identity-provider)
+ [Create a workload identity template](#runtime-agent-workload-identity-template-definitions)
+ [Write your agent code](#runtime-agent-workload-identity-agent-code)
+ [Create an agent runtime that uses the template](#runtime-agent-workload-identity-turn-on)
+ [Find the agent’s identity in CloudTrail](#runtime-agent-workload-identity-cloudtrail)
+ [Control access to a resource with the agent’s identity](#runtime-agent-workload-identity-resource-policy)
+ [Preview limitations](#runtime-agent-workload-identity-limitations)

## How it works
<a name="runtime-agent-workload-identity-how-it-works"></a>

This page uses *agent runtime* (or *runtime*) for the AgentCore Runtime resource that you create, and *agent* for your code, which the runtime runs in each session.

When a caller invokes an agent runtime that uses a workload identity template, AgentCore attests the runtime to [AWS Security Token Service (AWS STS)](https://docs.aws.amazon.com/STS/latest/APIReference/welcome.html), gets a signed context that carries the agent’s identity, and passes the context to the agent. The context is scoped to work only with the agent’s execution role. In your agent’s code, the AgentCore SDK calls AgentCore Identity with that context and gets execution role credentials that carry the identity. The SDK also refreshes the credentials automatically while the agent runs. Your agent then calls AWS services with these credentials, as it does with any AWS SDK client, and resource policies can allow or deny the call based on the agent’s identity with the `aws:OriginIdentity/Subject` and `aws:OriginIdentity/Issuer` condition keys. For more information, see [How the runtime gets its identity](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-agentcore.html#wi-ac-runtime-gets-identity) in the *IAM User Guide*.

### How it relates to AgentCore Identity
<a name="runtime-agent-workload-identity-agentcore-identity"></a>

Agent and workload identity is an IAM concept. In contrast, AgentCore Identity has its own workload identities, which serve a different purpose. The following table compares the two.


|  | AgentCore Identity | IAM for agents | 
| --- | --- | --- | 
| Purpose | Access services outside AWS, such as OAuth2 tokens and API keys | Identify the agent on its calls to AWS services | 
| Created by | AgentCore Runtime, automatically, for runtimes without a template | IAM, from the template that you set on the runtime | 
| Used in | AgentCore Identity: workload access tokens and credential providers | IAM policies (`aws:OriginIdentity/Subject` and `aws:OriginIdentity/Issuer`) and CloudTrail | 
| Learn more |  [Understanding workload identities](understanding-agent-identities.md)  |  [Amazon Bedrock AgentCore](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-agentcore.html) in the *IAM User Guide*  | 

Using agent and workload identity doesn’t take away anything that AgentCore Identity gives your agent. AgentCore Runtime doesn’t create an AgentCore Identity workload identity for a runtime that uses a template, so `GetAgentRuntime` doesn’t return `workloadIdentityDetails` for it. Your agent can still get workload access tokens (see [Get workload access token](get-workload-access-token.md)) and use them with AgentCore Identity as it does without a template, to get [OAuth 2.0 access tokens](identity-authentication.md) with the client credentials or authorization code flow, to exchange tokens with [on-behalf-of token exchange](on-behalf-of-token-exchange.md), and to get [API keys](obtain-api-key.md).

Those calls must carry the agent’s identity, so make them with the latest version of the AgentCore SDK. Calls made with the execution role’s credentials alone fail with an `AccessDeniedException` (HTTP 403).

## Before you begin
<a name="runtime-agent-workload-identity-prerequisites"></a>
+ Use the latest version of the AWS CLI or an AWS SDK, released on or after December 1, 2026.
+ In your agent code, use the latest version of the AgentCore SDK, so that your agent gets execution role credentials that carry its identity.
+ Your agent runtime must use [platform version V2](runtime-how-it-works.md#runtime-enable-v2) or the [Instances](runtime-instances.md) compute type, in an AWS Region where either is available.
+ Make sure that each person or role in the following table has the permissions that it needs.

### Permissions
<a name="runtime-agent-workload-identity-permissions"></a>

The following tables list every permission that you need to use agent and workload identity with AgentCore Runtime. There’s one table for each provider type: choose **Account-level provider** or **Organization-level provider**. To decide which provider type fits your setup, see [Choose a workload identity provider](#runtime-agent-workload-identity-provider).

**Example**  


| Who | Permissions | Needed in | Reference | 
| --- | --- | --- | --- | 
| The IAM user or role that creates a provider |  `iam:CreateWorkloadIdentityProvider`  |  [Choose a workload identity provider](#runtime-agent-workload-identity-provider)  |  [Example policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_agent-workload-manage.html) and [Create an account-level provider](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-create-provider.html#wi-cp-account)  | 
| The IAM user or role that creates a template |  `iam:CreateWorkloadIdentityTemplate` and `iam:PutWorkloadIdentityTemplateAttestationPolicy`  |  [Create a workload identity template](#runtime-agent-workload-identity-template-definitions)  |  [Example policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_agent-workload-manage.html) and [Create a template from a definition](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-templates.html#wi-tpl-from-definition)  | 
| The IAM user or role that creates or updates the agent runtime |  `iam:PassWorkloadIdentityTemplate` on the template, with `iam:PassedToService` set to `bedrock-agentcore.amazonaws.com`  |  [Create an agent runtime that uses the template](#runtime-agent-workload-identity-turn-on)  |  [Permission to assign a template](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-attestation-policies.html#wi-ap-pass)  | 
| AgentCore console users | To find providers and templates: `iam:ListWorkloadIdentityProviders`, `iam:GetWorkloadIdentityProvider`, `iam:ListWorkloadIdentityTemplates`, `iam:GetWorkloadIdentityTemplate`, and `iam:GetWorkloadIdentityTemplateAttestationPolicy`. For **Auto create a new setup**, also `iam:CreateWorkloadIdentityProvider`, `iam:CreateWorkloadIdentityTemplate`, and `iam:PutWorkloadIdentityTemplateAttestationPolicy`. |  [Create an agent runtime that uses the template](#runtime-agent-workload-identity-turn-on) (console) |  [Example policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_agent-workload-enable-console.html)  | 
| The agent’s execution role | None. You don’t need to update your existing execution role. | – | – | 


| Who | Permissions | Needed in | Reference | 
| --- | --- | --- | --- | 
| The IAM user or role that creates the provider, in the management account or a delegated administrator account |  `iam:CreateWorkloadIdentityProvider`, and `iam:PutWorkloadIdentityProviderResourcePolicy` so that member accounts can add templates |  [Choose a workload identity provider](#runtime-agent-workload-identity-provider)  |  [Create an organization-level provider](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-create-provider.html#wi-cp-org)  | 
| The IAM user or role that creates a template in a member account |  `iam:CreateWorkloadIdentityTemplate`, `iam:PutWorkloadIdentityTemplateAttestationPolicy`, and `iam:AssociateWorkloadIdentityTemplate` for your account’s path prefix. The provider’s resource policy must allow this action for your account. |  [Create a workload identity template](#runtime-agent-workload-identity-template-definitions)  |  [Example policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_agent-workload-member-templates.html) and [Create a template from a member account](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-templates.html#wi-tpl-member-account)  | 
| The IAM user or role that creates or updates the agent runtime |  `iam:PassWorkloadIdentityTemplate` on the template, with `iam:PassedToService` set to `bedrock-agentcore.amazonaws.com`  |  [Create an agent runtime that uses the template](#runtime-agent-workload-identity-turn-on)  |  [Permission to assign a template](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-attestation-policies.html#wi-ap-pass)  | 
| AgentCore console users | To find providers and templates: `iam:ListWorkloadIdentityProviders`, `iam:GetWorkloadIdentityProvider`, `iam:ListWorkloadIdentityTemplates`, `iam:GetWorkloadIdentityTemplate`, and `iam:GetWorkloadIdentityTemplateAttestationPolicy`. **Auto create a new setup** uses the organization’s template and creates nothing. |  [Create an agent runtime that uses the template](#runtime-agent-workload-identity-turn-on) (console) |  [Example policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_agent-workload-enable-console.html)  | 
| The agent’s execution role | None. You don’t need to update your existing execution role. | – | – | 

For example, the following policy lets the IAM user or role pass any template in your account (`111122223333`) or organization (`o-a1b2c3d4e5`) to AgentCore:

```json
{
"Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "PassWorkloadIdentityTemplate",
      "Effect": "Allow",
      "Action": "iam:PassWorkloadIdentityTemplate",
      "Resource": [
        "arn:aws:iam::111122223333:workload-identity-template/*",
        "arn:aws:iam::o-a1b2c3d4e5:workload-identity-template/*"
      ],
      "Condition": {
        "StringEquals": {
          "iam:PassedToService": "bedrock-agentcore.amazonaws.com"
        }
      }
    }
  ]
}
```

## Choose a workload identity provider
<a name="runtime-agent-workload-identity-provider"></a>

A workload identity provider in IAM issues identities to your agents. It sets the trust domain at the start of every identifier, and each template that you create must belong to a provider. Choose one of the following provider types.

 **Account-level provider**   
A provider for one account. Use it when you work in one account, or when each account manages its own agent identities. If you use **Auto create a new setup** in the AgentCore console, the console creates an account-level provider named `default`, with the SPIFFE scheme and the trust domain `<account-id>.aws.internal`, if one doesn’t exist. For example, its identifiers start with `spiffe://111122223333.aws.internal`.

 **Organization-level provider**   
If you use AWS Organizations, you can create one provider for the whole organization. Use it when you want one trust domain across your accounts, so that one policy can cover an agent in every account. You create it from the management account or a delegated administrator account. Agents in every member account then get identifiers under your organization’s trust domain, such as `spiffe://corp.example.com/111122223333/…​`, with the account ID in the identifier by default, so a resource owner can write one policy that covers an agent in all of your accounts. For an example, see [Control access to a resource with the agent’s identity](#runtime-agent-workload-identity-resource-policy).

For how to create either kind of provider, see [Create a workload identity provider](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-create-provider.html) in the *IAM User Guide*.

## Create a workload identity template
<a name="runtime-agent-workload-identity-template-definitions"></a>

A workload identity template defines the pattern that the agent’s identifier is built from. You can create a template from an AgentCore Runtime template definition, which we recommend, or with your own path pattern and attestation policy. The following table shows which options fit your setup.


| Provider | Template owned by | Use when | Instructions | 
| --- | --- | --- | --- | 
| Account-level | Your account | You work in one account, or each account manages its own identities. This is the simplest setup, and the console’s **Auto create a new setup** creates it for you. |  [Create a template from a definition](#runtime-agent-workload-identity-from-definition) (recommended) or [Create a template with your own path pattern](#runtime-agent-workload-identity-custom-template)  | 
| Organization-level | Your account | You want one trust domain across the organization, so that one policy can cover an agent in every account, and each account still creates its own templates. |  [Create a template from a definition](#runtime-agent-workload-identity-from-definition) (recommended) or [Create a template with your own path pattern](#runtime-agent-workload-identity-custom-template)  | 
| Organization-level | The organization | A central team controls how every account’s agent identifiers are formed, and member accounts don’t create templates. |  [Create a template with your own path pattern](#runtime-agent-workload-identity-custom-template) (no definition) | 

**Tip**  
We recommend the following when you choose an identifier format:  
Use a template that gives each runtime one identity. If your resources need to tell sessions apart, use a template that includes the session ID, such as a `*-session` definition.
Keep in mind that a per-session identifier is longer, and that the session ID counts toward the 256-character limit.
Don’t use a per-session identity as a security boundary between callers, because callers choose the session ID.

### Create a template from a definition
<a name="runtime-agent-workload-identity-from-definition"></a>

A definition sets the identifier format and writes the attestation policy for you. Choose the tab for your provider type, and then choose a definition for one identity for each runtime or for each session.

Every definition ARN starts with `arn:aws:iam::aws:workload-identity-template-definition/bedrock-agentcore.amazonaws.com/`.

**Example**  


| Identity | Definition | Example identifier | 
| --- | --- | --- | 
| One identity for each runtime |  `runtime/account-provider-default:1`  |  `spiffe://111122223333.aws.internal/us-east-1/bedrock-agentcore/runtime/agentA/agentA-a1b2c3d4e5`  | 
| One identity for each session |  `runtime/account-provider-session:1`  |  `spiffe://111122223333.aws.internal/us-east-1/bedrock-agentcore/runtime/agentA/agentA-a1b2c3d4e5/<session-id>`  | 
The following AWS CLI command creates a template from the account-level definition:  

```bash
aws iam create-workload-identity-template \
  --template-definition '{
    "TemplateDefinitionArn": "arn:aws:iam::aws:workload-identity-template-definition/bedrock-agentcore.amazonaws.com/runtime/account-provider-default:1",
    "ReplacementValues": {
      "Name": { "Values": ["agentcore-runtimes"] },
      "WorkloadIdentityProviderArn": { "Values": ["arn:aws:iam::111122223333:workload-identity-provider/default"] }
    }
  }'
```


| Identity | Definition | Example identifier | 
| --- | --- | --- | 
| One identity for each runtime |  `runtime/org-provider-account-template-default:1`  |  `spiffe://corp.example.com/111122223333/us-east-1/bedrock-agentcore/runtime/agentA/agentA-a1b2c3d4e5`  | 
| One identity for each session |  `runtime/org-provider-account-template-session:1`  |  `spiffe://corp.example.com/111122223333/us-east-1/bedrock-agentcore/runtime/agentA/agentA-a1b2c3d4e5/<session-id>`  | 
For an `org-provider-account-template-*` definition, use your organization’s provider ARN and set `PathPrefix`, usually to your account ID. For which definitions need `PathPrefix` and which values you can use, see [Template definitions](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-templates.html#wi-tpl-definitions) in the *IAM User Guide*. The following command creates a template from an organization-level definition:  

```bash
aws iam create-workload-identity-template \
  --template-definition '{
    "TemplateDefinitionArn": "arn:aws:iam::aws:workload-identity-template-definition/bedrock-agentcore.amazonaws.com/runtime/org-provider-account-template-default:1",
    "ReplacementValues": {
      "Name": { "Values": ["agentcore-runtimes"] },
      "WorkloadIdentityProviderArn": { "Values": ["arn:aws:iam::o-a1b2c3d4e5:workload-identity-provider/corp-example"] },
      "PathPrefix": { "Values": ["111122223333"] }
    }
  }'
```

For the permissions that you need, see [Permissions](#runtime-agent-workload-identity-permissions).

### Create a template with your own path pattern
<a name="runtime-agent-workload-identity-custom-template"></a>

To build the identifier yourself, create a template with a custom path pattern and attestation policy. For a template that your organization owns, start the pattern with the account ID, as the IAM console does, so that identifiers stay unique across accounts. Its ARN has the organization ID in place of the account ID, for example `arn:aws:iam::o-a1b2c3d4e5:workload-identity-template/my-template`. For the rules and steps, see [Create a template with a custom path pattern](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-templates.html#wi-tpl-custom) in the *IAM User Guide*.

#### Path pattern
<a name="runtime-agent-workload-identity-path-pattern"></a>

AgentCore Runtime reports the following facts about the agent runtime on each invocation. A path pattern can use them, and the global keys `aws:SourceAccount` and `aws:RequestedRegion`. In a path pattern, write the full key in braces, for example `{aws:WorkloadAttestation/aws/bedrock-agentcore/RuntimeId}`.


| Attestation key (`aws:WorkloadAttestation/…​`) | Value | 
| --- | --- | 
|  `aws/bedrock-agentcore/RuntimeName`  | The runtime name, for example `agentA`  | 
|  `aws/bedrock-agentcore/RuntimeId`  | The runtime ID: the runtime name, a hyphen, and a random suffix, for example `agentA-a1b2c3d4e5`  | 
|  `aws/bedrock-agentcore/RuntimeVersion`  | The runtime version that the invoked endpoint points to, for example `3`  | 
|  `aws/bedrock-agentcore/RuntimeSessionId`  | The invocation’s runtime session ID: `runtimeSessionId`, sent in the `X-Amzn-Bedrock-AgentCore-Runtime-Session-Id` header. If the caller doesn’t set one, AgentCore generates it. For an MCP server, the MCP session ID (`Mcp-Session-Id`) when the client sends one. | 

For example, the account-level definition uses the following path pattern:

```
{aws:RequestedRegion}/bedrock-agentcore/runtime/{aws:WorkloadAttestation/aws/bedrock-agentcore/RuntimeName}/{aws:WorkloadAttestation/aws/bedrock-agentcore/RuntimeId}
```

In the AgentCore console, **Select an existing setup** lists a template only if its path contains `bedrock-agentcore/runtime/` or uses a Runtime attestation key.

#### Attestation policy
<a name="runtime-agent-workload-identity-attestation-policy"></a>

The attestation policy names AgentCore as the principal that can request the identity. The following policy is the one that the AgentCore Runtime definitions write. It lets AgentCore Runtime request identities for agent runtimes in account `111122223333`:

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

For the condition keys that an attestation policy can use, see [Condition keys you can use](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-attestation-policies.html#wi-ap-condition-keys) in the *IAM User Guide*.

## Write your agent code
<a name="runtime-agent-workload-identity-agent-code"></a>

The AgentCore SDK gets the agent’s identity credentials for you. Import `bedrock_agentcore` before you create any boto3 client. The SDK then puts the credentials on boto3’s default credential chain, so a plain client carries the agent’s identity. A client that you create before the import keeps the execution role’s credentials without the identity. The following Python agent reads an Amazon S3 object with that identity:

```python
from bedrock_agentcore import BedrockAgentCoreApp  # import before boto3
import boto3

app = BedrockAgentCoreApp()

@app.entrypoint
def handler(payload, context):
    s3 = boto3.client("s3")  # uses credentials that carry the agent's identity
    obj = s3.get_object(Bucket="amzn-s3-demo-bucket", Key="report.txt")
    return {"bytes": obj["ContentLength"]}

if __name__ == "__main__":
    app.run()
```

Package the agent as you normally do, as a container image in Amazon ECR or as a .zip file for direct code deployment. For steps, see [Get started without the AgentCore CLI](getting-started-custom.md) (container image) and [Get started with Amazon Bedrock AgentCore Runtime direct code deployment](runtime-get-started-code-deploy.md) (.zip file). Include the AgentCore SDK in the package.

Keep the following in mind:
+ Subprocesses, such as the AWS CLI, get the same credentials through the AWS container credentials endpoint that the SDK sets in `AWS_CONTAINER_CREDENTIALS_FULL_URI`.
+ The credential method that boto3 reports doesn’t show whether the identity is attached. To check, call a resource whose policy requires the identity, such as the one in [Control access to a resource with the agent’s identity](#runtime-agent-workload-identity-resource-policy).

## Create an agent runtime that uses the template
<a name="runtime-agent-workload-identity-turn-on"></a>

Create the agent runtime with your template in the AgentCore console or with the AWS CLI.

**Important**  
The IAM user or role that creates or updates the runtime needs permission to pass the template. Without it, `CreateAgentRuntime` and `UpdateAgentRuntime` fail with an `AccessDeniedException` (HTTP 403). For the policy, see [Permissions](#runtime-agent-workload-identity-permissions).

**Example**  

1. Open the Amazon Bedrock AgentCore console at https://console.aws.amazon.com/bedrock-agentcore/home?region=us-east-1\# and choose **Agents**.

1. On the **Agents** page, choose **Create Host agent (runtime)**.

1. Configure the runtime with platform version **V2** or the **Instances** compute type. For Instances, choose or create a [capacity provider](runtime-instances-how-it-works.md#runtime-instances-capacity-provider).

1. Under **IAM for agents**, select **Enable IAM for agents**.

1. For **Workload identity setup**, choose one of the following:
   +  **Auto create a new setup** – The console uses your account’s default provider and template in IAM, and creates them if they don’t exist. If your account can use your organization’s workload identity provider, the console doesn’t create a provider in your account. It uses the organization’s Runtime template, or your account’s existing default template if the organization has none. If neither exists, ask your organization’s identity administrator to add a Runtime template. If the organization has more than one Runtime template, choose one with **Select an existing setup**. (Optional) To give each session its own identity, select **Include session ID in the agent identity**.
   +  **Select an existing setup** – Choose a **Workload identity provider** and a **Template**. To create either one in the IAM console, choose **Create new**.

1. Complete the rest of the configuration, and then choose **Create runtime**.

   The console shows the agent’s identity format, for example `spiffe://111122223333.aws.internal/{Region}/bedrock-agentcore/runtime/{RuntimeName}/{RuntimeId}`. It isn’t the actual identifier: values that AgentCore sets when the agent runs, such as the session ID, appear as placeholders. To see the actual identifier after the first invocation, see [Find the agent’s identity in CloudTrail](#runtime-agent-workload-identity-cloudtrail).

   The console calls IAM with your credentials. For the permissions that you need, see [Permissions](#runtime-agent-workload-identity-permissions).
Set `--workload-identity-template-arn` on the `create-agent-runtime` command, along with your other runtime settings.  

```bash
aws bedrock-agentcore-control create-agent-runtime \
  --agent-runtime-name "agentA" \
  --role-arn "arn:aws:iam::111122223333:role/AgentExecutionRole" \
  --platform-version V2 \
  --workload-identity-template-arn "arn:aws:iam::111122223333:workload-identity-template/my-template" \
  ...
```
The response doesn’t include the agent’s identifier. To see it after the first invocation, see [Find the agent’s identity in CloudTrail](#runtime-agent-workload-identity-cloudtrail).  
For the Instances compute type, first create a [capacity provider](runtime-instances-how-it-works.md#runtime-instances-capacity-provider). Then replace `--platform-version V2` with `--capacity-provider-configuration` and your capacity provider’s ARN. For the setup and the full command, see [Get started with Instances using the AWS CLI or SDK](runtime-instances-get-started-cli.md).

After you create the runtime, invoke it as you do today. Callers don’t change anything; AgentCore attaches the agent’s identity on each invocation. For more information, see [Invoke an AgentCore Runtime agent](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-invoke-agent.html).

### Change the template
<a name="runtime-agent-workload-identity-change-template"></a>

After you create the runtime:
+ To switch to a different template, choose another template when you edit the runtime in the console, or call `UpdateAgentRuntime` with the new template ARN. If you leave `workloadIdentityTemplateArn` out, the runtime keeps its current template.
+ To add a template to a runtime that was created without one, or to remove a template, create a new runtime.

## Find the agent’s identity in CloudTrail
<a name="runtime-agent-workload-identity-cloudtrail"></a>

When the agent gets its identity credentials, AWS CloudTrail records an `AssumeRole` event for the execution role in your account. The event’s `userIdentity.onBehalfOf` field holds the agent’s identity: `subject` (its identifier), `subjectType`, `issuer` (the provider ARN), and `workloadIdentityTemplateArn`. The following example shows the relevant fields of such an event:

```json
{
  "userIdentity": {
    "type": "AssumedRole",
    "onBehalfOf": {
      "subject": "spiffe://111122223333.aws.internal/us-east-1/bedrock-agentcore/runtime/agentA/agentA-a1b2c3d4e5",
      "subjectType": "workload",
      "issuer": "arn:aws:iam::111122223333:workload-identity-provider/default",
      "workloadIdentityTemplateArn": "arn:aws:iam::111122223333:workload-identity-template/agentcore-runtimes"
    }
  },
  "eventSource": "sts.amazonaws.com",
  "eventName": "AssumeRole",
  "requestParameters": {
    "roleArn": "arn:aws:iam::111122223333:role/AgentCoreExecutionRole",
    "roleSessionName": "AgentCore-MicroVM-a1b2c3d4-DEFAULT",
    "durationSeconds": 3600,
    "providedContexts": [
      { "providerArn": "arn:aws:iam::111122223333:workload-identity-provider/default" }
    ]
  }
}
```

AgentCore also records a management event with the event source `bedrock-agentcore.amazonaws.com` when the agent gets the credentials. The event’s `resources` include the agent runtime’s ARN, and `additionalEventData.sourceArn` holds the runtime endpoint that was invoked. The credentials themselves are hidden in the event, and the identity context isn’t logged.

Events for the agent’s later calls to other AWS services show the execution role’s session, not the identity. To trace those calls back to the agent, see [Logging and monitoring agent and workload identity](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-logging-monitoring.html) in the *IAM User Guide*.

## Control access to a resource with the agent’s identity
<a name="runtime-agent-workload-identity-resource-policy"></a>

After your agent runtime has an identity, resource owners can write policies that allow or deny the agent by that identity, with the `aws:OriginIdentity/Subject` (the identifier) and `aws:OriginIdentity/Issuer` (the provider) condition keys. An identifier is unique only within its provider, so always match both. You can write a policy before the first invocation, because the template sets the identifier format. For example identifiers, see [Create a template from a definition](#runtime-agent-workload-identity-from-definition). To see an agent’s actual identifier, see [Find the agent’s identity in CloudTrail](#runtime-agent-workload-identity-cloudtrail).

The following Amazon S3 bucket policy lets only agents named `agentA` read objects in the bucket with the execution role. Replace `111122223333`, `AgentCoreExecutionRole`, and the provider ARN with your own values.

```json
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AllowAgentA",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:role/AgentCoreExecutionRole" },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
      "Condition": {
        "StringLike": { "aws:OriginIdentity/Subject": "spiffe://111122223333.aws.internal/us-east-1/bedrock-agentcore/runtime/agentA/agentA-*" },
        "StringEquals": { "aws:OriginIdentity/Issuer": "arn:aws:iam::111122223333:workload-identity-provider/default" }
      }
    },
    {
      "Sid": "DenyRoleWithoutAgentA",
      "Effect": "Deny",
      "Principal": { "AWS": "arn:aws:iam::111122223333:role/AgentCoreExecutionRole" },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
      "Condition": {
        "StringNotLike": { "aws:OriginIdentity/Subject": "spiffe://111122223333.aws.internal/us-east-1/bedrock-agentcore/runtime/agentA/agentA-*" }
      }
    },
    {
      "Sid": "DenyRoleWithOtherProvider",
      "Effect": "Deny",
      "Principal": { "AWS": "arn:aws:iam::111122223333:role/AgentCoreExecutionRole" },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
      "Condition": {
        "StringNotEquals": { "aws:OriginIdentity/Issuer": "arn:aws:iam::111122223333:workload-identity-provider/default" }
      }
    }
  ]
}
```

The policy has three statements:
+  `AllowAgentA` allows the execution role to read the bucket when the call carries the identity of an agent named `agentA` from your provider.
+  `DenyRoleWithoutAgentA` denies the execution role when the call carries any other identity, or no identity. This also blocks calls made with the role’s credentials without the identity, and calls from other agents that use the same role.
+  `DenyRoleWithOtherProvider` denies the execution role when the identity comes from a different provider.

You need the `Deny` statements because an `Allow` in the resource policy doesn’t limit a role whose own IAM policy already grants access.

The policy uses `agentA- ` to match every runtime named `agentA`, including runtimes that you re-create. With a per-session template, it also matches every session of those runtimes. A runtime ID is the runtime name, a hyphen, and a random suffix, and runtime names can’t contain hyphens, so `agentA-` matches only runtimes named `agentA`. To match one runtime only, use its full runtime ID with `StringEquals`. A re-created runtime then doesn’t inherit the old runtime’s access.

With an organization-level provider, one policy can cover an agent in every account of your organization. The account ID is part of the identifier, so use a wildcard for it. For example, the following condition matches every runtime named `agentA` in any account in the organization, in one AWS Region:

```json
"Condition": {
  "StringLike": {
    "aws:OriginIdentity/Subject": "spiffe://corp.example.com/*/us-east-1/bedrock-agentcore/runtime/agentA/*"
  },
  "StringEquals": {
    "aws:OriginIdentity/Issuer": "arn:aws:iam::o-a1b2c3d4e5:workload-identity-provider/corp-example"
  }
}
```

For a policy that allows an agent regardless of which role it uses, see [Example: allow one agent to read a bucket](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-agentcore.html#wi-ac-example-bucket) in the *IAM User Guide*.

### Stop an agent’s identity
<a name="runtime-agent-workload-identity-stop"></a>

To stop an agent’s identity, delete its template. This affects every agent runtime that uses the template: every invocation fails with an `AccessDeniedException` (HTTP 403), including invocations of existing sessions. Work that’s already running in a session can keep using the credentials that the agent already holds until they expire. To take access away right away, revoke the execution role’s active sessions. For more information, see [Stop issuing an identity and deny its access](https://docs.aws.amazon.com/IAM/latest/UserGuide/workload-identity-attestation-policies.html#wi-ap-revoke) in the *IAM User Guide*.

## Preview limitations
<a name="runtime-agent-workload-identity-limitations"></a>

Keep the following in mind when you use agent and workload identity with AgentCore Runtime during the preview:
+ During the preview, your agent also has the execution role’s credentials without its identity. Calls made with them, or made when the AgentCore SDK can’t get the identity credentials, go out without the identity, and a `Deny` that names the agent’s identity doesn’t stop them. To limit a resource to the agent’s identity, deny the role when the identity doesn’t match, as shown in [Control access to a resource with the agent’s identity](#runtime-agent-workload-identity-resource-policy).
+ With an older SDK, getting OAuth2 tokens, API keys, or payment tokens from AgentCore Identity fails with an `AccessDeniedException` (HTTP 403).
+ You can’t update a runtime that has a template to platform version V1.
+ If your template puts the runtime version in the identifier, a running session keeps the version identity that it started with. When the session’s compute is replaced, for example after the agent fails, the session gets the identity of the version that its endpoint points to at that time. So after you update the runtime or repoint an endpoint, the same session ID can get a different identity. To pin a session to one version’s identity, invoke an endpoint that points to that version.
+  `CreateAgentRuntime` and `UpdateAgentRuntime` don’t check that the template exists. If it doesn’t, invocations of the runtime fail with an `AccessDeniedException` (HTTP 403).
+ If AWS STS can’t issue the agent’s identity when the runtime is invoked, the invocation fails.
+  AWS STS limits the full identifier to 256 characters. This limit might change. Every part of the identifier counts: the trust domain (your provider’s or organization’s domain), account ID, Region, runtime name, runtime ID (which also contains the runtime name), and the session ID if your template includes it. For example, with a 48-character runtime name, about 70 characters are left for the session ID. If the identifier goes over the limit, the invocation fails with a `ValidationException` (HTTP 400). Use a shorter session ID or runtime name, or a template whose identifier doesn’t include the session ID.
+ After you create a template or change its attestation policy, invocations can fail with an `AccessDeniedException` (HTTP 403) for a few minutes while the change propagates.