Skip to content

fix(build): Keep the Bedrock grant of the Box gateway in its region and account - #2883

Merged
SaiAbhishek98 merged 3 commits into
aws:box-integrationfrom
SaiAbhishek98:sa/box-bedrock-policy-scope
Nov 21, 2026
Merged

SaiAbhishek98 merged 3 commits into
aws:box-integrationfrom
SaiAbhishek98:sa/box-bedrock-policy-scope

Conversation

@SaiAbhishek98

@SaiAbhishek98 SaiAbhishek98 commented Nov 20, 2026 •

Copy link
Copy Markdown

Description

Problem. On box-integration, agentcore/box-bedrock-policy.json gives the role of the Box gateway bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream. The role can use them on all inference profiles and all foundation models, in all regions and in all accounts:

"Resource": ["arn:aws:bedrock:*:*:inference-profile/*", "arn:aws:bedrock:*::foundation-model/*"]

The agent uses the model only through the bedrock target of its Box gateway. build writes that target for one region, and the agent uses only the inference profiles of the account of the gateway. A code inspection found this problem. aws/agentcore-cli#2851 (e96cbdb9) gave the same limits to box-memory-policy.json. This PR uses the same procedure for the Bedrock file.

Change. 3 commits:

  1. 555f19c6: the Bedrock policy of the Box gateway keeps to the build region and to the account of the role. The text below is about this commit.
  2. 0d8c8d38: the Memory policy gets the partition from the region, the same as the Bedrock policy. This is the comment of leo237 on boxMemory.ts.
  3. 0b0b2b31: the Bedrock and AgentCore hosts of the Box gateway targets get the DNS suffix of the partition, for example amazonaws.com.cn in aws-cn. This is the comment of leo237 on shortcuts.ts. This problem was on box-integration before this PR.

In commit 1, boxBedrockPolicy(spec, region) gets the region of the bedrock target from the default targets writer, at the same location where boxMemoryPolicy gets its region. For us-west-2, build writes this policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "BoxedAgentInferenceProfilesThroughGateway",
      "Effect": "Allow",
      "Action": [
        "bedrock:InvokeModel",
        "bedrock:InvokeModelWithResponseStream"
      ],
      "Resource": [
        "arn:aws:bedrock:us-west-2:*:inference-profile/*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:ResourceAccount": "${aws:PrincipalAccount}"
        }
      }
    },
    {
      "Sid": "BoxedAgentModelsInRegionThroughGateway",
      "Effect": "Allow",
      "Action": [
        "bedrock:InvokeModel",
        "bedrock:InvokeModelWithResponseStream"
      ],
      "Resource": [
        "arn:aws:bedrock:us-west-2::foundation-model/*"
      ]
    },
    {
      "Sid": "BoxedAgentModelsThroughInferenceProfiles",
      "Effect": "Allow",
      "Action": [
        "bedrock:InvokeModel",
        "bedrock:InvokeModelWithResponseStream"
      ],
      "Resource": [
        "arn:aws:bedrock:*::foundation-model/*"
      ],
      "Condition": {
        "StringLike": {
          "bedrock:InferenceProfileArn": "arn:aws:bedrock:us-west-2:${aws:PrincipalAccount}:inference-profile/*"
        }
      }
    }
  ]
}
Statement What it lets the gateway role do
BoxedAgentInferenceProfilesThroughGateway Use an inference profile in the region, only in the account of the role.
BoxedAgentModelsInRegionThroughGateway Use a foundation model in the region, when the agent names the model ID.
BoxedAgentModelsThroughInferenceProfiles Use a foundation model in all regions, only through an inference profile of that account in the region.

boxGatewayIamWarnings counts the Bedrock file only for the Bedrock runtime host of the build region. It counts the Memory file in the same manner. The new boxGatewayBedrockHost(region) gives that host.

The decisions.

  • The account is in a condition, not in the ARN. One file is for all deploy targets. IAM does not let a policy variable go into the account part of a Resource ARN. Thus the profile ARN keeps * for the account, and "aws:ResourceAccount": "${aws:PrincipalAccount}" holds it to the account of the role, as in box-memory-policy.json.
  • StringLike, not ArnLike, for bedrock:InferenceProfileArn. The IAM page on policy variables says that a variable can go into an ARN condition. But with ${aws:PrincipalAccount} in the account part of an ArnLike value, CreatePolicy and the stack give The policy failed legacy parsing. The simulator and Access Analyzer accept that policy, thus only a deploy found the problem. StringLike with the same value is accepted, and the Bedrock example in the AWS documents uses StringLike. The value starts with a fixed partition, region, and account, thus StringLike is not wider than ArnLike here.
  • A foundation model in a different region needs the profile condition. A us. or global. inference profile sends the model operation to other regions. Bedrock then examines the foundation model in each destination region, and puts the profile ARN in bedrock:InferenceProfileArn. For a global. profile, Bedrock also examines arn:aws:bedrock:::foundation-model/<model>, which has no region. The * region agrees with that ARN.
  • The partition comes from the region, not from the stack. The L3 reads the file with iam.PolicyDocument.fromJson. That function does not replace ${AWS::Partition}. Thus the CLI writes the partition of the region from the partition data of the AWS SDK, as boxTelemetryPolicy does. For cn-north-1, the ARNs start with arn:aws-cn:bedrock:.
  • No application inference profiles. The policy before this change did not let the role use an application-inference-profile ARN. The CLI does not make one, and no template names one. A user can type such an ARN as the model ID. That call is refused before and after this PR. To permit it, add one application-inference-profile/* ARN to statement 1 and to the condition of statement 3.
  • A different behavior for a user target. A user target that signs Bedrock runtime operations with the gateway role for a region that is not the build region is now refused by IAM. Build now gives a warning for that target. Before this PR, the policy let that target operate.

The AWS documents for each statement.

  • Prerequisites for inference profiles: a profile ARN needs the foundation model in each region of the profile, and bedrock:InferenceProfileArn can limit a foundation-model statement to calls through a profile.
  • Geographic cross-Region inference: Bedrock examines the profile, the model in the source region, and the model in each destination region. The condition key is in the model evaluations, not in the profile evaluation.
  • Global cross-Region inference: the global model ARN arn:aws:bedrock:::foundation-model/<model>, which has no region.
  • Actions, resources, and condition keys for Amazon Bedrock: the inference-profile, application-inference-profile, and foundation-model ARN formats, and bedrock:InferenceProfileArn on InvokeModel and InvokeModelWithResponseStream.
  • IAM policy elements: Variables and tags: a variable in a Resource ARN is only in the resource part, after the fifth colon. The page also says that a variable can be in a string or an ARN condition. IAM refuses it in the account part of an ArnLike value, as the decisions above tell.
  • IAM JSON policy elements: Resource: a * agrees with 0 or more characters in its part of the ARN.
  • AWS global condition context keys: aws:ResourceAccount is in the request context for most API operations. Bedrock is not in the list of exceptions. aws:PrincipalAccount is in the context of all requests.

Base. This PR starts from box-integration at e2ac9d78.

Items to examine.

  • boxBedrockPolicy in src/core/project/boxMemory.ts.
  • defaultTargetsWriter in src/core/project/boxNetworkWriters.ts.
  • boxGatewayIamWarnings in src/core/project/boxNetwork/network.ts.
  • boxGatewayBedrockHost and boxGatewayAgentCoreHost in src/handlers/project/shortcuts.ts.

Related Issue

None. A code inspection of the Box gateway grants found this problem.

Documentation PR

Not applicable. This PR adds no command and no flag, and no document names the ARNs of the previous policy.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Testing

How have you tested the change?

  • I ran bun test: 5836 pass, 7 skip, 0 fail, in 353 files. The 5 test files that this PR changes: 134 pass, 0 fail.
  • I ran the relevant end-to-end tests with bun run test:e2e, or explained why they are not applicable: I did not do these tests. They deploy resources in AWS. I did the live test below.
  • I ran bun run typecheck
  • I ran bun run lint:check: exit 0.
  • I ran bun run format:check
  • I ran bun run audit: not done. This PR adds no package.
  • I ran bun run secrets:check: not done.
  • I ran bun run build: not done.
  • If I modified src/assets/, I updated affected snapshots: this PR does not change src/assets/.
  • If I re-recorded fixtures or golden files: this PR changes no fixture and no golden file. manager.test.ts and boxNetworkSource.test.ts name box-bedrock-policy.json, but they examine only its name and its position in additionalPolicies. They do not change.
  • This PR does not change command.md (the release workflow regenerates it)

The tests that change, and the cause of each change. Before its commit, each of these 10 tests gives (fail). After its commit, each gives (pass).

  • boxMemory.test.ts, boxBedrockPolicy: 3 tests, 1 for each statement, and 1 test for the partition of cn-north-1 and us-gov-west-1. These replace the test "grants the gateway role the model invoke actions in any region".
  • boxNetworkWriters.test.ts: "writes the Bedrock policy for the region of the bedrock target it writes". This is the Bedrock copy of the Memory test of aws/agentcore-cli#2851.
  • manager.boxNetwork.test.ts: "moves the Memory and Bedrock policies with their targets to the region of the targets". The Memory test of aws/agentcore-cli#2851 now also examines the bedrock target and the Bedrock policy. A deploy to a target in eu-west-1 moves both from us-west-2.
  • network.test.ts: "a Bedrock runtime target needs bedrock:InvokeModel, which the Bedrock file grants in the build region only". This IAM-warning test gets 1 more case: a bedrock target in us-east-1, with a build for us-west-2, gets the warning. Before this PR, the listed file counted for each region, because the policy allowed each region.
  • boxMemory.test.ts, boxMemoryPolicy: "names the partition of the region it is given", for cn-north-1 and us-gov-west-1 (commit 2).
  • shortcuts.test.ts: "take the DNS suffix of the partition of the region", for cn-north-1, us-gov-west-1, and us-west-2 (commit 3).
  • network.test.ts: "the Bedrock and Memory files grant the amazonaws.com.cn hosts of a build for China". A user target for the correct China host gets no warning (commit 3).

The tests find each change. I made each of these 12 changes, one at a time, and ran the test files of this PR. For each change, 1 or more of the tests above gave (fail). Then I removed the change.

Change Tests that fail
No aws:ResourceAccount condition 1
* region for the inference profiles 4
* region for the models by their ID 4
No bedrock:InferenceProfileArn condition 2
* account in that condition 2
ArnLike and not StringLike 2
A constant arn:aws partition 1
A constant region in the writer 2
No host check in the IAM warning 1
A constant arn:aws in the Memory ARN 1
A constant amazonaws.com in the Bedrock host 2
A constant amazonaws.com in the AgentCore host 2

IAM simulation. aws iam simulate-custom-policy on the us-west-2 policy, with aws:PrincipalAccount, aws:ResourceAccount, and bedrock:InferenceProfileArn in the context. simulate-principal-policy on the gateway role after the deploy gives the same 14 results. Both operations give the same result in each row.

Resource Context Result
arn:aws:bedrock:us-west-2::foundation-model/<m> no profile allowed
arn:aws:bedrock:us-west-2:<this>:inference-profile/us.<m> this account allowed
arn:aws:bedrock:us-west-2:<this>:inference-profile/global.<m> this account allowed
arn:aws:bedrock:us-west-2::foundation-model/<m> through the us. profile of this account allowed
arn:aws:bedrock:us-east-1::foundation-model/<m> through the us. profile of this account allowed
arn:aws:bedrock:us-east-2::foundation-model/<m> through the us. profile of this account allowed
arn:aws:bedrock:::foundation-model/<m> through the global. profile of this account allowed
arn:aws:bedrock:us-west-2:<other>:inference-profile/us.<m> a different account implicitDeny
arn:aws:bedrock:us-east-1:<this>:inference-profile/us.<m> this account, us-east-1 implicitDeny
arn:aws:bedrock:us-east-1::foundation-model/<m> no profile implicitDeny
arn:aws:bedrock:::foundation-model/<m> no profile implicitDeny
arn:aws:bedrock:us-east-1::foundation-model/<m> through a profile of a different account implicitDeny
arn:aws:bedrock:us-east-1::foundation-model/<m> through a profile of this account in us-east-1 implicitDeny
arn:aws:bedrock:us-west-2:<this>:application-inference-profile/abc123 this account implicitDeny

The policy before this PR gives allowed for all 6 of the implicitDeny rows that are not the application-inference-profile row.

Live test. I did this test in a dev account in us-west-2, with the CLI of this branch, box 0.1.11-preview.10 for macOS on PATH, and a local L3 from box-integration at 08f8b230.

  1. agentcore create --template agent-python-strands-box-container. The default model is the global.anthropic.claude-sonnet-5-5 inference profile. Build wrote the policy above.
  2. Deploy, and 6 invokes in 2 sessions. The agent gave 391, 5555 (through the add_numbers tool), and Paris, 2 times.
  3. I changed app/agent/model/load.py to the foundation model amazon.nova-lite-v1:0, did a deploy again, and did 3 invokes. The agent gave 391, 5555 (through add_numbers), and Paris, in the <thinking> format of Nova.
  4. CloudTrail shows 12 ConverseStream operations by the gateway role: 8 on global.anthropic.claude-sonnet-5-5 and 4 on amazon.nova-lite-v1:0, with no error code. The gateway role has only the Bedrock policy and the Memory policy. The APPLICATION_LOGS log group of the Box gateway shows 12 operations through the bedrock target, with no error.
  5. Teardown: agentcore remove all --yes and agentcore deploy --yes removed the stack. I removed the 3 log groups that stay after the stack: the runtime log group, the CodeBuild log group, and the Lambda log group. No gateway, runtime, Memory, ECR repository, role, or credential provider of the project stays. The CDK assets in the bootstrap bucket stay, and Transaction Search stays on in the account.

The first deploy used ArnLike. CloudFormation stopped it with The policy failed legacy parsing, and removed its resources. I removed that stack and changed the condition to StringLike before the commit.

Not shown live. CloudTrail gives "inferenceRegion": "us-west-2" for each operation of the global. profile. Thus the live test did not show a model operation in a different region. Bedrock examines the global model ARN, which has no region, for each operation of a global. profile, and the operations had no error. The simulation shows the other regions.

aws-cn and aws-us-gov have unit tests only. The unit tests examine the partition of the policy ARNs and the DNS suffix of the target hosts. I did no live test in these partitions.

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly: no document names the ARNs of the previous policy.
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.

…nd account

## Problem

agentcore/box-bedrock-policy.json lets the role of the Box gateway use
bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream on all
inference profiles and all foundation models, in all regions and in all
accounts:

  arn:aws:bedrock:*:*:inference-profile/*
  arn:aws:bedrock:*::foundation-model/*

The agent uses the model only through the `bedrock` target of the
gateway. `build` writes that target for one region. The agent uses only
the inference profiles of the account of the gateway. A code inspection
found this problem.

## Solution

boxBedrockPolicy(spec, region) gets the region of the `bedrock` target
from the default targets writer. boxMemoryPolicy gets the region of the
`agentcore` target from the same writer. When the writer has no region,
it writes no Bedrock policy and no Memory policy. The policy has 3
statements:

1. BoxedAgentInferenceProfilesThroughGateway: the inference profiles in
   the region. One file is for all deploy targets, thus the ARN keeps
   "*" for the account. The condition of
   [e96cbdb](aws@e96cbdb)
   keeps the inference profile in the account of the gateway role:
   "aws:ResourceAccount": "${aws:PrincipalAccount}".
2. BoxedAgentModelsInRegionThroughGateway: the foundation models in the
   region, when the agent names the model ID.
3. BoxedAgentModelsThroughInferenceProfiles: the foundation models in
   all regions, only when the agent uses an inference profile of that
   account in the region:
   "StringLike": {"bedrock:InferenceProfileArn":
   "arn:aws:bedrock:<region>:${aws:PrincipalAccount}:inference-profile/*"}.
   IAM does not accept that value in an ArnLike condition. CreatePolicy
   and the stack give "The policy failed legacy parsing". The Bedrock
   example in the AWS documents also uses StringLike.
   A `us.` or `global.` inference profile can send the model operation
   to other regions. For a `global.` inference profile, Bedrock also
   examines arn:aws:bedrock:::foundation-model/<model>, which has no
   region. The "*" region agrees with that ARN.

Each ARN has the partition of the region (aws, aws-cn, or aws-us-gov),
from the partition data of the AWS SDK. boxTelemetryPolicy uses the same
data. The policy file cannot contain the AWS::Partition value of the
stack, because the L3 reads the file with PolicyDocument.fromJson, and
that function does not replace such a value.

boxGatewayIamWarnings counts the Bedrock file only for the Bedrock
runtime host of the region that `build` writes. It counts the Memory
file only for the Memory host of that region. Thus a target that signs
Bedrock operations for a different region with the gateway role gets a
warning, because the new policy does not let the role do these
operations. The new boxGatewayBedrockHost(region) gives the host.

The policy keeps the same 2 operations. The policy does not let the
role use an `application-inference-profile`. The policy before this
change did not let the role use one, and the CLI does not make one.

## Tests

Before this change, each of these tests gives an incorrect result.
After this change, each result is satisfactory:

- boxMemory.test.ts, "boxBedrockPolicy": 1 test for each statement, and
  1 test for the partition of cn-north-1 and us-gov-west-1.
- boxNetworkWriters.test.ts, "writes the Bedrock policy for the region
  of the bedrock target it writes".
- manager.boxNetwork.test.ts, "moves the Memory and Bedrock policies
  with their targets to the region of the targets". A deploy to a
  target in eu-west-1 moves the `bedrock` target from us-west-2, and the
  Bedrock policy moves with it.
- network.test.ts, "a Bedrock runtime target needs bedrock:InvokeModel,
  which the Bedrock file grants in the build region only".

Each of 9 mutations gives an incorrect result in 1 or more of these
tests: no account condition, a wildcard region for the inference
profiles, a wildcard region for the models, no inference profile
condition, a wildcard account in that condition, ArnLike and not
StringLike, a constant `arn:aws`, a constant region in the writer, and
no host check in the warning.

IAM: `aws iam simulate-custom-policy` on the us-west-2 policy gives
`allowed` for these 7 items: the model in us-west-2 by its ID, the
`us.` and `global.` inference profiles of the account in us-west-2, and
the model in us-west-2, us-east-1, us-east-2, and in the region-less
global ARN through such a profile. It gives `implicitDeny` for these 7
items: an inference profile of a different account, an inference
profile in us-east-1, the model in us-east-1 and the global model with
no inference profile, the model in us-east-1 through a profile of a
different account or of us-east-1, and an
`application-inference-profile`. `simulate-principal-policy` on the
gateway role after the deploy gives the same 14 results. CreatePolicy accepts
the policy.

Live test in a dev account in us-west-2: a new project from the
agent-python-strands-box-container template, with the L3 at
[08f8b230](https://github.com/aws/agentcore-l3-cdk-constructs/commit/08f8b23002f9357b7607b9d073dfd77929629e6a).
With the default model, global.anthropic.claude-sonnet-5-5, 6 invokes
gave 391, 5555 (through the add_numbers tool), and Paris. Then
amazon.nova-lite-v1:0 in `app/agent/model/load.py`, a deploy, and 3
invokes gave the same answers. CloudTrail shows 12 ConverseStream operations
of the gateway role on these 2 model IDs, with no error code. The
gateway log group shows 12 operations through the `bedrock` target,
with no error. CloudTrail gives `"inferenceRegion": "us-west-2"` for
each operation, thus
the live test did not show a model operation in a different region.
Only the simulation shows it. The teardown removed the stack and the 3
log groups that stay after the stack.

Not done: `bun run test:e2e`, and a live test in aws-cn or aws-us-gov.

`bun test` gives `5833 pass, 7 skip, 0 fail`. The typecheck, lint, and
format checks are satisfactory.
@SaiAbhishek98
SaiAbhishek98 requested review from a team and leo237 November 20, 2026 22:53
@codecov-commenter

codecov-commenter commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.80%. Comparing base (e2ac9d7) to head (0b0b2b3).
⚠️ Report is 2 commits behind head on box-integration.

Additional details and impacted files
@@               Coverage Diff                @@
##           box-integration    #2883   +/-   ##
================================================
  Coverage            96.79%   96.80%           
================================================
  Files                  766      766           
  Lines                66803    66830   +27     
================================================
+ Hits                 64665    64692   +27     
  Misses                2138     2138           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leo237 leo237 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: scope the Bedrock grant of the Box gateway to its region and account

Verdict: approve. I found nothing blocking. The policy keeps the documented Bedrock paths working (in-region model, geographic us./eu./apac. profiles, global. profiles) and refuses direct calls to out-of-region models, profiles in other regions, and profiles of other accounts. The PR is up to date with box-integration (merge-base = e2ac9d78), and it reverts nothing.

IAM correctness, checked against the AWS docs

  • System-defined profiles carry the caller's account. Prerequisites for inference profiles shows the system-defined us. and global. profiles as arn:aws:bedrock:us-west-2:111122223333:inference-profile/us.anthropic..., "in the account 111122223333", which is the caller's account. So statement 1 (aws:ResourceAccount == ${aws:PrincipalAccount}) matches them. Your live run backs this up: the gateway role had only the Bedrock and Memory files, and 8 ConverseStream calls on global.anthropic.claude-sonnet-5-5 succeeded. That run could only pass through statement 1. Note that this is your empirical result. The docs don't say outright that aws:ResourceAccount is filled in for InvokeModel on an inference profile.
  • Out-of-region models through a profile. The same page says: "When you specify an inference profile in the Resource field ... you must also specify the foundation model in each Region associated with it". It also says bedrock:InferenceProfileArn "can be included in a statement that scopes to the foundation-model resources", and its own example uses StringLike. Statement 3 follows that pattern. The condition value (arn:<partition>:bedrock:<region>:${aws:PrincipalAccount}:inference-profile/*) matches the in-region, same-account profile ARN that Bedrock puts in the key.
  • global. profiles. Global cross-Region inference says Bedrock checks the profile, the source-region model, and the region-less arn:aws:bedrock:::foundation-model/<model>. It also says "bedrock:InferenceProfileArn ... is populated for the foundation model resource evaluations, but not for the inference profile resource evaluation". That fits the split here: no profile condition on statement 1, and the profile condition on statement 3. The * region in statement 3 matches the empty region, because a * in a Resource ARN matches zero or more characters (IAM Resource element).
  • StringLike vs ArnLike. The docs' own examples use StringLike for this key. Because the value has a fixed partition, region, and account prefix, StringLike is no wider than ArnLike here. I didn't reproduce the "legacy parsing" failure you saw with ArnLike, so I'm relying on your deploy log for that.
  • Application inference profiles are still not covered, as you noted. inference-profile/* never matched application-inference-profile/*, so this isn't a regression.

Region plumbing / silent failures

  • defaultTargetsWriter now takes the region for the Bedrock file from networks[0].region, the same source that addBoxGatewayTargets and boxMemoryPolicy already use (#2851). BoxNetwork.region is a required string, so region === undefined only happens when there are no networks. In that case no Box runtime is being built and nothing needs the file. This matches the Memory handling.
  • Per-runtime networks (#2866): the comment "Every network of one build has the region build builds for" holds, since every network takes project.region. One build therefore can't need two Bedrock regions.
  • A user-edited bedrock target, or one in another region, now gets an IAM warning from boxGatewayIamWarnings, which checks the host with boxGatewayBedrockHost(network.region). That's the right fallback: a loud warning, not a silent wildcard. The new network.test.ts case covers it.
  • The route region (${{ inputs.aws.region }} / writesBedrockRoute) is unchanged, and it is the same build region.

Tests

The new tests check each statement exactly (Sid, Resource, Condition), the aws-cn and aws-us-gov partitions, the writer's region, the deploy-time move from us-west-2 to eu-west-1 in manager.boxNetwork.test.ts, and the cross-region warning. The mutation table in the PR body is convincing. I found no unsafe test patterns: no hard-coded / paths, no splitting of paths or env on :, no shell or network calls.

Non-blocking

  1. Partition is now inconsistent with the Memory file. boxBedrockPolicy gets its partition from the region, but boxMemoryPolicy still hard-codes arn:aws:bedrock-agentcore:. Consider making Memory match in a follow-up (inline comment).
  2. aws-cn endpoint. boxGatewayBedrockHost (and the existing target endpoint) builds bedrock-runtime.<region>.amazonaws.com. In cn-* the endpoint is amazonaws.com.cn, so the partition-aware ARNs don't yet give a working China path from start to finish. This predates the PR (inline comment).
  3. No test for the no-region branch in defaultTargetsWriter (no networks, so no Bedrock file). It's trivial and matches Memory, so this is optional.
  4. Back-merge needed. box-integration-development (435b6ba1) still has the old BoxedAgentModelCallsThroughGateway policy on arn:aws:bedrock:*:*:inference-profile/* and arn:aws:bedrock:*::foundation-model/*. This looks like a security fix outside the squash plan, so please port it to dev too. In dev, boxBedrockPolicy takes (spec, projectRoot), so the port won't be a clean cherry-pick.

CI

At review time, Linux, Windows, CodeQL/Analyze, and CodeBuild e2e pass. verify / macOS is still pending. Please confirm it goes green before merge.

Comment thread src/core/project/boxMemory.ts Resolved
Comment thread src/handlers/project/shortcuts.ts Resolved
Sai Abhishek added 2 commits November 20, 2026 16:14
…he Box gateway

The comment of leo237 on boxMemory.ts: boxMemoryPolicy wrote
"arn:aws:bedrock-agentcore:<region>" for each region. Thus `build` for
cn-north-1 or us-gov-west-1 wrote a Bedrock policy with the correct
partition, and a Memory policy with an incorrect partition.

boxMemoryPolicy gets the partition from the region, with the
partition data of the AWS SDK, the same as boxBedrockPolicy.

Test: boxMemory.test.ts, "boxMemoryPolicy" > "names the partition of
the region it is given", for cn-north-1 (aws-cn) and us-gov-west-1
(aws-us-gov). Before this change, the result of this test is
incorrect.
The comment of leo237 on shortcuts.ts: boxGatewayBedrockHost wrote
"bedrock-runtime.<region>.amazonaws.com" for each region, and
boxGatewayAgentCoreHost wrote "bedrock-agentcore.<region>.amazonaws.com".
In the aws-cn partition, the DNS suffix is "amazonaws.com.cn". Thus,
for `build` in cn-north-1, the `bedrock` and `agentcore` targets had an
incorrect endpoint. Also, boxGatewayIamWarnings compared a target host
with an incorrect host, and gave a warning for a correct China host.
This problem was on box-integration before this PR.

The 2 functions get the DNS suffix from the partition data of the
AWS SDK, as boxBedrockPolicy gets the partition.

Tests. Before this change, the result of each test is incorrect:

- shortcuts.test.ts, "Box gateway targets" > "take the DNS suffix of
  the partition of the region": cn-north-1 gives amazonaws.com.cn,
  us-gov-west-1 and us-west-2 give amazonaws.com.
- network.test.ts, "the Bedrock and Memory files grant the
  amazonaws.com.cn hosts of a build for China": no warning.

A constant "amazonaws.com" in each of the 2 functions gives an
incorrect result in the 2 tests.
@SaiAbhishek98
SaiAbhishek98 requested a review from leo237 November 21, 2026 00:19

@leo237 leo237 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 0b0b2b3. I looked at 555f19c6..0b0b2b31. Still approved.

Both earlier comments are fixed:

  • 0d8c8d3: boxMemoryPolicy now builds the ARN with partition(region).name, so it uses the same partition as the Bedrock grant. The new test checks aws-cn and aws-us-gov.
  • 0b0b2b3: boxGatewayBedrockHost and boxGatewayAgentCoreHost now use partition(region).dnsSuffix. Both the target endpoints and the host match in boxGatewayIamWarnings go through these two helpers, so the warning check stays in step with the endpoints. The tests cover cn-north-1 (.amazonaws.com.cn), us-gov-west-1 and us-west-2, plus a China network-warnings case. The egress.ts endpoint patterns already accept (?:\.cn)?.

The new code reuses @aws-sdk/util-endpoints partition(), the same call as src/core/partition.ts and boxTelemetry.ts, rather than adding a new table. An unknown region falls back to aws/amazonaws.com, which is fine. No other Box gateway host still hard-codes amazonaws.com. The two left in src/core/project (templates/export.ts and migrate/templateStore.ts) are outside this PR.

Non-blocking:

  • In the ISO partitions (c2s.ic.gov, sc2s.sgov.gov), the SDK gives the right suffix, but the egress.ts patterns only match amazonaws.com(.cn). Those hosts would not be classified as AWS endpoints. AgentCore isn't offered there today, so this is just for later.
  • #2886 copies the Bedrock scoping into boxMemory.ts but still has the arn:aws: and amazonaws.com versions, so the partition handling here makes the gap with #2886 bigger. That is one more reason to land this PR and drop #2886's copy.
  • Still open from before: there is no test for the no-region branch, and this needs a back-merge to box-integration-development.

The Bedrock route signing, ${{ inputs.aws.region }}, the xray grants and the #2851 Memory scoping are untouched by the new commits.

Merge state: the branch is 2 commits behind box-integration (#2884, which doesn't touch these files) and merges cleanly. At posting, CodeQL, Analyze and CodeBuild e2e pass, and verify / Linux|Windows|macOS are still pending. Please merge only after the verify checks pass.

@SaiAbhishek98
SaiAbhishek98 merged commit 57c7c52 into aws:box-integration Nov 21, 2026
7 checks passed
mquang-amazon added a commit that referenced this pull request Nov 21, 2026
…uild region"

This reverts commit 6072b2c. #2883 makes the same change and more (the
region's partition, and the account in the inference-profile condition), and
the two conflict, so the grant lands with #2883.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants