Here’s the pattern AWS is pitching. An orchestrator agent runs under a role. When it hands a task to a sub-agent, it calls GetScopedCredentials with a policy that allows only that task, and gives the sub-agent the result. The sub-agent can read one S3 prefix, for fifteen minutes, and nothing else.
AWS announced the API on 19 November with agents, sub-agents and workloads as the headline use case, and it’s a real improvement. Before this, giving a sub-agent less than its parent meant another AssumeRole, with a session policy or a separate role per shape of task, and role chaining caps those sessions at one hour.
But there are two questions here, and the API answers only one. What may the sub-agent’s credential do? GetScopedCredentials answers that. What credentials can the sub-agent’s process find? Your launcher answers that, and the default answer is “the parent’s too”.
What the API actually does
The IAM documentation and the CLI reference are short and worth reading in full. The parts that matter for agent design:
- It only narrows. You call it with temporary credentials (an assumed role or a federated session; IAM user and root credentials are rejected). The result’s permissions are the intersection of your session’s effective permissions and the scope-down policy you pass. The lifetime can only get shorter, and session tags and source identity can’t be added or changed.
- The identity doesn’t change. Principal ARN, role session name, session tags and source identity all carry over. In CloudTrail, the sub-agent looks like the parent unless you look at the scoped session fields.
- Three layers, then no. You can call it again on its own output, and each call adds a layer that intersects with all the earlier ones. A session can carry three. The fourth is denied.
- Duration runs from 1 second to 36 hours, capped by whatever the caller has left. With no duration, the scoped credentials expire when the parent does. There’s no one-hour cap like role chaining has.
- The policy is small. 2,048 characters of plaintext JSON.
- Regional endpoints only. It isn’t available on the STS global endpoint.
Here’s what a call looks like for a sub-agent that should only read one incident’s artifacts:
cat > scope.json <<'EOF'
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::incident-artifacts/INC-4812/*"
}]
}
EOF
aws sts get-scoped-credentials \
--region us-east-1 \
--policy file://scope.json \
--duration-seconds 900 \
--scoped-session-description "triage-subagent INC-4812"
The response carries Credentials (the usual access key, secret, session token and expiration), a SessionInfo block with a ScopedSessionId, and a ScopedPoliciesCount telling you how many layers deep you are. The description you pass is written to CloudTrail. Use it, because it’s the easiest way to tell one sub-agent’s calls from another’s.
The test
What does a sub-agent actually see once you hand it those credentials? I wrote a small script to find out. It runs locally, makes no AWS calls, and every credential in it is a fake placeholder.
The parent holds its role session in three places a real host would: environment variables, the shared credentials file, and a container credentials variable (what ECS sets for a task role). It then launches the same sub-agent three ways, each time putting the scoped key in the child’s environment, and asks the child to list every AWS credential source it can see.
"""What can a sub-agent reach after you hand it scoped credentials?
Stdlib only, no network calls to AWS, every credential is a fake placeholder.
The parent holds its own role session in three places a real host would:
environment variables, a shared credentials file, and a container-credentials
endpoint variable (what ECS sets). It then launches the same sub-agent three
ways and asks the child to list every AWS credential source it can see.
"""
import os
import socket
import subprocess
import sys
import tempfile
from pathlib import Path
PROBE = r'''
import configparser, os, socket
from pathlib import Path
found = []
if os.environ.get("AWS_ACCESS_KEY_ID"):
found.append(("env vars", os.environ["AWS_ACCESS_KEY_ID"]))
creds = Path(os.environ.get("AWS_SHARED_CREDENTIALS_FILE",
Path.home() / ".aws" / "credentials"))
if creds.is_file():
cp = configparser.ConfigParser(); cp.read(creds)
for profile in cp.sections():
found.append((f"{creds.name} [{profile}]", cp[profile].get("aws_access_key_id")))
for var in ("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI", "AWS_CONTAINER_CREDENTIALS_FULL_URI"):
if os.environ.get(var):
found.append(("container endpoint", var))
try:
socket.create_connection(("169.254.169.254", 80), timeout=0.3).close()
found.append(("instance metadata", "169.254.169.254 reachable"))
except OSError:
pass
for source, value in found:
print(f" {source:24s} {value}")
if not found:
print(" (nothing)")
'''
PARENT_KEY = "ASIAPARENTEXAMPLE0001"
SCOPED_KEY = "ASIASCOPEDEXAMPLE0002"
def main():
home = Path(tempfile.mkdtemp(prefix="parent-home-"))
(home / ".aws").mkdir()
(home / ".aws" / "credentials").write_text(
"[default]\n"
f"aws_access_key_id = {PARENT_KEY}\n"
"aws_secret_access_key = parent-secret-placeholder\n"
"aws_session_token = parent-token-placeholder\n"
)
parent_env = {
"PATH": os.environ["PATH"],
"HOME": str(home),
"AWS_ACCESS_KEY_ID": PARENT_KEY,
"AWS_SECRET_ACCESS_KEY": "parent-secret-placeholder",
"AWS_SESSION_TOKEN": "parent-token-placeholder",
"AWS_CONTAINER_CREDENTIALS_RELATIVE_URI": "/v2/credentials/example",
}
scoped = {
"AWS_ACCESS_KEY_ID": SCOPED_KEY,
"AWS_SECRET_ACCESS_KEY": "scoped-secret-placeholder",
"AWS_SESSION_TOKEN": "scoped-token-placeholder",
}
launches = {
"1. inherit env, override AWS_* vars": {**parent_env, **scoped},
"2. clean env, same filesystem": {"PATH": parent_env["PATH"], "HOME": str(home), **scoped},
"3. clean env, empty HOME": {"PATH": parent_env["PATH"],
"HOME": tempfile.mkdtemp(prefix="sub-home-"), **scoped},
}
for name, env in launches.items():
print(name, flush=True)
subprocess.run([sys.executable, "-I", "-c", PROBE], env=env, check=True)
if __name__ == "__main__":
main()
Output, on a laptop with no instance metadata service:
1. inherit env, override AWS_* vars
env vars ASIASCOPEDEXAMPLE0002
credentials [default] ASIAPARENTEXAMPLE0001
container endpoint AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
2. clean env, same filesystem
env vars ASIASCOPEDEXAMPLE0002
credentials [default] ASIAPARENTEXAMPLE0001
3. clean env, empty HOME
env vars ASIASCOPEDEXAMPLE0002
Reading the output
Launch 1 is how most code starts a child process: copy the current environment, override the variables you care about. And it passes the test you’d naturally write, because the scoped key is in the environment and environment variables come first in the SDK credential chain. Call S3 from the sub-agent and you’ll see the scope-down working.
It’s also the launch that leaks the most. The parent’s key is sitting in ~/.aws/credentials, one file read away. The container credentials variable came along with the rest of the environment, so anything that unsets the AWS_* variables falls through the chain to the task role. Neither needs an exploit. It needs a sub-agent with a file tool or a shell, which is most of them.
Launch 2 cleans the environment and still leaks the file. Launch 3 is the only one where the sub-agent sees nothing but the scoped key, and only because it got its own empty home directory.
On a real host there’s more to close. On EC2, a process on the instance can reach the instance metadata service whatever environment you give it. When IMDSv2 is required, a hop limit of 1 keeps the response from reaching containers, but not a plain process on the host. On Linux, a process can often read /proc/<pid>/environ of another process running as the same user, which is where the parent’s variables are. So “clean environment” means a separate user or a separate container, not just a separate dictionary.
I’d also expect agents to find these paths more often than ordinary code does, and this part is opinion. A script that gets AccessDenied fails. An agent that gets AccessDenied and has a shell tries something else, because finishing the task is the whole point of it. Looking for another credential is a reasonable next step from its point of view.
Three details in the docs that change your design
Deny sts:AssumeRole* in every scope-down. The IAM docs’ own deny-list example excludes it, alongside the destructive EC2, RDS and S3 actions. The reason is that a role you assume gets that role’s permissions, not your scope-down. If the parent role is allowed to assume something bigger and the scoped credential still allows sts:AssumeRole, the sub-agent can climb out of its layer in one call.
There’s no per-sub-agent revoke. Scoped credentials inherit the parent session’s issue time and can’t be revoked on their own. Revoking the role’s older sessions takes every layer with them. So the duration is your revocation: ask for minutes, not the parent’s remaining hours, and put a ceiling on it with an SCP. The docs show one that denies sts:GetScopedCredentials when sts:DurationSeconds is greater than 900. If you’re designing a kill switch for agents, this is the trade: stopping one sub-agent early means stopping its siblings too, so keep its life short enough that you rarely need to.
Attribution is your job. Every layer has the parent’s principal ARN. CloudTrail records the GetScopedCredentials call with your scopedSessionDescription, and the response carries a scopedSessionId. Write both into the record of which agent did what and under whose authority, the evidence an AI operator owes you, or you’ll be reconstructing it from timestamps later.
Two smaller notes from the same page. Same-account resource policies don’t bypass the scope-down: for these credentials both the identity side and the scope-down must allow the action, even when a bucket policy trusts the principal directly. And some services cache KMS data keys, so removing KMS permissions in a scope-down may not block access to data that was decrypted recently.
The three-layer limit is a design constraint too. Orchestrator, sub-agent, tool worker is the whole budget. If your agents spawn agents that spawn agents, the fourth level needs a fresh role session, which brings back the AssumeRole dance this API was meant to remove.
Where the boundary actually is
GetScopedCredentials makes the credential honest: it can’t do more than you said. That’s the authorization half, and it’s the easy half. The isolation half lives in the launcher: which environment the sub-agent gets, which files it can open, which network it’s on. Hand a well-scoped key to a process that can read the parent’s, and you’ve built a nicer front door on a house with the back door open.
Comments