· AI dev tools

AWS STS GetScopedCredentials API scopes down permissions of existing sessions for AI agents

A sub-agent might only require specific permissions, not the entire scope of the session that initiated it, a common requirement when constructing AI agents.


To address this, AWS has introduced GetScopedCredentials, a novel API within the AWS Security Token Service (AWS STS) that permits restricting the permissions associated with existing temporary security credentials. This functionality enables you to grant each component—be it an agent, a sub-agent, or a process—its own set of credentials. These new credentials retain the caller's AWS Identity and Access Management (IAM) identity but can be configured with diminished permissions, a shorter active period, or both. You can invoke GetScopedCredentials using credentials you are already utilizing, such as those obtained via `aws login`, an Amazon Elastic Compute Cloud (Amazon EC2) instance profile, or from an AWS Lambda function. With every invocation, you must supply either a scope down policy, a reduced session duration, or both. A scope down policy functions as an inline policy, detailing the maximum permissions the newly generated credentials should possess. The permissions granted are determined by the intersection between the effective permissions of your current session and the scope down policy; consequently, permissions can only ever be reduced. Likewise, the session duration you request cannot surpass the remaining time of the session that made the call. Furthermore, you possess the option to call GetScopedCredentials again, using the resulting credentials, to impose further restrictions on permissions or to shorten the session duration even more. This API is engineered to serve as a fundamental building block. Because it restricts permissions on credentials you already hold, it integrates seamlessly into various systems, including agent frameworks, services that issue credentials to other parts of a system, continuous integration and deployment (CI/CD) pipelines, and custom applications. You can also chain calls, using the credentials that have already been scoped down to provide a sub-agent with even narrower access than the orchestrating agent itself. This discussion will explore several typical scenarios to get you started, demonstrate the procedure for invoking GetScopedCredentials, and clarify how to manage access to this feature.

Any operational workload that needs less access than the session that launches it can benefit from GetScopedCredentials. Examples where this is applicable include limiting the capabilities of AI agents, tailoring permissions based on the circumstances of execution, and providing access only when it is strictly necessary (just-in-time access). This section delves into two of the most frequently encountered use cases in greater detail.

When credentials are provided to an agent, that agent has the authority to execute any action permitted by those credentials. Since an agent determines its actions dynamically during runtime, often guided by prompts or output from tools, overly broad permissions on its credentials present a risk; a flawed agent could potentially operate outside the scope of its assigned task. Prior to handing credentials to an agent, you can employ GetScopedCredentials to narrow permissions down to precisely what its duties demand, perhaps limiting it to only reading from a specific Amazon Simple Storage Service (Amazon S3) bucket. Alternatively, you might opt for the reverse approach: retaining most of its existing permissions while explicitly removing specific actions the agent should never perform, such as resource deletion. An orchestrating agent can extend this practice to every sub-agent it initiates. Since a scope down operation can only narrow access, a sub-agent will never possess greater access than the agent that spawned it. To help guarantee that your agents adhere to the restricted credentials, running them within isolated or sandbox environments, such as AWS Strands Box, is advisable.

In many scenarios, various workloads operate under a single IAM role but each task requires a distinct, more limited set of permissions. The appropriate permission set for a specific task frequently hinges on information the workload only acquires during its execution, such as the identity of the entity that submitted a request. Imagine a multi-tenant application where each tenant's files reside under a separate directory prefix within a single S3 bucket. This application uses one IAM role to serve all its tenants, meaning the role inherently has access to every tenant's prefix. However, each incoming request should only access the files belonging to the tenant who initiated it, and the application only ascertains this tenant identity after successfully authenticating the request. At that juncture, a trusted credential broker within the application extracts the tenant details from the authenticated session and subsequently calls GetScopedCredentials, providing a scope down policy that permits access exclusively to that tenant's specific prefix. It then furnishes only these narrowly scoped credentials to the worker responsible for handling the request, ensuring that Amazon S3 denies that worker access to any other tenants' prefixes, even though the original role grants it access to all of them.

To initiate the process of restricting permissions for an established session, this section outlines the necessary steps. Before invoking GetScopedCredentials, you must possess valid temporary security credentials, and those credentials must carry the authorization to call the API. The following identity-based policy grants this necessary permission: { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "sts:GetScopedCredentials", "Resource": "*" }] }.

You can utilize either the most recent version of the AWS Command Line Interface (AWS CLI) or the AWS SDK corresponding to your chosen programming language to make the call to GetScopedCredentials.

Step 1: Formulate a scope down policy. You must construct a scope down policy that specifies the maximum permissions the resulting credentials ought to hold. Initially, GetScopedCredentials accepts a single inline scope down policy, limited to 2,048 characters. You have several avenues for creating this policy: you can author it entirely from scratch, adapt or reuse an existing one, or request an AI assistant to draft it for you. This section covers two distinct methods for achieving this.

Option A: Drafting the policy yourself. If you are certain about the exact actions and resources your task requires, you should write the policy directly. The following example policy permits the resultant credentials to only retrieve objects from a single S3 bucket: { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*" }] }. It is crucial to include every action the task depends on; for instance, if your task uses Amazon Athena to query data residing in Amazon S3, the policy must also permit `s3:GetObject` on that data, as Athena utilizes your credentials to read it. To retain the majority of the calling session's permissions while eliminating only a few sensitive ones, employ an `Allow` statement combined with `NotAction`. This statement does not bestow new access because a scope down policy is inherently restrictive. The resulting credentials will retain the calling session's permissions, minus the actions you list, offering a rapid method to establish safeguards without enumerating every single action a task might need. The following sample policy restricts identity and account management, assumes other roles, and deletes certain vital resources: { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "NotAction": [ "iam:*", "organizations:*", "account:*", "sts:AssumeRole*", "s3:DeleteBucket", "ec2:TerminateInstances", "rds:DeleteDBInstance", "dynamodb:DeleteTable" ], "Resource": "*" }] }.

Option B: Generating the policy using IAM Policy Autopilot. An alternative is to leverage IAM Policy Autopilot to generate the required scope down policy. IAM Policy Autopilot is an open-source utility provided by AWS that examines the AWS SDK calls within your code to pinpoint the permissions necessary for successful execution. You can run this tool either from the command line or as a Model Context Protocol (MCP) server within your AI coding assistant. Refer to the Getting Started documentation for IAM Policy Autopilot to install it. We will illustrate policy generation using the following Python code, which logs a report's status into an Amazon DynamoDB table:

import json import logging import os import boto3 from botocore.exceptions import ClientError

logger = logging.getLogger() logger.setLevel(logging.INFO) dynamodb = boto3.client("dynamodb") table_name = os.environ["TABLE_NAME"]

def _response(status_code, message): return {"statusCode": status_code, "body": json.dumps({"message": message})}

def handler(event, context): try: request = json.loads(event.get("body") or "{}") report_id = request["reportId"] except (json.JSONDecodeError, KeyError, TypeError): return _response(400, "Request body must be JSON with a reportId")

if not isinstance(report_id, str) or not report_id: return _response(400, "reportId must be a non-empty string")

try: dynamodb.put_item( TableName=table_name, Item={ "reportId": {"S": report_id}, "status": {"S": "READY"}, }, ConditionExpression="attribute_not_exists(reportId)", ) return _response(200, "Report status saved") except ClientError as error: code = error.response["Error"]["Code"] if code == "ConditionalCheckFailedException": return _response(409, "Report status already exists") logger.error("PutItem failed: %s", code) return _response(500, "Unable to save the report status")

Save this code as `report_status.py` and execute the following command. Should the generated policy

Earlier coverage

Related coverage

Also worth reading

  1. Next.js 16.5.0-canary.61 adds experimental image optimization support, Turbopack cache recovery
  2. Firefox UI features glowing progress bar in URL bar, user criticizes "AI slop
  3. Grafana 13.3 adds shared dashboard variables, Notebooks in public preview
  4. QCon San Francisco 2026: Netflix engineer presents staff-plus alignment for tech strategy
  5. Researchers show malicious webpage can hijack Meta Muse and access private chats