AWS STS GetScopedCredentials: Hand Each Tenant, Job or AI Agent Only the Permissions It Needs (2026)

AWS announced sts:GetScopedCredentials on 20 November 2026, an API that narrows the temporary credentials you already hold. How it behaves, a per-tenant S3 pattern in Python with input validation, and the limits to plan for.

On 20 November 2026 the AWS Security Blog announced GetScopedCredentials, a new AWS STS API that takes temporary credentials you already have and returns a new set with fewer permissions, a shorter lifetime, or both. For application developers it addresses a familiar problem: one IAM role serves many tenants, jobs or agents, so a bug or a hijacked prompt in any one of them inherits everything the role can do. This guide summarizes what AWS says the API does and shows one pattern for using it. Everything about the API comes from the AWS post; the code is our own illustration and has not been run.

What AWS says the API does

According to the announcement:

  • You call it with credentials you already use (the post names aws login, an EC2 instance profile and a Lambda function) and pass a scope down policy, a shorter session duration, or both.
  • The result is the intersection of the session’s effective permissions and the scope down policy, “so they can only be reduced”. The duration cannot exceed the remaining duration of the calling session.
  • The new credentials keep the caller’s IAM identity, including role session name, session tags and context keys.
  • You can call it again with the scoped credentials. At most three scope down policies can apply to a session, and each recursive call must be allowed by every earlier policy to call sts:GetScopedCredentials.
  • At launch it accepts one inline policy of up to 2,048 characters. The post lists a quota of 200 requests per second per account per Region and says some services are unsupported (see the API reference, which we did not open).
  • Each call is logged in CloudTrail, with the optional scoped-session-description recorded, and later calls made with the scoped keys can be traced to the parent session through the access key ID.

The post is explicit that the API narrows, never widens. A scope down policy with an Allow statement does not grant anything the session lacked.

Why this matters for application security

Two use cases in the post map directly onto common vulnerability classes.

Tenant isolation (broken access control, OWASP A01). The post describes a multi-tenant app with one role that can read every tenant’s S3 prefix. After authenticating a request, a trusted credential broker calls the API with a policy limited to that tenant’s prefix and gives only those credentials to the worker. In our illustration (the post does not discuss traversal or IDOR), if the worker has such a bug, S3 itself denies reads outside that prefix.

AI agents. The post argues that an agent chooses actions at runtime, often from prompts or tool output, so overly broad credentials let a mistaken agent act beyond its task. An orchestrator can scope down for each sub-agent. AWS also advises running agents in isolated or sandbox environments so they only reach the scoped keys.

A per-tenant broker in Python (illustrative, untested)

The AWS CLI form shown in the post is aws sts get-scoped-credentials --policy '<json>' --duration-seconds 300 --scoped-session-description report-status-job. We have not checked the boto3 method name; the snippet below assumes the SDK exposes it as get_scoped_credentials with matching parameters. Confirm against your SDK version before relying on it.

The key secure-coding point is ours, not AWS’s: the tenant ID ends up inside an IAM resource ARN, so validate it strictly. An ID containing * could widen the policy, and we assume (untested) that other unexpected characters could change what the ARN matches.

import json
import re
import boto3

# Allow-list: lowercase alphanumerics and hyphens only. No wildcards, slashes, dots.
TENANT_RE = re.compile(r"[a-z0-9][a-z0-9-]{2,62}")
BUCKET = "amzn-s3-demo-bucket"  # placeholder from the AWS post's examples

sts = boto3.client("sts")


def tenant_credentials(tenant_id: str, seconds: int = 300) -> dict:
    # fullmatch, not match: reject any trailing characters
    if not TENANT_RE.fullmatch(tenant_id):
        raise ValueError("invalid tenant id")

    policy = {
        "Version": "2012-10-17",
        "Statement": [{
            "Effect": "Allow",
            "Action": ["s3:GetObject", "s3:PutObject"],
            "Resource": f"arn:aws:s3:::{BUCKET}/tenants/{tenant_id}/*",
        }],
    }
    doc = json.dumps(policy, separators=(",", ":"))
    if len(doc) > 2048:  # launch limit stated in the AWS post
        raise ValueError("scope down policy too large")

    # ASSUMPTION: method and parameter names mirror the CLI; verify in your SDK.
    resp = sts.get_scoped_credentials(
        Policy=doc,
        DurationSeconds=seconds,
        ScopedSessionDescription=f"tenant:{tenant_id}",
    )
    return resp["Credentials"]  # hand ONLY this to the request worker

Build the policy as a dict and serialize it, rather than concatenating strings, so quoting tricks in input cannot change its structure. Do not log the returned SecretAccessKey or SessionToken.

Insecure pattern to replace

# VULNERABLE (illustrative): every request worker holds the full role.
s3 = boto3.client("s3")  # role can read all tenants
def get_report(tenant_id, name):
    return s3.get_object(Bucket=BUCKET, Key=f"tenants/{tenant_id}/{name}")
# A tenant_id taken from untrusted input, or a path-normalising layer in front of `name`,
# reads another tenant's objects because IAM allows it.

Scoped credentials do not replace input validation in this code. They are a second layer that limits the damage when validation fails.

Limits and cautions

  • The broker is now a high-value component: it holds the broader credentials and decides the scope. Keep it small, separate from request-handling code, and gate who can call sts:GetScopedCredentials. The post notes you can use the sts:DurationSeconds condition key and global keys such as aws:PrincipalArn and aws:SourceVpce.
  • The Allow with NotAction style shown in the post (keep everything except iam:*, sts:AssumeRole* and a few delete actions) is quicker but our inference is that allow-listing is safer, because new actions are included by default under NotAction.
  • The post says IAM Policy Autopilot can draft a scope down policy from SDK calls and that its output can contain wildcards you should replace. Treat generated policies as a starting point.

References