Skip to content

fix(vm): drop link-local metadata in the sandbox forward path - #539

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:fix/357-metadata-forward-drop
Oct 15, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:fix/357-metadata-forward-drop

Conversation

@pdettori

Copy link
Copy Markdown
Member

What

Closes #357.

install_sandbox_firewall's moca_sandbox table filtered only the input hook — traffic addressed to the host itself. Metadata traffic is forwarded through the host, so a sandbox could reach 169.254.169.254; on an EC2 host with IMDSv1, or IMDSv2 with a hop limit of 2 or more, model code in a sandbox could read the instance role's credentials. Those belong to the host, not to any session or user.

This adds a forward chain that drops exactly the link-local destinations arriving from the sandbox bridge:

chain forward {
  type filter hook forward priority filter; policy accept;
  iifname "$MOCA_SANDBOX_BRIDGE" ip daddr 169.254.0.0/16 counter drop
  iifname "$MOCA_SANDBOX_BRIDGE" ip6 daddr fd00:ec2::254 counter drop
}

and nothing else — general internet egress stays untouched until MI1 S5's moca-egress (#277). setup-vm.test.sh's "no forward hook" assertion becomes "the forward hook exists, drops both link-local metadata destinations, and contains no other rule".

Live verification (the reason this was not in #350)

The table is loaded by a oneshot unit RequiredBy= sh-relay.service and podman-restart.service — a table that fails to parse keeps every sandbox down. Verified live on 2026-10-14 on the same Amazon Linux 2023 host (rootful static podman 5.8.7, netavark 1.17.2, nftables 1.0.4) as #350's run, from a container on moca-sandbox:

  • the candidate table parses and loads cleanly on nftables 1.0.4;
  • before (input-only table): http://169.254.169.254/latest/meta-data/ answered HTTP 401 in 0.4 ms — IMDSv2 wanted a token, but the request had reached the service through the forward path;
  • after (forward chain loaded): the same request times out after 5 s, with the drop rule's counter incrementing (5 packets / 300 bytes);
  • outbound internet (https://example.com → 200), the relay's attach port (TCP connect to the gateway on 9443), and the input chain's other drops (host port 22) are all unchanged;
  • the IPv6 rule (fd00:ec2::254) is not exercised on that host — the container has no IPv6 route to it; it covers hosts where the IPv6 metadata endpoint is routable.

The run is recorded in deploy/vm/README.md alongside the 2026-09-29 verification, and resolves the deferral recorded in docs/specs/2026-09-28-moca-multi-user-isolation-design.md §13.

The README's platform-side guidance (IMDSv2 with hop limit 1) stays, as defense in depth.

🤖 Generated with Claude Code

The moca_sandbox table filtered only the input hook, so a sandbox could
reach cloud instance metadata (169.254.169.254) through the forwarded
path; on an EC2 host with IMDSv1, or IMDSv2 with hop limit >= 2, that
exposes the instance role's credentials, which belong to the host and
not to any session or user.

Add a forward chain that drops exactly the link-local destinations
arriving from the sandbox bridge -- 169.254.0.0/16 and the IPv6 metadata
address fd00:ec2::254 -- and nothing else: general internet egress stays
untouched until MI1 S5's moca-egress. setup-vm.test.sh's 'no forward
hook' assertion becomes 'the forward hook drops only link-local
metadata'.

Verified live (2026-10-14) on the same Amazon Linux 2023 host as rossoctl#350's
run, recorded in deploy/vm/README.md: the candidate table parses and
loads on nftables 1.0.4 (the fail-closed risk that kept this out of
rossoctl#350); with the chain loaded, the metadata endpoint that answered HTTP
401 from inside a sandbox now times out with the drop counter
incrementing, while outbound internet, the relay's attach port, and the
input chain's other drops are unchanged.

Closes rossoctl#357.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori requested a review from cwiklik as a code owner October 15, 2026 02:57
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 15, 2026

@ingpaolodettori-dev ingpaolodettori-dev 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.

Small, well-scoped fix for #357. It adds a forward chain to inet moca_sandbox that drops only 169.254.0.0/16 and fd00:ec2::254 arriving on $MOCA_SANDBOX_BRIDGE, with policy accept, so general egress stays S5's job. The test pins both rules and checks that the chain holds nothing else. A drop in our own base chain is final no matter what netavark's tables accept. DNS goes through aardvark on the gateway (the input hook, port 53), so it isn't affected even on hosts whose upstream resolver is link-local (e.g. GCE). The live verification recorded in the README covers the fail-closed parse risk that kept this out of #350.

Suggestions (non-blocking):

  • docs/specs/2026-09-28-moca-multi-user-isolation-design.md §13 (around line 834) still lists "Blocking cloud instance metadata from sandboxes" as deferred: "R8 filters only the input hook… S5's egress filtering closes it. Until then, deploy/vm/README.md gives the platform-side mitigation". The PR body says this resolves that deferral, but the spec isn't in the diff. Please update or strike that bullet so the spec and README don't contradict each other.
  • The README now says a sandbox "cannot reach a metadata service". See the inline comment for clouds whose metadata isn't link-local.

CI: the check job's Test step is red. This PR changes only deploy/vm/ shell and docs. deploy-scripts, which runs setup-vm.test.sh, passed, and check passed on the base commit 70321d1. That points to an unrelated flake, but please re-run check and confirm it's green before merging.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: Shell (nftables table, test), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: failing (check › Test, likely unrelated; all others pass)

Comment thread deploy/vm/README.md Outdated
**Cloud instance metadata is blocked in-product** (closed rossoctl/moca#357). The `moca_sandbox`
table's forward chain drops link-local destinations — `169.254.0.0/16`, which carries
`169.254.169.254`, and the IPv6 metadata address `fd00:ec2::254` — arriving from the sandbox
bridge, so a sandbox cannot reach a metadata service even though general forwarded traffic stays

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — "a sandbox cannot reach a metadata service" is broader than what the chain drops. It covers metadata served from link-local addresses (AWS/GCP/Azure IMDS/OCI at 169.254.169.254, plus AWS's IPv6 fd00:ec2::254). Some clouds serve instance data from routable addresses that this chain leaves open: Alibaba Cloud ECS metadata at 100.100.100.200, and Azure's WireServer at 168.63.129.16. Either name the clouds or addresses this covers ("link-local metadata endpoints such as 169.254.169.254"), or add those two destinations to the forward chain. If you add them, the test's "exactly two rules" count changes too. Either way, the platform-side hardening paragraph that follows still matters on those clouds.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Took the naming option: the README now says a sandbox cannot reach "the link-local metadata endpoints that AWS, GCP, Azure and OCI serve", and names the gap explicitly — Alibaba's 100.100.100.200 and Azure's WireServer 168.63.129.16 stay reachable until S5's egress allowlist. I did not add those two to the chain: they are routable, cloud-specific addresses, and dropping them on every host (including non-Alibaba/Azure ones) is destination filtering that belongs to S5's allowlist model, not to a link-local drop. The setup-vm.sh comment and MI1 §13 (see the other thread) carry the same scoping. Platform hardening is now framed as "defense in depth where the table already covers the endpoint, the only barrier where it does not".

Comment thread deploy/vm/setup-vm.sh Outdated
# a sandbox takes to cloud instance metadata, which on a cloud VM can hand out the instance role's
# credentials -- they belong to the host, not to any session (rossoctl/moca#357). General
# forwarded (internet) traffic is still untouched; MI1 S5 routes it through moca-egress. The
# declare/delete/redeclare idiom makes

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — the rewrap leaves a short line (# declare/delete/redeclare idiom makes) inside an otherwise ~100-col comment block. Reflow the rest of the paragraph so it reads evenly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reflowed the whole paragraph in 0a372d7 — no short lines left, and the comment now carries the same link-local scoping as the README (routable-address metadata stays for S5).

Review feedback on rossoctl#539: 'a sandbox cannot reach a metadata service'
was broader than what the forward chain drops. The chain covers the
link-local endpoints AWS, GCP, Azure and OCI serve (169.254.169.254,
fd00:ec2::254); clouds serving instance data from routable addresses --
Alibaba's 100.100.100.200, Azure's WireServer 168.63.129.16 -- stay
open until S5's egress allowlist. Name the covered clouds and the gap in
the README, the setup-vm.sh comment, and MI1 §13, whose 'deferred' bullet
now records the in-product close (rossoctl#539) instead of contradicting the
README. Also reflow the comment paragraph the forward-chain edit had
left with one short line.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori

Copy link
Copy Markdown
Member Author

All three points addressed in 0a372d7, plus the CI rerun:

  • MI1 §13 now records the close instead of deferring: the bullet says "Closed in-product 2026-10-15 (fix(vm): drop link-local metadata in the sandbox forward path #539)" with the forward chain, and keeps the routable-address remainder (Alibaba 100.100.100.200, Azure WireServer 168.63.129.16) attributed to S5 — so spec and README no longer contradict each other.
  • README claim scoped to the link-local endpoints AWS, GCP, Azure and OCI serve, with the routable-address gap named and left to S5's egress allowlist (reasoning in the thread: a link-local drop shouldn't filter cloud-specific routable destinations on every host). The setup-vm.sh comment carries the same scoping.
  • Comment paragraph reflowed.
  • check: the failure was harness/test/turn-registry.test.ts — expected 601 to be less than 600, a 1 ms overshoot of a timing bound in a package this PR does not touch. On 0a372d7 the full matrix is green, check included: https://github.com/rossoctl/moca/actions — flake confirmed, not related.

@pdettori
pdettori merged commit 38efc66 into rossoctl:main Oct 15, 2026
14 checks passed
@pdettori
pdettori deleted the fix/357-metadata-forward-drop branch October 15, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deploy/vm: sandboxes can reach cloud instance metadata (169.254.169.254)

2 participants