Skip to content

feat(egress): upgrade plain HTTP to HTTPS for listed hosts - #411

Merged
opieter-aws merged 1 commit into
mainfrom
feature/gateway-http-upgrade
Nov 12, 2026
Merged

opieter-aws merged 1 commit into
mainfrom
feature/gateway-http-upgrade

Conversation

@opieter-aws

Copy link
Copy Markdown
Contributor

Description

Problem

On macOS, rustup checks certificates with the macOS platform verifier. That verifier cannot trust the box's per-run CA (the CA is an environment value, not in the keychain), so rustup toolchain install in a box fails with OSStatus -26276 (#344). Letting rustup skip the gateway would also drop the per-request decision and the credential swap for cargo and everything it starts, because cargo is rustup's proxy.

Measured on macOS and Linux with a test-only gateway patch (rustup with RUSTUP_DIST_SERVER):

Setup Result Gateway judged
https:// (today) macOS: fails, -26276 static.rust-lang.org:443
http://, no upgrade refused static.rust-lang.org:80
http://, upgrade on installed static.rust-lang.org:443

Solution

A new top-level box.toml table, [gateway], with one key:

[gateway]
upgrade_http = ["static.rust-lang.org"]
  • A plain http:// request to port 80 of a listed host is decided and sent as https:// on port 443. Every other plain request is unchanged (unlisted host, or another port of a listed host).
  • Policy decides it exactly as a CONNECT to the host: net:connect (host and each pinned address) and http:request see port 443, and the decision records name port 443. A backend that matches host:443 still re-routes it, as for a CONNECT.
  • The gateway does the TLS upstream with its usual roots (webpki plus any extra upstream CA), SNI = the host, and Host = the bare host.
  • The workload's own leg stays plain, so intercepted stays false and the existing "a secret must ride TLS" refusal still applies: a credential-matched request to an upgraded host is refused with 403.
  • Each entry is checked at load (and again when a stored record is read): a host name only. A scheme, port, path, * wildcard, IP address, or other character is refused with invalid Box configuration: `[gateway] upgrade_http` entry "<entry>" is not a host name: <reason>; ....

Why a new [gateway] table: no gateway-wide table exists today, and [egress.<name>] is a map of route names, so a list key cannot live there. The upgrade acts on the workload's hop before any route matches, so it is box-wide, not per route. Keys inside tables use snake_case (box_dir, contain_egress, phantom_prefix).

Interfaces that move:

  • box.toml: new [gateway] upgrade_http (twelfth key). four_inputs.rs pins the key set; the argument that it is not a fifth input (policy still decides every upgraded request) is in its module doc and in crates/box/AGENTS.md.
  • Stored record: gateway field; a record that sets it is version 32 (UPGRADE_HTTP_RECORD_VERSION), so an older build refuses it.
  • egress_gateway::MitmConfig: new upgrade_http: Vec<String> field (default empty). No new exported name.

Docs: docs/user/egress.md (new "Upgrade plain HTTP to HTTPS" section and error rows), docs/user/config.md (key table row and [gateway] section), docs/user/native-filesystem-policy.md (record version 32), docs/design/egress.md, crates/box/README.md, crates/egress-gateway/README.md, and a decision entry in docs/design/decisions.md (macOS platform verifiers cannot trust the per-run CA; the local hop is plain HTTP on the machine; rustup still checks each package's SHA-256 from its channel manifest).

Related Issues

#344

Type of Change

New feature

Testing

Base: a41332d (origin/main at the time of testing).

  • Unit: connect::tests::only_port_80_of_a_listed_host_is_upgraded_to_443, l7::tests::an_upgraded_plain_request_speaks_tls_to_its_own_host, l7::tests::a_plain_host_header_omits_the_upstream_schemes_default_port, gateway::tests::an_entry_that_is_not_a_host_name_is_refused_with_its_reason, gateway::tests::a_host_name_is_accepted, config::tests::a_gateway_upgrade_entry_that_is_not_a_host_name_is_refused_at_load, config::tests::the_gateway_upgrade_list_parses_and_is_empty_by_default, config::tests::the_gateway_upgrade_list_cannot_hide_in_a_legacy_record.
  • Gateway e2e (interception_e2e.rs): a_listed_plain_request_is_decided_and_dialed_on_443 (listed host decided, resolved and dialed on 443; unlisted host and port 8080 keep their port), a_listed_plain_request_reaches_a_tls_upstream_judged_on_443, a_credential_on_an_upgraded_plain_request_is_refused. With the upgrade disabled in first_request, all three fail.
  • Manual, real box on Linux (curl as the agent, real static.rust-lang.org, policy permits only static.rust-lang.org:443):
Request Result Decisions
http://, upgrade on 200 net:connect and http:request on 443, permit
http://, no upgrade 403 net:connect on 80, no permit matched
https://, upgrade on 200 443, permit
http://…:8080, upgrade on 403 net:connect on 8080, no permit matched

Gates: cargo fmt --all --check; cargo clippy --workspace --all-targets --all-features -- -D warnings with the justfile's allow list; cargo clippy -p strands-box-egress-gateway --all-targets --all-features -- -D warnings; cargo build -p strands-box-egress-gateway --no-default-features; RUSTDOCFLAGS="-D warnings" cargo doc -p strands-box-egress-gateway --all-features --no-deps; cargo test -p strands-box-egress-gateway --all-features (all pass); cargo test -p strands-box --all-features --no-fail-fast (1505 pass). Three box tests failed only under the full parallel run and pass alone: mcp_alias_fallback (Text file busy when run in parallel; passes with --test-threads=1) and runtime_mcp_policy_staging::catalog_page_limit_accepts_256_pages_and_refuses_a_257th (MCP client timeout under load). This change touches neither.

  • I ran the relevant suites (cargo test -p strands-box-egress-gateway --all-features, cargo test -p strands-box --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Not covered

  • This exact code has not run on macOS. The macOS result above is from the test-only patch with the same decision and TLS path. The macOS CI legs run the unit and e2e tests.
  • The e2e tests cannot listen on port 443, so the TLS-upstream test moves the dial to the fixture's port with a re-route of host:443. The no-backend TLS choice is covered by the unit test and by the manual Linux run against the real host.
  • No rustup run with this build; the manual run used curl. rustup also needs a writable RUSTUP_HOME, which is outside this change.
  • [gateway] upgrade_http is box-wide; there is no per-tool scope.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment thread docs/design/decisions.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment

I found no correctness defect in the upgrade path. The one open point is scope: the credential refusal means this change does not fix the gh case in #344 (see the inline comment). The other open point is approval: this PR changes frozen surfaces.

Review categories
  • Approval / API review: Root AGENTS.md lists box.toml keys and stored records as frozen surfaces and says to "Get the user's explicit approval before writing code". It also says to "Record an entry in docs/design/decisions.md only after the user decides it." The PR names the surfaces it moves, which is good, but it has no api/needs-review label. A new top-level [gateway] table is a new public config abstraction, so the label and a maintainer sign-off on the key name and shape are needed before merge.
  • Verification of the motivating case: The feature exists for macOS rustup. "Not covered" says this build has not run on macOS and has not run with rustup. Before merge, run rustup toolchain install once on macOS with RUSTUP_DIST_SERVER=http://static.rust-lang.org and this build. That would confirm the docs/user/egress.md instruction, because committed examples must still work.

Checks that held (each in one line):

  • Plain requests reaching plain_destination: ports 80 and explicit :80 are upgraded. :443, :8080, unlisted hosts and parent domains keep their port. Host spelling is normalized in parse_authority before matching.
  • Policy is the only authorizer: upgraded requests still pass Resolve, Connect (host and pinned address), HttpRequest and ResponseRelease on 443, and the address decided is the address dialed.
  • One request per plain connection: a kept-alive connection cannot carry an upgraded destination over to another host.
  • A backend that matches host:443 still decides the leg and the Host, the same as for a CONNECT.
  • pub use set is unchanged. The new MitmConfig field has a named consumer (run/hosted.rs), and it is the only MitmConfig construction site.
  • Record version 32 is stamped and checked on read, older versions are refused (the_gateway_upgrade_list_cannot_hide_in_a_legacy_record), and four_inputs.rs key set is updated.
  • Entry validation refuses a scheme, port, path, wildcard, IP, empty label or non-ASCII entry, both at load and on record read.
  • The new e2e and unit tests pass locally.

The scope is tight, and the tests cover the decision and port behaviour well.

@zastrowm zastrowm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aligned directionally but check the names

Comment thread docs/user/egress.md Resolved
@opieter-aws
opieter-aws merged commit 61ade09 into main Nov 12, 2026
33 of 35 checks passed
@opieter-aws
opieter-aws deleted the feature/gateway-http-upgrade branch November 12, 2026 16:43
ferdingler added a commit that referenced this pull request Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants