[Update] I Tried Creating Credentials with Restricted Permissions and Duration Using AWS STS GetScopedCredentials
This page has been translated by machine translation. View original
Introduction
On November 19, 2026, a new API GetScopedCredentials was added to AWS STS.
It is an API that creates credentials with narrowed permissions and validity period from the temporary credentials you are currently using. Since it does not re-assume a role, you can reduce permissions while keeping the same identity.
The assumed use case seems to be "handing AI agents credentials that have only the permissions they need."
In this article, I will actually call GetScopedCredentials from the AWS CLI and check how the permissions and validity period are narrowed.
Features of GetScopedCredentials
Until now, you could also create temporary credentials with narrowed permissions by passing a session policy to AssumeRole. According to the documentation, GetScopedCredentials differs in the following points.
| Item | AssumeRole with session policy | GetScopedCredentials |
|---|---|---|
| Credentials that can be used to call | IAM users or temporary credentials | Temporary credentials only |
| Resulting identity | Session of the assumed role | Same session as the caller |
| When stacking policies | Replaces the previous session policy | Stacks on top of the previous scoping. Up to 3 layers |
| Maximum validity period | 1 hour with role chaining | Remaining time of the caller's session |
If you want to narrow the credentials of an IAM user, first obtain temporary credentials with GetSessionToken, and then make the call.
The caller needs permission for sts:GetScopedCredentials. Also, it cannot be used with the global endpoint sts.amazonaws.com; you need to use a regional endpoint.
When I tried specifying the global endpoint, the following error was returned.
aws sts get-scoped-credentials --duration-seconds 300 \
--endpoint-url https://sts.amazonaws.com --region us-east-1
aws: [ERROR]: An error occurred (InvalidAction) when calling the GetScopedCredentials operation: Operation not supported on STS global endpoint
Narrowing down to read-only access to a specific bucket
First, from a session of a role with administrator permissions, let's create credentials that can only read the S3 bucket devio-gsc-e6fe0a41-a.
For verification, I prepared two buckets, devio-gsc-e6fe0a41-a and devio-gsc-e6fe0a41-b, and placed hello.txt in each.
The policy used for narrowing is as follows.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:ListBucket", "s3:GetObject"],
"Resource": [
"arn:aws:s3:::devio-gsc-e6fe0a41-a",
"arn:aws:s3:::devio-gsc-e6fe0a41-a/*"
]
}
]
}
Pass this file to --policy and call the API. You can write a description of the purpose in --scoped-session-description.
aws sts get-scoped-credentials \
--policy file://read-bucket-a.json \
--scoped-session-description "read-only-bucket-a"
{
"Credentials": {
"AccessKeyId": "ASIA...",
"SecretAccessKey": "...",
"SessionToken": "IQoJb3JpZ2lu...",
"Expiration": "2026-11-20T10:54:41+00:00"
},
"SessionInfo": {
"ScopedSessionId": "AROAEXAMPLEID:my-session",
"Arn": "arn:aws:sts::123456789012:assumed-role/MyRole/my-session"
},
"SessionTokenUtilization": 18,
"SessionTokenSize": 752,
"ScopedPoliciesCount": 1
}
SessionInfo.Arn was the same as the ARN of the caller's session. Even when I put the returned credentials into environment variables and ran aws sts get-caller-identity, the same ARN as the caller was returned.
I tried several operations with these credentials.
| Operation | Result |
|---|---|
Listing devio-gsc-e6fe0a41-a |
Success |
Getting hello.txt in devio-gsc-e6fe0a41-a |
Success |
Listing devio-gsc-e6fe0a41-b |
AccessDenied |
Uploading to devio-gsc-e6fe0a41-a |
AccessDenied |
ec2:DescribeRegions |
UnauthorizedOperation |
As expected, only the operations allowed by the policy can be performed!
The error message when denied was as follows. Since it says because no session policy allows, the narrowing policy seems to be evaluated in the same way as a session policy.
aws: [ERROR]: An error occurred (AccessDenied) when calling the ListObjectsV2 operation: User: arn:aws:sts::123456789012:assumed-role/MyRole/my-session is not authorized to perform: s3:ListBucket on resource: "arn:aws:s3:::devio-gsc-e6fe0a41-b" because no session policy allows the s3:ListBucket action
Excluding only delete operations
Next, conversely, let's keep most permissions and remove only some operations. I wrote it using the combination of Allow and NotAction, which was also introduced in the documentation.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"NotAction": [
"s3:DeleteObject",
"s3:DeleteBucket",
"ec2:TerminateInstances",
"sts:AssumeRole*"
],
"Resource": "*"
}
]
}
With the credentials narrowed by this policy, the results were as follows.
| Operation | Result |
|---|---|
Uploading to devio-gsc-e6fe0a41-a |
Success |
Deleting an object in devio-gsc-e6fe0a41-a |
AccessDenied |
ec2:DescribeRegions |
Success |
You can upload, but you cannot delete the uploaded object. This looks useful for situations where you want to let an agent work but "don't want it to do anything destructive."
Shortening the validity period
By specifying --duration-seconds, you can shorten the validity period. Credentials created with 60 seconds could be used immediately after creation, but after 60 seconds they were rejected with ExpiredToken.
aws: [ERROR]: An error occurred (ExpiredToken) when calling the ListObjectsV2 operation: The provided token has expired.
You cannot specify a value longer than the remaining time of the caller's session. When I tried specifying the upper limit of 129600 seconds, InsufficientSessionLifetime was returned.
The error message also includes the remaining time of the caller's session.
aws: [ERROR]: An error occurred (InsufficientSessionLifetime) when calling the GetScopedCredentials operation: The requested DurationSeconds exceeds the remaining lifetime of the calling session. Remaining session lifetime is 3593 seconds.
When --duration-seconds was omitted, Expiration became the same time as the caller's session.
Stacking the narrowing
You can also call GetScopedCredentials again from credentials created with GetScopedCredentials. Since policies stack on top of the previous narrowing, permissions should not return even if you broaden the policy later.
I stacked the following 3 layers in order.
| Layer | Allowed operations |
|---|---|
| 1 | s3:* and sts:GetScopedCredentials |
| 2 | Read access to devio-gsc-e6fe0a41-a and sts:GetScopedCredentials |
| 3 | All operations |
The third layer allows all operations, but both listing devio-gsc-e6fe0a41-b and ec2:DescribeRegions were denied. The narrowing up to the second layer remains as is.
When I tried to pass a fourth-layer policy, I hit the limit.
aws: [ERROR]: An error occurred (ValidationError) when calling the GetScopedCredentials operation: Credentials have reached the maximum scope down limit and cannot be scoped down further.
Incidentally, the reason I included sts:GetScopedCredentials in the first and second layers in the above verification is that without it, you cannot create the next layer. When I called from credentials that allowed only s3:*, it was denied as follows.
aws: [ERROR]: An error occurred (AccessDenied) when calling the GetScopedCredentials operation: User: arn:aws:sts::123456789012:assumed-role/MyRole/my-session is not authorized to perform: sts:GetScopedCredentials on resource: arn:aws:sts::123456789012:self because no session policy allows the sts:GetScopedCredentials action
If you want the credentials handed to an agent to be able to create further narrowed credentials for a sub-agent, you need to include sts:GetScopedCredentials in the allowed actions. Conversely, if you don't want any further narrowing, it seems you can simply leave it out.
Conclusion
Using GetScopedCredentials, I was able to easily create credentials with only the permissions and validity period narrowed, while keeping the identity of the current session. It's convenient that you can reduce permissions before handing credentials to an agent without preparing a new role.
On the other hand, narrowing is limited to 3 layers, and to stack them you need to leave the sts:GetScopedCredentials permission in place. When designing the hierarchy of agents and sub-agents, it seems good to decide in advance what to narrow at which layer.