Agent and workload identity for AgentCore Runtime (preview)
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), 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
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), 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 in the IAM User Guide.
How it relates to AgentCore Identity
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 ( |
|
Learn more |
Amazon Bedrock AgentCore 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) and use them with AgentCore Identity as it does without a template, to get OAuth 2.0 access tokens with the client credentials or authorization code flow, to exchange tokens with on-behalf-of token exchange, and to get API keys.
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
-
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 or the Instances 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
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.
Example
For example, the following policy lets the IAM user or role pass any template in your account (111122223333) or organization (o-a1b2c3d4e5) to AgentCore:
{ "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 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 withspiffe://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.
For how to create either kind of provider, see Create a workload identity provider in the IAM User Guide.
Create a workload identity template
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 (recommended) or Create a template with your own path pattern |
|
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 (recommended) or Create a template with your own path pattern |
|
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 (no definition) |
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
*-sessiondefinition. -
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 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
For the permissions that you need, see Permissions.
Create a template with your own path pattern
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 in the IAM User Guide.
Path pattern
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 |
|---|---|
|
|
The runtime name, for example |
|
|
The runtime ID: the runtime name, a hyphen, and a random suffix, for example |
|
|
The runtime version that the invoked endpoint points to, for example |
|
|
The invocation’s runtime session ID: |
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
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:
{ "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 in the IAM User Guide.
Write your agent code
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:
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 (container image) and Get started with Amazon Bedrock AgentCore Runtime direct code deployment (.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.
Create an agent runtime that uses the template
Create the agent runtime with your template in the AgentCore console or with the AWS CLI.
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.
Example
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.
Change the template
After you create the runtime:
-
To switch to a different template, choose another template when you edit the runtime in the console, or call
UpdateAgentRuntimewith the new template ARN. If you leaveworkloadIdentityTemplateArnout, 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
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:
{ "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 in the IAM User Guide.
Control access to a resource with the agent’s identity
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. To see an agent’s actual identifier, see Find the agent’s identity in 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.
{ "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:
-
AllowAgentAallows the execution role to read the bucket when the call carries the identity of an agent namedagentAfrom your provider. -
DenyRoleWithoutAgentAdenies 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. -
DenyRoleWithOtherProviderdenies 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:
"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 in the IAM User Guide.
Stop an agent’s identity
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 in the IAM User Guide.
Preview limitations
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
Denythat 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. -
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.
-
CreateAgentRuntimeandUpdateAgentRuntimedon’t check that the template exists. If it doesn’t, invocations of the runtime fail with anAccessDeniedException(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.