Subchapter 23.1
references/agentcore-credentials-and-security.mdMarkdown6 KBView on GitHub
Assets
Kb Shim PyThree authentication types for AgentCore services. Getting the wrong type causes hard-to-debug 401/403 errors.
Security consideration: API keys are long-lived credentials. Prefer IAM authentication (ephemeral, auto-rotated) or OAuth when the target supports it. Use API keys only when the external target requires them (e.g., third-party APIs that only accept API key auth).
Setup sequence:
1. Create credential provider with the API key value (transmitted over TLS/SigV4; service encrypts and stores it in Secrets Manager internally)
2. Attach credential provider to Gateway targetConstraints:
export API_KEY=<their-key>aws bedrock-agentcore-control create-api-key-credential-provider --name <name> --api-key "$API_KEY"apiKeySecretArn)aws bedrock-agentcore-control update-api-key-credential-provider --name <name> --api-key "$NEW_API_KEY" — the service re-encrypts and stores the new key internally. Do not call secretsmanager rotate-secret directly on the service-managed secret.CreateApiKeyCredentialProvider, UpdateApiKeyCredentialProvider, DeleteApiKeyCredentialProvider) logged under eventSource: bedrock-agentcore.amazonaws.comConstraints:
create-oauth2-credential-provider API call (the service encrypts and stores it in Secrets Manager automatically — response includes clientSecretArn)aws bedrock-agentcore-control create-oauth2-credential-provider --name <name> --credential-provider-vendor <vendor> --oauth2-provider-config-input '...'For Lambda targets and cross-service communication:
AgentCore has three distinct OAuth layers — agents confuse these:
| Layer | Direction | Purpose |
|---|---|---|
| Inbound JWT | Caller → AgentCore | Validate tokens from callers (Cognito, external IdPs) |
| Outbound Credential Provider | Agent → External API | Agent authenticating to external APIs via Gateway |
| Gateway OAuth | Gateway → Upstream MCP | Gateway authenticating to upstream MCP servers |
Each layer is configured independently. Getting the wrong layer causes auth failures that look identical (401/403) but have different root causes.
Supported IdPs for inbound JWT: Cognito, Okta, Auth0, Azure AD, custom OIDC.
Refer to the latest AWS documentation on AgentCore OAuth architecture for current configuration steps and CDK examples.
Cross-account Bedrock access requires IAM trust policies on both sides.
Pattern:
bedrock:InvokeModel permission and sts:AssumeRole to the target account’s rolebedrock:InvokeModel permissionTrust policy pattern (target account role):
{
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::<calling-account-id>:role/<role-name>"},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "<agreed-external-id>"
}
}
}Include sts:ExternalId for confused deputy protection. For service-to-service access, use aws:SourceArn and aws:SourceAccount conditions instead.
Common failure: AccessDeniedException when calling Bedrock from a different account — verify:
bedrock:InvokeModel permission in the target accountRefer to the latest AWS documentation on Bedrock cross-account access for current IAM policy patterns and any service-specific conditions.
| Practice | How |
|---|---|
| Resource-based policies | Restrict access to specific principals, accounts, VPCs |
| VPC endpoints | Private AgentCore access without internet traversal |
| IP restrictions | Limit access by source IP range |
| Encryption | Data encrypted at rest and in transit by default |
| Audit logging | Enable CloudTrail for all AgentCore API calls |
| Least privilege | Grant only required permissions per service role |
Deploying framework-specific agents on AgentCore Runtime:
| Framework | Key Configuration |
|---|---|
| Strands Agents | S3 for file storage, session state via Memory service |
| LangChain/LangGraph | Standard Python deployment, state management via Memory |
| Custom frameworks | Implement the protocol contract (HTTP/MCP/A2A/AG-UI) |
Refer to the latest AWS documentation on AgentCore deployment for the relevant framework.
Constraints: