Skip to content

feat(box): Forbid the AWS instance metadata service in every box profile - #2899

Merged
leo237 merged 1 commit into
box-integrationfrom
feat/box-imds-forbid
Nov 24, 2026
Merged

leo237 merged 1 commit into
box-integrationfrom
feat/box-imds-forbid

Conversation

@leo237

@leo237 leo237 commented Nov 23, 2026

Copy link
Copy Markdown

Description

Box adds no cloud metadata rule to a box profile. Box main asserts this: crates/cli/app/src/profile_tests.rs checks that metadata_hosts and metadata_addresses are absent, and docs/user/security.md tells the operator to write the forbids. So far a boxed agent was kept away from the AWS instance metadata service only because nothing permitted it. A route or a rule the user added could open it. On AgentCore Runtime, MMDS at 169.254.169.254 serves the execution role's credentials.

This PR makes every box project include an AWS metadata block:

  • agentcore create and agentcore add runtime write .box/<agent>/local/aws-metadata-block.dw beside the box profile, and renderBoxProfile lists it under policies. The file has two forbids on net:connect:
    • aws_metadata_addresses: ip4 == "169.254.169.254" or ip6 == "fd00:ec2::254". Each family has its own has guard, as docs/user/policy.md in Box requires.
    • aws_metadata_hosts: 169.254.169.254, instance-data and instance-data.ec2.internal, before DNS resolution.
  • Build already copies each policies file into .box-dist/, so no deploy-path change was needed. The rules hold on AgentCore Runtime for both CodeZip (start.py) and container (the Dockerfile copies .box-dist/ whole), and in the container dev image (boxPolicyFileCopies).
  • The file has its own name, so policy.dw, the name Box uses for the policy a user edits, stays free. A user adds rules in another file beside the profile and appends it to policies. The profile comment and the file header both say so.
  • The policy file is written before the profile, so a failed write can't leave a profile that names a missing file, which Box would refuse. The CLI owns this file, so it replaces any file already there. A profile that already exists is still left alone, and then neither file is written.
  • Host map: the address forbid could match any host before DNS resolution, so build would warn "the gateway allows every request to this host; Box still applies the rule …" for every host. hostMap.ts now leaves the aws_metadata_* ids (AWS_METADATA_RULE_IDS) out of enforcedByBox, as it already does for metadata_*.
  • Comments that said Box writes metadata rules into every profile (boxProfileResolver-test-support.ts, places.ts) now say it doesn't.

Scope is AWS only, on purpose. Other link-local addresses (169.254.*) and other clouds' metadata services are not forbidden here, and the file header says so.

Not in this PR:

  • Projects created before this change don't get the file. Their profiles have no policies entry, and nothing migrates them.
  • Possible follow-ups, each needing its own review:
    • The first form of the "gateway allows every request…" warning never tells the user anything new for a Box gateway: it's a passthrough with no policy engine.
    • The message "…is one Box adds itself to every profile" in places.ts contradicts Box main.

Related Issue

Closes #

Documentation PR

Not applicable. The shipped profile and policy file explain themselves in comments.

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 (6059 pass, 7 skip, 0 fail)
  • I ran the relevant end-to-end tests with bun run test:e2e, or explained why they are not applicable
    (CI does not run them for you). Not run yet. The unit tests check the rules only with the CLI's own Dogwood parser and host map. Only e2e runs a real box, which would confirm that Box loads and enforces the file.
  • I ran bun run typecheck
  • I ran bun run lint:check
  • I ran bun run format:check
  • I ran bun run audit
  • I ran bun run secrets:check
  • I ran bun run build
  • If I modified src/assets/, I updated affected snapshots with bun test <test-file> --update-snapshots and committed them (not applicable)
  • If I re-recorded fixtures or golden files, every change beyond account identifiers is explained
    by this PR. box-network-build-stopped.golden.txt was re-recorded with RECORD=1 (no AWS calls). Only the line numbers in the profile changed, because the profile now has three more lines: the policies comment and key.
  • This PR does not change command.md (the release workflow regenerates it)

New tests cover:

  • the profile listing the file, for each box template
  • the file holding exactly the AWS_METADATA_RULE_IDS forbids
  • each metadata address and name being denied even when a route permits it
  • api.example.com and 169.254.169.253 staying reachable with no reported limit (this fails without the host-map fix)
  • agentcore create writing the file before the profile
  • add runtime replacing an existing file
  • a failed policy write leaving no profile (this fails if the write order is reversed)
  • a failed agentcore.json write removing .box/<name>
  • an untouched profile building with the file in .box-dist/

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
  • 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.

Box adds no cloud metadata rule to a profile, so a boxed agent was kept from
IMDS only by default deny: a route or rule the user added could open it. On
AgentCore Runtime, MMDS at 169.254.169.254 serves the execution role's
credentials.

agentcore create and add runtime now write .box/<agent>/local/aws-metadata-block.dw
beside the box profile, and the profile lists it under policies. Its two forbids
on net:connect refuse 169.254.169.254, fd00:ec2::254, instance-data and
instance-data.ec2.internal. Build already stages each policies file into
.box-dist/, so the rules hold on the Runtime, CodeZip and container.

The file is written before the profile, so a failed write leaves no profile that
names a missing file, and it replaces a file already there. The host map leaves
the aws_metadata_* rules out of the limits it reports, since an address forbid
could hold for any host before DNS resolution and would warn for every host.

Comments that said Box writes metadata rules into every profile now say it does
not.
@leo237
leo237 requested a review from a team November 23, 2026 23:54

@tejaskash tejaskash left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving. The deny holds in a real run of the pinned box: 169.254.169.254, [fd00:ec2::254], [::ffff:169.254.169.254], the decimal and hex forms, and the instance-data names all get 403 behind a permit-all policy, and the Bedrock, AgentCore and Memory routes still work. Follow-ups:

  1. Old and kept profiles get no block, and build says nothing. The file is written only with a new profile (manager.tsx:2222, templates/boxProfile.ts:590), so projects made before this PR, add runtime on a profile that remove runtime kept, and a profile whose policies line was removed all stay open. With the policies line removed and [egress.imds] destinations = ["169.254.169.254"] added, build writes a gateway target for https://169.254.169.254 with no warning. A build check that warns when a box runtime's resolved policy has no aws_metadata_addresses forbid covers all three. If it is not in this PR, it needs to land before box-integration merges into v1.x.
  2. No test fails when the IPv6 clause or the context.input.host == "169.254.169.254" clause is removed from renderAwsMetadataPolicy. Assert both in the "holds only forbids" test (boxProfile.test.ts:357), and add one box e2e case that requests http://[fd00:ec2::254]/ and http://169.254.169.254/ behind a permit and expects 403.
  3. The container credential endpoints stay reachable: 169.254.170.2 (ECS, CodeBuild), 169.254.170.23 and fd00:ec2::23 (EKS Pod Identity). Add them to aws_metadata_addresses by name rather than widening to 169.254.*, since 169.254.169.253 stays open on purpose.
  4. boxNetwork/hostMap.ts:27 now imports the rule ids from the scaffold template. Put them in boxNetwork/places.ts next to BOX_METADATA_RULE_IDS and let the template import them, so hostMap.ts:624 has one set and one loop.
  5. The test.each at boxProfile.test.ts:338 repeats what the Strands toEqual at line 73 checks, and the write-order check in manager.test.ts:862 repeats the failed-write test in manager.box.test.ts. Both can go.

@vvargu vvargu 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.

One blocking issue: the IPv4-mapped IPv6 address ::ffff:169.254.169.254 gets past both metadata forbids (see the comment on boxProfile.ts). The other two comments are non-blocking.

Comment thread src/core/project/manager.tsx Resolved
@leo237
leo237 merged commit 2de737f into box-integration Nov 24, 2026
4 of 10 checks passed
@leo237
leo237 deleted the feat/box-imds-forbid branch November 24, 2026 04:26
mquang-amazon added a commit that referenced this pull request Nov 24, 2026
Bring in #2899, which forbids the AWS instance metadata service in every
box profile. Both branches changed the old-renderer fixture tests: they
now apply withCreatePolicy and withApiKeySignIn. box-network-build-stopped
is re-recorded: its profile line numbers move by #2899's policy file and
this branch's removal of [tool.uname].
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.

4 participants