Repository navigation
feat(box): Forbid the AWS instance metadata service in every box profile - #2899
Merged
Merged
Conversation
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.
tejaskash
approved these changes
Nov 24, 2026
tejaskash
left a comment
Contributor
There was a problem hiding this comment.
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:
- 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 runtimeon a profile thatremove runtimekept, and a profile whosepoliciesline was removed all stay open. With thepoliciesline removed and[egress.imds] destinations = ["169.254.169.254"]added, build writes a gateway target forhttps://169.254.169.254with no warning. A build check that warns when a box runtime's resolved policy has noaws_metadata_addressesforbid covers all three. If it is not in this PR, it needs to land beforebox-integrationmerges intov1.x. - No test fails when the IPv6 clause or the
context.input.host == "169.254.169.254"clause is removed fromrenderAwsMetadataPolicy. Assert both in the "holds only forbids" test (boxProfile.test.ts:357), and add one box e2e case that requestshttp://[fd00:ec2::254]/andhttp://169.254.169.254/behind a permit and expects 403. - The container credential endpoints stay reachable:
169.254.170.2(ECS, CodeBuild),169.254.170.23andfd00:ec2::23(EKS Pod Identity). Add them toaws_metadata_addressesby name rather than widening to169.254.*, since169.254.169.253stays open on purpose. boxNetwork/hostMap.ts:27now imports the rule ids from the scaffold template. Put them inboxNetwork/places.tsnext toBOX_METADATA_RULE_IDSand let the template import them, sohostMap.ts:624has one set and one loop.- The
test.eachatboxProfile.test.ts:338repeats what the StrandstoEqualat line 73 checks, and the write-order check inmanager.test.ts:862repeats the failed-write test inmanager.box.test.ts. Both can go.
mquang-amazon
approved these changes
Nov 24, 2026
vvargu
reviewed
Nov 24, 2026
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].
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Box adds no cloud metadata rule to a box profile. Box
mainasserts this:crates/cli/app/src/profile_tests.rschecks thatmetadata_hostsandmetadata_addressesare absent, anddocs/user/security.mdtells 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 at169.254.169.254serves the execution role's credentials.This PR makes every box project include an AWS metadata block:
agentcore createandagentcore add runtimewrite.box/<agent>/local/aws-metadata-block.dwbeside the box profile, andrenderBoxProfilelists it underpolicies. The file has two forbids onnet:connect:aws_metadata_addresses:ip4 == "169.254.169.254"orip6 == "fd00:ec2::254". Each family has its ownhasguard, asdocs/user/policy.mdin Box requires.aws_metadata_hosts:169.254.169.254,instance-dataandinstance-data.ec2.internal, before DNS resolution.policiesfile 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).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 topolicies. The profile comment and the file header both say so.hostMap.tsnow leaves theaws_metadata_*ids (AWS_METADATA_RULE_IDS) out ofenforcedByBox, as it already does formetadata_*.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:
policiesentry, and nothing migrates them.places.tscontradicts Boxmain.Related Issue
Closes #
Documentation PR
Not applicable. The shipped profile and policy file explain themselves in comments.
Type of Change
Testing
How have you tested the change?
bun test(6059 pass, 7 skip, 0 fail)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.bun run typecheckbun run lint:checkbun run format:checkbun run auditbun run secrets:checkbun run buildsrc/assets/, I updated affected snapshots withbun test <test-file> --update-snapshotsand committed them (not applicable)by this PR.
box-network-build-stopped.golden.txtwas re-recorded withRECORD=1(no AWS calls). Only the line numbers in the profile changed, because the profile now has three more lines: thepoliciescomment and key.command.md(the release workflow regenerates it)New tests cover:
AWS_METADATA_RULE_IDSforbidsapi.example.comand169.254.169.253staying reachable with no reported limit (this fails without the host-map fix)agentcore createwriting the file before the profileadd runtimereplacing an existing fileagentcore.jsonwrite removing.box/<name>.box-dist/Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.