Tutorials
How to Restrict S3 Access to Individual AI Agents with AWS IAM Workload Identity
AWS IAM now supports verifiable identities for individual AI agents. Learn how to restrict S3 access when agents share an execution role, prevent requests without identity context, and verify access through CloudTrail.
Suppose you have two AI agents running on Amazon Bedrock AgentCore. One generates reports, while the other handles customer support.
Both use the same IAM execution role. That role provides the permissions necessary for their common operations, but the reporting agent also needs to read documents from Amazon S3.
How do you grant that permission without allowing the support agent to read the same documents?
Creating another IAM role is an obvious solution. However, as the number of agents grows, maintaining separate roles for workloads with nearly identical permissions can become cumbersome.
On December 1, 2026, AWS announced Agent and Workload Identity for IAM, currently available in preview.
The new mechanism allows individual workloads to carry their own verifiable identities within IAM role sessions. Resource owners can use those identities in access policies without necessarily assigning a different execution role to every agent.
How IAM identifies individual agents
An IAM execution role defines which AWS operations a workload is permitted to perform.
Previously, two agents using the same execution role were difficult to distinguish through role-based resource policies alone.
Workload identity introduces additional information into the role session.
AWS IAM policies can now inspect two condition keys:
| Condition key | Purpose |
|---|---|
aws:OriginIdentity/Subject |
Identifies the originating workload |
aws:OriginIdentity/Issuer |
Identifies the provider that issued its identity |
The subject can be represented by a SPIFFE identifier.
SPIFFE, or Secure Production Identity Framework for Everyone, provides a standard for identifying software workloads.
For example, our reporting agent might receive an identifier resembling:
spiffe://111122223333.aws.internal/us-east-1/bedrock-agentcore/runtime/reportAgent/reportAgent-a1b2c3d4
The support agent receives a different identifier, despite using the same execution role.
An S3 bucket policy can evaluate this additional context when deciding whether to permit a request.
flowchart TD
A["reportAgent"] --> C["Shared IAM execution role"]
B["supportAgent"] --> C
C --> D["S3 bucket policy"]
D --> E{"Valid reporting agent identity?"}
E -->|Yes| F["Allow GetObject"]
E -->|No or missing identity| G["Access denied"]
The identity does not replace the role. It gives the authorization system more information about the workload making the request.
1. Prepare the AWS environment
For this tutorial, assume the following resources belong to the same AWS account:
| Resource | Example |
|---|---|
| AWS account | 111122223333 |
| Region | us-east-1 |
| Execution role | AgentCoreExecutionRole |
| Reporting agent | reportAgent |
| Support agent | supportAgent |
| S3 bucket | example-reports |
| Test object | report.json |
Replace these demonstration values with your own resources.
The AgentCore integration has several requirements during the preview:
- AgentCore Runtime must use platform version V2 or the Instances compute type.
- The AWS CLI or SDK must have been released on or after December 1, 2026.
- The agent must use an AgentCore SDK version supporting workload identity credentials.
- The selected AWS Region must support the required AgentCore Runtime configuration.
There is also a limitation for existing deployments.
During the preview, workload identity cannot be enabled on an already-created runtime. You need to configure it when creating a new runtime.
For an existing production agent, this may require creating a replacement runtime and migrating traffic deliberately.
2. Configure a workload identity provider
Open the AWS Management Console and navigate to IAM’s Agent and Workload Identity section.
A workload identity provider establishes the trust domain used when issuing workload identities.
For a single AWS account, an account-level provider is sufficient.
The default provider created through AgentCore uses the SPIFFE scheme and an account-specific trust domain:
111122223333.aws.internal
Its ARN follows this format:
arn:aws:iam::111122223333:workload-identity-provider/default
Next, create a workload identity template based on the AgentCore Runtime definition.
The template determines how AWS constructs identifiers from runtime attributes, such as the runtime name and ID.
You can also configure identities at the session level. However, for this example, runtime-level identification is enough. We want to distinguish the reporting agent from the support agent, not individual conversations handled by either one.
The AgentCore console can create the default provider and template automatically, so manual IAM configuration is not necessary for every deployment.
3. Enable IAM workload identity in AgentCore Runtime
When creating a runtime in the AgentCore console, locate the IAM for agents section.
Enable the feature and choose either:
- Auto create a new setup.
- Select an existing setup.
The second option allows you to reuse the provider and template created in the previous step.
Create both runtimes using the same execution role and the appropriate workload identity template.
Their identities will differ because their runtime names and IDs differ.
The administrator creating the runtime also needs the iam:PassWorkloadIdentityTemplate permission for the selected template, with iam:PassedToService restricted to bedrock-agentcore.amazonaws.com.
The execution role’s existing trust policy does not need to be rewritten solely to enable workload identity.
Once the runtime is invoked, AgentCore participates in an attestation process with AWS STS. The resulting signed context allows the AgentCore SDK to obtain temporary role credentials carrying the agent’s identity.
This distinction becomes relevant when we write the bucket policy.
4. Restrict access using an S3 bucket policy
Consider the following condition:
{
"StringLike": {
"aws:OriginIdentity/Subject": "spiffe://111122223333.aws.internal/us-east-1/bedrock-agentcore/runtime/reportAgent/reportAgent-*"
},
"StringEquals": {
"aws:OriginIdentity/Issuer": "arn:aws:iam::111122223333:workload-identity-provider/default"
}
}
The subject pattern matches runtimes named reportAgent.
The issuer condition ensures the identity comes from the expected workload identity provider.
Why check both?
An identifier is unique within its provider. Checking only the subject would omit part of the trust relationship.
However, putting this condition inside an Allow statement is insufficient if the shared IAM role already grants unrestricted access to the bucket.
AWS IAM evaluates permissions from multiple applicable policies. An existing role permission may still authorize a request that does not match the conditional Allow.
We therefore need explicit Deny statements.
Open the S3 bucket’s permissions and configure a policy based on the following example:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowReportingAgent",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111122223333:role/AgentCoreExecutionRole"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-reports/*",
"Condition": {
"StringLike": {
"aws:OriginIdentity/Subject": "spiffe://111122223333.aws.internal/us-east-1/bedrock-agentcore/runtime/reportAgent/reportAgent-*"
},
"StringEquals": {
"aws:OriginIdentity/Issuer": "arn:aws:iam::111122223333:workload-identity-provider/default"
}
}
},
{
"Sid": "DenyOtherAgentSubjects",
"Effect": "Deny",
"Principal": {
"AWS": "arn:aws:iam::111122223333:role/AgentCoreExecutionRole"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-reports/*",
"Condition": {
"StringNotLike": {
"aws:OriginIdentity/Subject": "spiffe://111122223333.aws.internal/us-east-1/bedrock-agentcore/runtime/reportAgent/reportAgent-*"
}
}
},
{
"Sid": "DenyOtherIdentityProviders",
"Effect": "Deny",
"Principal": {
"AWS": "arn:aws:iam::111122223333:role/AgentCoreExecutionRole"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-reports/*",
"Condition": {
"StringNotEquals": {
"aws:OriginIdentity/Issuer": "arn:aws:iam::111122223333:workload-identity-provider/default"
}
}
}
]
}
This example adapts AWS’s documented bucket policy to our reporting-agent scenario.
Notice that the two Deny conditions are separate statements.
If both negative conditions were combined into one statement, IAM would require both to match before denying the request. An agent from the correct provider but with the wrong subject could escape that particular denial.
With separate statements, either mismatch is sufficient.
The intended behavior is:
| Request identity | Expected result |
|---|---|
reportAgent, correct provider |
Allowed |
supportAgent, correct provider |
Denied |
| Correct subject, different provider | Denied |
| Shared role without workload identity | Denied |
These outcomes assume no additional policy restrictions prevent the reporting agent from accessing the object.
The policy covers s3:GetObject requests made through the specified role. It does not restrict every other IAM principal or S3 operation.
If the role also has write, deletion, bucket-listing, or object-version permissions, review those separately.
5. Why the wildcard deserves attention
The policy uses the following pattern:
reportAgent/reportAgent-*
An AgentCore runtime ID contains its name followed by a generated suffix.
This pattern therefore permits runtimes recreated under the same name.
That can be convenient during deployment. A replacement reporting agent does not require a bucket policy update merely because its generated runtime ID changes.
But perhaps that is not what you want.
If access should belong to one particular runtime, replace the wildcard pattern with its complete identifier and use StringEquals. The corresponding negative condition should then use StringNotEquals.
A recreated runtime will need explicit authorization.
The choice depends on whether the security boundary represents a named application or one particular runtime resource.
In either case, permissions to create runtimes and assign identity templates also need to be restricted.
6. Verify access using TypeScript
Install the AWS SDK for JavaScript:
pnpm add @aws-sdk/client-s3 @aws-sdk/credential-providers
Use package releases published on or after December 1, 2026.
Create a small test script:
import {
S3Client,
GetObjectCommand,
} from "@aws-sdk/client-s3";
import {
fromContainerMetadata,
} from "@aws-sdk/credential-providers";
const s3 = new S3Client({
region: "us-east-1",
credentials: fromContainerMetadata(),
});
async function testAccess() {
try {
const result = await s3.send(
new GetObjectCommand({
Bucket: "example-reports",
Key: "report.json",
}),
);
console.log("Access granted");
console.log("Object size:", result.ContentLength);
} catch (error) {
if (error instanceof Error) {
console.error("S3 request failed:", error.name);
console.error(error.message);
}
process.exitCode = 1;
}
}
await testAccess();
The explicit container credential provider is used here to avoid accidentally selecting unrelated local AWS credentials.
But there is an important prerequisite.
This script does not create workload identity credentials by itself.
The AgentCore SDK must already have initialized the runtime’s identity-aware credential endpoint. AWS documents that subprocesses can obtain these credentials through the endpoint exposed in AWS_CONTAINER_CREDENTIALS_FULL_URI.
One possible arrangement is an AgentCore application using the supported Python SDK, with a Node.js subprocess executing the TypeScript-based S3 operation.
Running this script directly on your development computer will not reproduce that environment.
AWS also provides a native Python AgentCore example, which is the more directly documented approach for initializing workload identity credentials.
With the correct runtime setup, execute the same S3 operation from both agents.
The reporting agent should receive the object’s metadata. The support agent should receive an AccessDenied response.
The expected HTTP status for the denied S3 operation is 403.
Do not print the actual report contents when testing access controls. A successful response and its content length are sufficient to establish that the object was accessible.
7. Check the agent’s identity in CloudTrail
A successful S3 request does not, by itself, prove that workload identity was involved.
The request might have used another credential source.
To verify the identity, inspect the AWS CloudTrail records associated with the role session.
AWS documents that the originating identity appears in:
userIdentity.onBehalfOf
on the AssumeRole event that establishes the identity-bearing session.
This lets you associate the role session with the workload responsible for its activity.
If you also want to inspect individual S3 GetObject operations, enable CloudTrail data events for the bucket.
Object-level operations are data events, not ordinary management events. They are not displayed in the default CloudTrail Event history.
Enabling data event logging may incur additional charges, so limit the event selectors to the resources you need to monitor.
8. The preview limitation that affects security
During the preview, AgentCore Runtime also has access to execution role credentials that do not contain workload identity information.
That means an agent can make requests which carry its IAM role but lack the additional subject and issuer.
Consider a policy that explicitly denies only supportAgent.
What happens when the same workload makes a request without an identity?
The subject-specific denial may not match at all.
If the role independently permits S3 access, the request could succeed.
This is why our earlier policy takes the opposite approach.
It explicitly denies access whenever the expected reporting identity or provider is missing or incorrect.
The permission is therefore dependent on the presence of the expected identity, rather than merely the absence of a known unwanted identity.
There is also a broader architectural limitation. Workload identity distinguishes the origin of a request; it does not establish that the agent’s reasoning, tool selection, or handling of data is trustworthy.
A permitted reporting agent can still misuse its legitimate access. Application-level authorization, tool restrictions, and least-privilege policies remain necessary.
Does workload identity replace separate IAM roles?
Not in every situation.
Separate roles remain useful when workloads require substantially different baseline permissions or need stronger isolation from one another.
Workload identity is particularly interesting when several agents share common infrastructure permissions but need different access to specific resources.
Instead of creating another role solely to distinguish two otherwise similar agents, a resource policy can evaluate their verified identities.
The December 1 announcement introduces that additional authorization dimension to AWS IAM.
For our example, both agents retain the same execution role. The reporting agent can read its S3 documents, while the support agent cannot perform the same operation through that role.
The distinction is enforced by AWS rather than by a prompt instructing the support agent not to access reports.
And that is what makes this mechanism useful: the access boundary exists independently of the model’s decisions.
External Sources used for this article
- AWS News Blog — AWS Builds for More Ambitious Agents, December 1, 2026
- Amazon Bedrock AgentCore — Agent and Workload Identity for Runtime
- AWS IAM — Condition Keys for Agent and Workload Identity
- AWS IAM — Create a Workload Identity Provider
- AWS SDK for JavaScript — Credential Providers
- AWS — Container Credential Provider
- Amazon S3 — Enabling CloudTrail Event Logging