8000 nstun: block the Azure, Alibaba, and GCE metadata-service addresses by matepad007 · Pull Request #416 · google/nsjail · GitHub
[go: up one dir, main page]

Skip to content

nstun: block the Azure, Alibaba, and GCE metadata-service addresses - #416

Open
matepad007 wants to merge 1 commit into
google:masterfrom
matepad007:egress-gate-cloud-metadata
Open

matepad007 wants to merge 1 commit into
google:masterfrom
matepad007:egress-gate-cloud-metadata

Conversation

@matepad007
Copy link
Copy Markdown
Contributor

Summary

The SSRF gate in both IP families blocks loopback, link-local, multicast, and broadcast destinations, plus one cloud provider's instance-local service range: AWS's fd00:ec2::/32 (ip6_is_aws_local_service), added in #282. The other three major cloud providers' metadata-service addresses are not covered by any existing check:

  • Azure WireServer (168.63.129.16, IPv4) — the VM agent's health/goalstate endpoint.
  • Alibaba Cloud ECS metadata (100.100.100.200, IPv4) — the ECS instance metadata service, documented at help.aliyun.com.
  • GCE metadata server for IPv6-only instances (fd20:ce::254, IPv6) — per Google's own Compute Engine docs. This is a unique-local address (fc00::/7), not a link-local or deprecated site-local address, so it isn't caught by IN6_IS_ADDR_LINKLOCAL/IN6_IS_ADDR_SITELOCAL the way fe80::/10 or fec0::/10 addresses are — the same reason AWS's fd00:ec2::/32 needed its own explicit check rather than falling under the generic ULA/site-local tests.

None of the three addresses fall into a standard loopback, link-local, or multicast range, so a jailed process able to reach the host's network path for one of these providers could otherwise reach its metadata service unimpeded, the same SSRF/credential-theft shape AWS's IMDS has.

Change

Adds ip4_is_azure_local_service, ip4_is_alibaba_local_service, and ip6_is_gce_local_service to nstun/net_defs.h, matching ip6_is_aws_local_service's existing style (exact-address/prefix match, no new types). Wires all three into the two SSRF gates in nstun/ip.cc alongside the existing checks.

Test

Extended tests/nstun_ip_test.cc with boundary assertions for each new check, following the exact pattern already used for the AWS case (exact match, off-by-one neighbors, and a same-prefix-different-service negative case for the GCE /128 check).

Validation

Unlike the mount-related PRs from this account, this one only touches POSIX networking code with no Linux-only syscalls, so it was fully compiled and run, not just traced:

  • g++ -std=c++20 -I. tests/nstun_ip_test.cc nstun/ip.cc -o nstun_ip_test && ./nstun_ip_test → exit 0, all assertions (including the pre-existing ones) pass.
  • Confirmed red/green: with net_defs.h/ip.cc reverted and only the test file changes kept, the test fails to even compile (the new functions don't exist) — confirming the new assertions are actually exercising the new code, not passing vacuously.
  • Independently recomputed the IPv4 constants (168.63.129.16 → 0xA83F8110, 100.100.100.200 → 0x646464C8) rather than trusting a transcription.

This branch has not been deployed

No deployments
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.

1 participant

0