|
| 1 | +# AWS Bedrock AgentCore - Code Interpreter Role Pivot |
| 2 | + |
| 3 | +## Service |
| 4 | + |
| 5 | +**Amazon Bedrock AgentCore** |
| 6 | + |
| 7 | +## Technique Name |
| 8 | + |
| 9 | +**Code Interpreter Role Pivot** (Privilege escalation/lateral movement via over-privileged `executionRoleArn`) |
| 10 | + |
| 11 | +## Why this Matters |
| 12 | + |
| 13 | +Amazon Bedrock AgentCore introduced a "Code Interpreter" feature in mid-2025 that acts as a managed compute surface. It executes code within a Firecracker MicroVM-isolated environment. The critical security hook is the **`executionRoleArn`**: this is the IAM identity the interpreter uses to interact with other AWS services. |
| 14 | + |
| 15 | +When a developer grants this service-linked role excessive permissions (e.g., `s3:*`, `secretsmanager:GetSecretValue`), any user with the ability to invoke the interpreter can effectively "hijack" those permissions to move laterally or escalate privileges within the account. |
| 16 | + |
| 17 | + |
| 18 | +## Preconditions (The Misconfiguration) |
| 19 | + |
| 20 | +1. **Over-privileged Execution Role:** An AgentCore Code Interpreter is configured with a role that has access to sensitive data or administrative APIs. |
| 21 | +2. **Broad Invocation Access:** A low-privileged IAM principal is granted permission to start or interact with these sessions. |
| 22 | +3. **Governance Failure:** The environment is treated as "AI experimental tooling" rather than "Managed Compute," bypassing standard Least Privilege reviews. |
| 23 | + |
| 24 | + |
| 25 | +## Required IAM Actions |
| 26 | + |
| 27 | +To execute this pivot, an attacker needs one or more of the following `bedrock-agentcore` actions: |
| 28 | + |
| 29 | +* `bedrock-agentcore:StartCodeInterpreterSession` |
| 30 | +* `bedrock-agentcore:InvokeCodeInterpreter` |
| 31 | +* `bedrock-agentcore:CreateCodeInterpreter` (Allows creating a session with a pre-existing role) |
| 32 | + |
| 33 | +> **Note on `iam:PassRole`:** In current AWS Service Authorization References, `CreateCodeInterpreter` does not explicitly list `iam:PassRole` as a dependency in the same way `CreateGateway` does. This creates a potential "PassRole-less" role selection edge case that should be validated in target environments. |
| 34 | +
|
| 35 | + |
| 36 | +## Exploitation Flow |
| 37 | + |
| 38 | +### 1. Reconnaissance |
| 39 | + |
| 40 | +Identify existing interpreters and their associated execution roles. |
| 41 | + |
| 42 | +```bash |
| 43 | +aws bedrock-agentcore-control list-code-interpreters |
| 44 | +aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id <TARGET_ID> |
| 45 | + |
| 46 | +``` |
| 47 | + |
| 48 | +### 2. Session Initiation |
| 49 | + |
| 50 | +Start a session to gain access to the compute environment. |
| 51 | + |
| 52 | +```bash |
| 53 | +aws bedrock-agentcore start-code-interpreter-session --code-interpreter-id <TARGET_ID> |
| 54 | + |
| 55 | +``` |
| 56 | + |
| 57 | +### 3. Lateral Movement / Exfiltration |
| 58 | + |
| 59 | +Invoke the interpreter to execute Python code that uses the `executionRoleArn` credentials to access other services. |
| 60 | + |
| 61 | +```python |
| 62 | +import boto3 |
| 63 | +# The interpreter uses the executionRoleArn automatically |
| 64 | +s3 = boto3.client('s3') |
| 65 | +print(s3.list_buckets()) |
| 66 | + |
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | +## Mitigation & Detection |
| 71 | + |
| 72 | +### **Prevention** |
| 73 | + |
| 74 | +* **Apply Permission Boundaries:** Attach a boundary to the `executionRoleArn` to ensure it cannot perform IAM mutations or sensitive data deletions, regardless of its primary policy. |
| 75 | +* **Restrict Invocation:** Limit `StartCodeInterpreterSession` and `InvokeCodeInterpreter` to specific, authorized admin principals. |
| 76 | +* **Identity Scoping:** Use the `bedrock-agentcore:sessionId` and `bedrock-agentcore:actorId` condition keys to ensure sessions are isolated to specific users. |
| 77 | + |
| 78 | +### **Detection** |
| 79 | + |
| 80 | +* **CloudTrail Monitoring:** Monitor for `StartCodeInterpreterSession` events from unexpected IPs or principals. |
| 81 | +* **Credential Usage:** Alert on the use of AgentCore execution role credentials (detectable via the `UserAgent` or `PrincipalId` in CloudTrail) to access S3 buckets or Secrets Manager outside of normal AI operations. |
| 82 | + |
| 83 | + |
| 84 | +## References |
| 85 | + |
| 86 | +* [AWS CLI Reference: create-code-interpreter](https://docs.aws.amazon.com/cli/latest/reference/bedrock-agentcore-control/create-code-interpreter.html) |
| 87 | +* [AWS Service Authorization: Bedrock AgentCore](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrockagentcore.html) |
| 88 | +* [AWS CLI: start-code-interpreter-session](https://docs.aws.amazon.com/cli/latest/reference/bedrock-agentcore/start-code-interpreter-session.html) |
0 commit comments