Skip to content

Commit f296c2c

Browse files
committed
fix(payments): two IAM grants and SDK version compat
Found in end-to-end deploy + invoke testing: 1. Vended cdk-stack.ts: grant runtime execution role sts:AssumeRole on the ProcessPaymentRole. ProcessPaymentRole's trust policy allows AccountRootPrincipal, but the caller still needs sts:AssumeRole on its own role. Without this, every invoke that touches payments fails with AccessDenied. 2. Vended payments.py: detect whether the installed bedrock-agentcore SDK supports the boto3_session field via inspect.signature() before passing it. The field was added in 1.11; older published versions (1.10 and below) reject the kwarg. Falls back to the runtime role's default credentials with a warning when the SDK is too old.
1 parent 1e89b90 commit f296c2c

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ exports[`Assets Directory Snapshots > CDK assets > cdk/cdk/lib/cdk-stack.ts shou
283283
type CustomJWTAuthorizerConfig,
284284
} from '@aws/agentcore-cdk';
285285
import { CfnOutput, Stack, type StackProps } from 'aws-cdk-lib';
286+
import * as iam from 'aws-cdk-lib/aws-iam';
286287
import { Construct } from 'constructs';
287288
288289
export interface PaymentConnectorSpec {
@@ -376,6 +377,16 @@ export class AgentCoreStack extends Stack {
376377
env.runtime.addEnvironmentVariable(\`\${prefix}_MANAGER_ARN\`, manager.paymentManagerArn);
377378
env.runtime.addEnvironmentVariable(\`\${prefix}_PROCESS_PAYMENT_ROLE_ARN\`, manager.processPaymentRoleArn);
378379
380+
// Grant runtime execution role permission to assume the ProcessPaymentRole.
381+
// The ProcessPaymentRole's trust policy allows AccountRootPrincipal, but the
382+
// caller still needs sts:AssumeRole on its own role to perform the assumption.
383+
env.runtime.role.addToPrincipalPolicy(
384+
new iam.PolicyStatement({
385+
actions: ['sts:AssumeRole'],
386+
resources: [manager.processPaymentRoleArn],
387+
})
388+
);
389+
379390
if (payment.autoPayment !== undefined) {
380391
env.runtime.addEnvironmentVariable(\`\${prefix}_AUTO_PAYMENT\`, String(payment.autoPayment));
381392
}
@@ -5450,7 +5461,17 @@ def create_payments_plugin(user_id, instrument_id=None, session_id=None):
54505461
config_kwargs["network_preferences_config"] = _network_prefs
54515462
54525463
if _process_payment_role_arn:
5453-
config_kwargs["boto3_session"] = _assume_role_session(_process_payment_role_arn)
5464+
# Only pass boto3_session if SDK supports it (added in bedrock-agentcore >= 1.11).
5465+
# Older SDKs use the runtime role's default credentials and can still call ProcessPayment
5466+
# if the runtime role has been granted permission directly.
5467+
import inspect
5468+
if "boto3_session" in inspect.signature(AgentCorePaymentsPluginConfig).parameters:
5469+
config_kwargs["boto3_session"] = _assume_role_session(_process_payment_role_arn)
5470+
else:
5471+
logger.warning(
5472+
"PROCESS_PAYMENT_ROLE_ARN set but bedrock-agentcore SDK does not support boto3_session. "
5473+
"Upgrade to bedrock-agentcore>=1.11 to enable cross-role payment processing."
5474+
)
54545475
54555476
if _auth_mode == "bearer":
54565477
bearer_token = os.getenv("AGENTCORE_BEARER_TOKEN")

src/assets/cdk/lib/cdk-stack.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type CustomJWTAuthorizerConfig,
99
} from '@aws/agentcore-cdk';
1010
import { CfnOutput, Stack, type StackProps } from 'aws-cdk-lib';
11+
import * as iam from 'aws-cdk-lib/aws-iam';
1112
import { Construct } from 'constructs';
1213

1314
export interface PaymentConnectorSpec {
@@ -101,6 +102,16 @@ export class AgentCoreStack extends Stack {
101102
env.runtime.addEnvironmentVariable(`${prefix}_MANAGER_ARN`, manager.paymentManagerArn);
102103
env.runtime.addEnvironmentVariable(`${prefix}_PROCESS_PAYMENT_ROLE_ARN`, manager.processPaymentRoleArn);
103104

105+
// Grant runtime execution role permission to assume the ProcessPaymentRole.
106+
// The ProcessPaymentRole's trust policy allows AccountRootPrincipal, but the
107+
// caller still needs sts:AssumeRole on its own role to perform the assumption.
108+
env.runtime.role.addToPrincipalPolicy(
109+
new iam.PolicyStatement({
110+
actions: ['sts:AssumeRole'],
111+
resources: [manager.processPaymentRoleArn],
112+
})
113+
);
114+
104115
if (payment.autoPayment !== undefined) {
105116
env.runtime.addEnvironmentVariable(`${prefix}_AUTO_PAYMENT`, String(payment.autoPayment));
106117
}

src/assets/python/http/strands/capabilities/payments/payments.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,17 @@ def create_payments_plugin(user_id, instrument_id=None, session_id=None):
113113
config_kwargs["network_preferences_config"] = _network_prefs
114114

115115
if _process_payment_role_arn:
116-
config_kwargs["boto3_session"] = _assume_role_session(_process_payment_role_arn)
116+
# Only pass boto3_session if SDK supports it (added in bedrock-agentcore >= 1.11).
117+
# Older SDKs use the runtime role's default credentials and can still call ProcessPayment
118+
# if the runtime role has been granted permission directly.
119+
import inspect
120+
if "boto3_session" in inspect.signature(AgentCorePaymentsPluginConfig).parameters:
121+
config_kwargs["boto3_session"] = _assume_role_session(_process_payment_role_arn)
122+
else:
123+
logger.warning(
124+
"PROCESS_PAYMENT_ROLE_ARN set but bedrock-agentcore SDK does not support boto3_session. "
125+
"Upgrade to bedrock-agentcore>=1.11 to enable cross-role payment processing."
126+
)
117127

118128
if _auth_mode == "bearer":
119129
bearer_token = os.getenv("AGENTCORE_BEARER_TOKEN")

0 commit comments

Comments
 (0)