Repository navigation
fix(vm): drop link-local metadata in the sandbox forward path - #539
Conversation
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]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
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.mdgives 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)
| **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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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".
| # 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
|
All three points addressed in 0a372d7, plus the CI rerun:
|
What
Closes #357.
install_sandbox_firewall'smoca_sandboxtable filtered only the input hook — traffic addressed to the host itself. Metadata traffic is forwarded through the host, so a sandbox could reach169.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:
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.serviceandpodman-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 onmoca-sandbox: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;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;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.mdalongside the 2026-09-29 verification, and resolves the deferral recorded indocs/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