Skip to content

feat(egress-proxy): members fetch spawn's own bootstrap downloads through the proxy (#1515 phase 4) - #1523

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/1515-members-use-proxy
Nov 3, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/1515-members-use-proxy

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Refs #1515 (phase 4 of the build plan: members fetch through the proxy).

What this does

With --bootstrap-egress proxy (so LaunchConfig.EgressProxyAddr is set by ensureEgressProxy), a member sets http_proxy/https_proxy/no_proxy only for spawn's own fetches from outside AWS. Nothing is exported, nothing goes to /etc/environment or profile.d, and --command, --mpi-command and --user-data never see the variables.

fetch how it's proxied where
EFA installer download (curl, mirror then origin) spawn_px curl ...: the variables prefix that one command. no_proxy names S3, so curl fetches the regional mirror directly and only efa-installer.amazonaws.com goes through the proxy MPI fragment
./efa_installer.sh (its own dnf on AL2023, apt-get on Ubuntu) spawn_px ./efa_installer.sh -y -g. AL2023's repos are S3 buckets, which no_proxy sends direct MPI fragment
spawn's Ubuntu apt-get update / install (the MPI apt path and the pre-EFA refresh from #1491) -o Acquire::http::Proxy=http://<addr>/ -o Acquire::https::Proxy=http://<addr>/ MPI fragment
AWS CLI zip (stock Ubuntu) SPAWN_PX_REGION=<r>; http_proxy=… https_proxy=… no_proxy=… spawn_need_aws "$SPAWN_PX_REGION" || true, before the body. The mirror is still tried first, directly; only the awscli.amazonaws.com fallback goes through the proxy. The body's own spawn_need_aws then finds the CLI installed and returns per-launch part of the bootstrap
spawn's AL2023 dnf/yum (Open MPI, acpid), every AWS API call not proxied —

spawn_px() { http_proxy=… https_proxy=… no_proxy=… "$@"; }: in bash, assignments that prefix a command reach only that command's environment, so they are gone when it returns. The function isn't exported, so mpirun and ssh never see it.

no_proxy, derived in code (pkg/aws.EgressProxyNoProxy)

169.254.169.254, localhost, 127.0.0.1, .s3.amazonaws.com, .s3.<r>.amazonaws.com, .s3.dualstack.<r>.amazonaws.com, s3.<r>.amazonaws.com, plus <svc>.<r>.amazonaws.com for every other privateServices endpoint: ec2, ssm, ssmmessages, ec2messages, dynamodb, fsx, sqs, xray.

  • No blanket .amazonaws.com, because efa-installer and awscli must reach the proxy.
  • No STS: neither the bootstrap nor spored calls it (the iamcoverage gate has no sts).
  • AL2023 repos, verified from the package itself. I installed amazon-linux-repo-s3-2023.12.20261021 in an amazonlinux:2023 container. Its mirrorlist is https://al2023-repos-$awsregion-de612dc2.s3$dualstack.$awsregion.$awsdomain/..., with /etc/dnf/vars/dualstack = .dualstack. Both the dualstack and the plain form are covered. The container image itself ships -repo-cdn (cdn.amazonlinux.com), which no EC2 member uses.
  • pkg/egressproxy.NoProxyBypasses mirrors curl's rule from lib/noproxy.c (7.86+): comma/space separated, one leading and one trailing dot ignored, an exact match or a match on a .-bounded suffix, IP/CIDR matching only for IP hosts, and *. TestEgressProxyNoProxySparesTheAllowlist checks three regions: every egressproxy.Allowlist host goes to the proxy, and every S3, AL2023-repo and endpoint host bypasses it.

Member SG egress preflight

deploy.CheckMemberEgress runs right after MemberGroups, before any member exists. It refuses unless at least one of the member's groups has egress (all traffic, or a TCP range containing 3128) to:

  • the clients SG;
  • the proxy SG;
  • or an IPv4 CIDR containing the proxy IP (0.0.0.0/0 included).

Prefix-list destinations aren't counted. The refusal names every group (sg-… (name)), and never blames the clients group, which has no rules by design.

  • spawn's own groups pass. Nothing in spawn revokes egress except the proxy's own groups (grep RevokeSecurityGroupEgress). The MPI, Windows, --efa-group and VPC default groups keep EC2's allow-all egress, and ensureMPIClusterRules only adds a self rule.
  • IAM: the read is ec2:DescribeSecurityGroups, already in the launch IAM. make cli-iam-actions produced no diff.
  • Ordering: the check runs after find-or-create, so a refused launch may leave a proxy behind. That proxy is shared, reused by the next launch, and idle-expires.

Readiness

Unchanged. #1518's ordering still holds: ensureEgressProxy (now with the egress check) runs before buildUserData and before any RunInstances. Every member is cloned from that config.

The signed bootstrap body: unchanged

BootstrapBody() hashes the same as main (73d1876b…c049). The AWS CLI proxying lives in the per-launch part (perLaunchPreBody). On the stub path, the user data also carries the spawn_need_aws definition when a proxy is set (about 1 KB raw, ~0.5 KB gzipped), as the staged-files path already does.

Why there and not in the body:

  • The body is published and signed once per release, and must carry no per-launch text.
  • Keeping it unchanged keeps every non-proxy launch byte-identical, with no republish needed.
  • The call runs before the body, so the body's own spawn_need_aws "$REGION" returns at once.

Without the opt-in: byte-identical

  • A scratch program rendered GenerateMPIUserData (EFA rank 0 and peer, plain, --skip-mpi-install, a no-mirror region) and BuildLinuxBootstrap (stub, inline) on origin/main and on this branch. All sha256s are identical.
  • TestNoEgressProxyRendersUnchanged (MPI) and TestEgressProxyLeavesTheBodyAndAPlainLaunchUnchanged (bootstrap) assert this structurally: removing exactly the proxy insertions from a proxied render gives the plain render byte for byte, and the plain render names no proxy at all.

Tests

Sandbox (pkg/userdata/mpi_egress_proxy_test.go). The stand-in curl, apt-get, yum and efa_installer.sh now log the proxy variables they ran with. The cases run on AL2023 (yum base), Ubuntu (apt base) and the ubuntu:24.04 container, and assert:

  • curl fetched the mirror directly and the origin through the proxy, judged by curl's rule;
  • efa_installer.sh saw http(s)_proxy and exactly the derived no_proxy, which bypasses the AL2023 repo hosts and proxies the Ubuntu mirrors;
  • every spawn apt-get carried the Acquire options;
  • yum got no proxy env;
  • the --mpi-command, on all 3 ranks, saw no *_proxy variable;
  • no /etc/environment or profile.d file names the proxy.

Other tests:

  • Bootstrap (pkg/launcher/bootstrap_egress_proxy_test.go): full boot with a recording curl wrapper. Mirror missing: the mirror is fetched direct, then the origin through the proxy. Mirror present: one fetch, direct. The IMDS curls, --command and --user-data see no proxy env. On the stub path, spawn_need_aws is defined before the call, and the call comes before the staged fetch and the body.
  • CLI: TestMemberUserDataCarriesTheProxy checks the bootstrap and the MPI script through buildUserData and buildJobArrayMemberConfig, with and without an address. TestEnsureEgressProxyChecksMemberEgress and TestLaunchRefusesMemberGroupsThatCannotReachTheProxy check that the refusal comes before RunInstances (with withLogDir).
  • Other: TestCheckMemberEgress, TestNoProxyBypasses, TestEgressProxyEnv and TestEgressProxyAddrIsValidated. The address must be IP:port and the region a plain region name, since both are rendered unquoted. The shellcheck matrix adds two proxy configs.

Revert evidence

Each key decision was reverted with a change that compiles. The named tests failed in 20 of 20:

reverted decision failing tests
EFA curl not proxied TestEFAThroughTheEgressProxy
installer not proxied TestEFAThroughTheEgressProxy
pre-EFA apt-get update without Acquire options TestEFAThroughTheEgressProxy
MPI apt install without Acquire options TestMPIAptThroughTheEgressProxy
proxy env exported globally TestEFAThroughTheEgressProxy (the --mpi-command saw no_proxy on all 3 ranks)
spawn's yum proxied TestMPIYumIsNotProxied
proxy text rendered without a proxy TestNoEgressProxyRendersUnchanged
blanket .amazonaws.com in no_proxy TestEgressProxyNoProxySparesTheAllowlist, TestEFAThroughTheEgressProxy
dual-stack S3 dropped TestEgressProxyNoProxySparesTheAllowlist, TestEFAThroughTheEgressProxy
VPC endpoints dropped TestEgressProxyNoProxySparesTheAllowlist
matcher: plain suffix (no . boundary) TestNoProxyBypasses
address not validated TestEgressProxyEnv, TestEgressProxyAddrIsValidated
bootstrap AWS CLI install not proxied TestAWSCLIOriginThroughTheEgressProxy, TestEgressProxyLeavesTheBodyAndAPlainLaunchUnchanged
stub path without the spawn_need_aws definition TestEgressProxyLeavesTheBodyAndAPlainLaunchUnchanged
CLI bootstrap / MPI script not given the proxy TestMemberUserDataCarriesTheProxy (each)
member egress check not called TestEnsureEgressProxyChecksMemberEgress, TestLaunchRefusesMemberGroupsThatCannotReachTheProxy
egress check: any group / any port / any CIDR counts TestCheckMemberEgress (each)

Checks

  • make check passes.
  • The hermetic go test ./... passes (AWS env stripped, /dev/null config).
  • semgrep scan --config=auto --error . is clean.
  • make api-snapshot and make gen-docs were regenerated. The --bootstrap-egress help now says what is proxied and that member groups need egress to tcp 3128, with no backticks.
  • CHANGELOG has entries under [Unreleased]: a new Added entry, and the phase 3 entry's "Members do not route anything through it yet" sentence is updated.

Not run against AWS

Nothing here touched AWS. The owner runs the live test: AL2023 and Ubuntu 24.04 --mpi --efa in a no-NAT VPC.

…ough the proxy (#1515 phase 4)

With --bootstrap-egress proxy, the EFA installer download and run, spawn's
own apt-get, and the AWS CLI zip's origin fallback go through the egress
proxy, each command by itself; the S3 mirrors, AL2023's S3 repos and every
AWS endpoint bypass it through a no_proxy derived in code. The user's
--command and --mpi-command never see the variables. Members whose own
security groups allow no egress to tcp 3128 on the proxy are refused before
any is created. Without a proxy address the user data is byte-identical,
and the published bootstrap body is unchanged.

Refs #1515
@scttfrdmn scttfrdmn added this to the v0.158.0 milestone Nov 3, 2026
@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.91525% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/egressproxy/deploy/groups.go 87.09% 4 Missing ⚠️
pkg/egressproxy/noproxy.go 90.90% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live end-to-end test: PASS (aws account, us-east-1, CLI built from 4f4ec4cb, spored v0.157.0)

Setup: a no-NAT VPC with a public subnet (IGW) and a private subnet with no default route. Gateway endpoints for s3 and dynamodb; interface endpoints for ec2, ssm, ssmmessages and ec2messages. Each run was a 2-node --mpi --efa --no-public-ip --bootstrap-egress proxy cohort on c6gn.16xlarge Spot.

AL2023: PASS

  • Proxy: created in 141.6 s.
  • Cohort: reconciled in 212 s, and spored was verified on 2 of 2 nodes.
  • Job: SPAWN_COMPLETE = {"status": "completed", "exit_code": 0, "source": "mpi"}, and the ranks used /opt/amazon/openmpi/bin/mpirun.
  • EFA download and install:
    • Installing EFA installer 1.51.0...
    • the mirror returned curl: (22) … 403, so the origin was fetched through the proxy;
    • EFA installation complete., then Open MPI 4 was installed in /opt/amazon/openmpi.
    • fi_info -p efa shows efa-direct.
  • No leakage: the --mpi-command printed proxyvars=0, and /etc/environment and /etc/profile.d/* have no proxy settings.
  • Proxy log: 2 × CONNECT efa-installer.amazonaws.com:443 (one per member) and 1 × CONNECT awscli.amazonaws.com:443 (the readiness probe). There were no S3 or al2023-repos hosts, so dnf went direct through the S3 gateway endpoint and no_proxy is right.

Ubuntu 24.04 arm64 (ami-09a93d801db0bafae): PASS

  • Proxy: reused (reusing i-016251846d7b624f2, 4.3 s).
  • Cohort: reconciled in 245.7 s, and spored was verified on 2 of 2 nodes.
  • Job: SPAWN_COMPLETE = completed / mpi / 0. All 128 ranks used /opt/amazon/openmpi/bin/mpirun, and all 128 printed proxyvars=0.
  • apt and the EFA installer:
  • AWS CLI: /usr/local/bin/aws is aws-cli/2.39.3.
  • No leakage: no proxy settings in /etc/environment, profile.d or apt.conf.d.
  • Proxy log after both runs:
    • 4 × CONNECT efa-installer.amazonaws.com:443 and 2 × CONNECT awscli.amazonaws.com:443;
    • 246 × GET us-east-1.ec2.ports.ubuntu.com:80 and 34 × GET ports.ubuntu.com:80;
    • everything was allowed, with no refusals and no S3 hosts.

Member SG egress check

A member with --security-group-ids <sg allowing egress on 443 only> was not refused, and that is correct. With --mpi the members also carry spawn-mpi-<name>, whose allow-all egress reaches 3128, and SG egress is the union of all groups. Today the only internet need is --mpi --efa, which always gets that group, so the refusal can't trigger live. It guards future non-MPI needs and is covered by member_egress_test.go.

Teardown

  • All 5 instances (proxy plus 4 members) are terminated.
  • The endpoints, 7 SGs, subnets, route tables, IGW, VPC and the spawn-mpi-lp* placement groups are deleted.
  • Leak diff: compared against a pre-run baseline, there are no open Spot requests and no EIPs. The only new instance and SG are the owner's kempner-demand-traces collector, which isn't mine.

@scttfrdmn
scttfrdmn merged commit 5e153b9 into main Nov 3, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the feat/1515-members-use-proxy branch November 3, 2026 23:21
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