Skip to content

Add outbound mTLS client identities, implemented on Fastly - #524

Open
ChristianPavilonis wants to merge 10 commits into
review/admitted-error-finalizationfrom
feat/523-outbound-client-identity
Open

ChristianPavilonis wants to merge 10 commits into
review/admitted-error-finalizationfrom
feat/523-outbound-client-identity

Conversation

@ChristianPavilonis

@ChristianPavilonis ChristianPavilonis commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Outbound requests can present a TLS client certificate by naming a client identity declared in the manifest: OutboundRequest::client_identity(name). Application code never holds certificate or key bytes.
  • Core owns declarations end to end. App builds an identity policy from the baked manifest once, and dispatch attaches it to each request's HttpClient, so adapters write no policy code. Core rejects undeclared and non-HTTPS identity requests, owns the hosts grammar and certificate-chain fingerprint, and reports redirects to unlisted hosts as redirect failures.
  • Fastly is the first adapter. It reads the certificate chain and hosts list from the identity's Config Store once per inbound request, opens the private key from its Secret Store as a handle only when it registers a backend, and calls provide_client_certificate. Cloudflare, Spin and Axum reject identity requests before I/O until their bindings land.
  • Stacked on Extract admitted-error finalization from demo RC #464 (review/admitted-error-finalization), above Add portable ClientInfo for Fastly, Axum, Cloudflare and Spin #517 in GitHub stack #539. This PR does not include Portable DynamoDB and celld record providers on Fastly #522's portable record providers. Design: docs/superpowers/specs/2026-11-23-outbound-client-identity-design.md. Plan, decisions and evidence: docs/superpowers/plans/2026-11-23-outbound-client-identity.md.

Changes

Crate / File Change
edgezero-core manifest [capabilities.outbound.client-identities.<name>] with optional config-store and secret-store, name rules, store validation, AtomicHost::permits, and the outbound-client-identity capability.
edgezero-core outbound New client_identity module: ClientIdentityName, ClientIdentityPolicy, ClientIdentityHosts, ClientCertificateChain and ClientIdentityError. OutboundRequest::client_identity. dispatch::prepare rejects undeclared and non-HTTPS identity requests and hands the resolved identity to adapters. Redirect replay keeps the identity, and the follower reports unlisted redirect hosts as 502. HttpClient carries an optional policy.
edgezero-core app and error App builds the policy from Hooks::manifest() and attaches it at dispatch unless the client already has one. New EdgeError::ClientIdentity { name, reason }; the reason chooses 500, 503 or 502. base64 joins core's dependencies (already pinned in the workspace).
edgezero-adapter / edgezero-cli New Adapter::validate_client_identities hook, run in the CLI's required-capability check.
edgezero-adapter-fastly Binding module and per-request binding cache; provide_client_certificate; backend names include the identity and chain fingerprint under ez_b31v2_; identity requests bypass the response cache; identity plus Image Optimizer or surrogate-key caching is unsupported. The CLI check rejects identities whose stores can't resolve. The capability is Native.
edgezero-adapter-{cloudflare,spin,axum} Reject identity requests as Unsupported before any transport work.
edgezero-test-harness New client-identity suite, now part of the Fastly ci suite. A run_app fixture runs against host-side rustls origins that require client certificates, with per-run certificates from rcgen. Reviewed owner fingerprints updated for the new dispatch. The harness gains rcgen and rustls; the main workspace gains no packages.
docs/guide/*, scripts/check_outbound_docs_contract.mjs Client certificates in the proxying guide, the Fastly binding, rotation and local setup, the capability matrix row, and the manifest fields.
Lockfiles The base64 edge in every workspace that builds core by path; the harness lockfile for rcgen and rustls.

Decisions made during implementation

These differ from the agreed spec and are recorded in it and in the plan:

  • fastly::secret_store::Secret is neither Clone nor Sync, and provide_client_certificate takes it by value, so the key handle can't be cached. The key is opened once per backend registration, and not at all when the instance already has the backend. That is at least as cheap as the planned "one read per identity per request" for the expected single-origin case.
  • The hosts entry uses the outbound allowlist grammar (ASCII, punycode for internationalized names) so hosts and allowlist parse identically.
  • The Viceroy fixture overrides Hooks::manifest() rather than using app!, because the fixture workspace has no edgezero.toml layout for the macro.
  • Viceroy reports a rejected handshake as a generic InternalError (Viceroy#727). The runner proves rejection from the origin's own records instead of a TLS cause.

Closes

Closes #523

Test plan

After rebasing onto #464: 3,139 workspace tests and 681 harness tests passed on Rust 1.98.1. All nine Fastly client-identity cases passed on Viceroy 0.22.0. Formatting, Clippy, feature checks, and the docs build passed. The original implementation checks are below.

  • cargo test --workspace --all-targets: 3,265 passed, 16 ignored
  • cargo clippy --workspace --all-targets --all-features -- -D warnings, plus every Fastly, Cloudflare and Spin wasm feature set from format.yml, Fastly cli and no-default, the harness, and the fixtures
  • cargo fmt --all -- --check (root, harness, fixtures)
  • cargo check --workspace --all-targets --features "fastly cloudflare spin"
  • WASM: Fastly runtime unit tests (374) and SDK contract (37) under the repaired Viceroy; Spin wasm32-wasip2 check
  • examples/app-demo workspace: cargo test --workspace --all-targets and the three adapter checks
  • Docs build: npm run lint && npm run format && npm run build; outbound docs contract
  • Manual testing via edgezero serve --adapter axum: not applicable, Axum rejects identities
  • Other:
    • scripts/test_integration.sh --adapter fastly --suite client-identity: 9 of 9 cases. The identity request succeeds and the origin sees the configured certificate; requests without the identity and with a wrong-CA certificate fail at the handshake; a replaced certificate is presented after relaunch; undeclared, unsupported, non-HTTPS and missing-hosts requests make no TCP connection; a redirect to an unlisted host fails at hop 1 and that origin is never connected.
    • Fastly, Axum, Cloudflare and Spin --suite ci.
    • Harness 683 passed.

Not covered: hosted Fastly behavior. Trusted Server's staging run for IABTechLab/trusted-server#1650 exercises a real origin and the Secret Store read budget.

Checklist

  • Changes follow CLAUDE.md conventions
  • No Tokio deps added to core or adapter crates
  • Route params use {id} syntax (not :id)
  • Types imported from edgezero_core (not http crate)
  • Store wiring goes through the registries; the Fastly binding opens its logical store aliases the same way run_app does
  • New code has tests
  • No secrets or credentials committed; test certificates are generated per run

@ChristianPavilonis ChristianPavilonis linked an issue Nov 25, 2026 that may be closed by this pull request
9 tasks
aram356 added a commit that referenced this pull request Nov 25, 2026
Take PR #524's updated tip, which carries main's Fastly SDK 0.13.3
upgrade (#529) with Viceroy 0.22.0 and the Fastly CLI 17.2.0 upgrade
(#531), PR #275's drain of declared uploads before an early-response
HTTP/1 close, and the macOS test fixes from PRs #407 and #414. It
merges without conflicts.
aram356 added a commit that referenced this pull request Nov 25, 2026
Take PR #524's updated tip, which carries PR #275's installation of the
wasm32-unknown-unknown target before the Viceroy 0.22.0 readiness
repair builds. It merges without conflicts.
@aram356

aram356 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed 97ecf479 and af85b4ee, two merges of #522's new heads. 97ecf479 takes EdgeZero main's Fastly SDK 0.13.3 upgrade (#529), with Viceroy 0.22.0 and the Fastly CLI 17.2.0 upgrade (#531), with #275's exact pins at 0.13.3 and url 2.5.9, its Viceroy readiness repair on 0.22.0, its typed Image Optimizer unavailability check and its drain of declared uploads after an early response on Axum, and #522's Viceroy repair pins for the Portable record contracts (Fastly) job (39d307fe). af85b4ee takes #275's d8cd85c8, which installs the wasm32-unknown-unknown target before the Viceroy 0.22.0 readiness repair builds, as the fastly wasm tests and Portable record contracts (Fastly) jobs need. Both merges had no conflicts.

aram356 added a commit that referenced this pull request Nov 26, 2026
Take PR #524's updated tip, which carries PR #275's atomic conditional
KV insert in the Viceroy readiness repair and the production hosting
port reservation and respawn fixes. It merges without conflicts.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed f7df718a, a merge of #522's new head that brings #275's 41cdf035, which makes conditional KV inserts atomic in the Viceroy readiness repair, as the Fastly record contract's native race needs, and the production hosting tests' held port reservations and spawn-token respawn from #406 up, with each later PR's tests reading the live host's address, and #522's matching patch digest for the Portable record contracts (Fastly) job. It had no conflicts.

aram356 added a commit that referenced this pull request Nov 26, 2026
Take PR #524's updated tip, which carries PR #275's batch cutoff test
fix, the AWS emulator proofs' readiness markers published by rename,
and PR #522's strict documentation, Geo contract and generated CLI
formatting fixes. It merges without conflicts.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed d1c6bea1, a merge of #522's new head that brings #275's 0e2a58ae, which fixes an intermittent failure of the batch cutoff test by advancing its clock when the request arms its deadline timer, the AWS emulator proofs' readiness markers from #414 and #510, now published by rename, and #522's fixes for the strict documentation build, the Geo dependency check's platform graphs and the generated CLI's rustfmt layout. It had no conflicts.

@prk-Jr prk-Jr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. I found no blocking issues, and there is one small test-protection note inline.

What I checked

  • Core: undeclared and non-HTTPS identity requests are rejected in dispatch::prepare before any adapter call. Redirect replay keeps the identity and checks every hop again. A refused redirect hop is reported as 502, and the origin shown in errors never includes a path or query.
  • Fastly binding:
    • Host check: the backend connects to the URI's host and port, which is exactly what ClientIdentityHosts::check checks, so a Host override can't send the certificate to an origin outside the list.
    • Private key: opened as a Secret handle only when a backend has to be registered, and never read as plaintext.
    • Backend names: include the identity name and the chain fingerprint, so a plain request and an identity request never share a backend, and a rotated chain registers a new one.
    • Caching: identity responses always bypass the cache, and combining an identity with Image Optimizer or surrogate-key caching is rejected.
    • Per-request cache: the binding cache is per inbound request, because outbound_client() builds a new client for each request.
  • Fastly SDK 0.13.3: BackendBuilder::provide_client_certificate(impl ToString, Secret) matches how it is used here, including taking the Secret by value (the reason the key handle isn't cached).
  • Other adapters: Axum, Cloudflare and Spin reject identity requests as Unsupported before any transport work.
  • CodeQL alerts: both look like false positives. One is a test assertion message in cli.rs; the other logs only the leaf certificate's SHA-256 fingerprint, which is public.

Evidence

  • Local, Rust 1.98.1, all passed: core client_identity (15), core manifest identity tests (3), Fastly host-side client_identity (7), Axum (1).
  • Broken-code check: I stopped redirect replay from keeping the identity, and redirects_keep_the_identity_and_recheck_every_hop failed as it should.
  • Hosted CI at d1c6bea1: all completed jobs passed. The fastly wasm tests job ran the new client-identity Viceroy suite inside --suite ci, and the CI runner validated its events. A few deploy and smoke jobs were still queued or running when I looked.

Not covered: hosted Fastly mTLS against a real origin, and the Secret Store read budget. The PR description already lists both.

ClientIdentityError::Undeclared,
));
};
if !is_https(request.uri()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking (test protection): this check is the only place that guarantees what OutboundDispatchRequest::client_identity() promises ("already checked to be declared and HTTPS"). But no test fails if it is removed.

I disabled this if locally, and all 15 core client_identity tests still passed. undeclared_and_non_https_requests_never_reach_the_adapter keeps passing because the IdentityClient mock runs ClientIdentityHosts::check again, and that also returns RequiresHttps for an http:// URI. So the request does reach the adapter: the mock rejects it before writing to sent. In production, Fastly's own hosts check covers this today, and the other adapters reject as Unsupported, so there's no current defect.

The protection gap is for a future adapter that relies on core's guarantee. Recording every dispatched request in the mock before its own check (or not rechecking the scheme there) would let this test tell the difference.

Declare identities under [capabilities.outbound.client-identities], build
the identity policy once per App from the baked manifest, and attach it to
each request's HttpClient at dispatch. OutboundRequest::client_identity
selects one; core rejects undeclared and non-HTTPS identity requests before
adapter I/O, owns the hosts-entry grammar and certificate-chain fingerprint,
and reports redirect hops to unlisted hosts as redirect failures. Add the
outbound-client-identity capability and a CLI hook that lets Fastly reject
identities whose stores cannot resolve.
These adapters cannot present a client certificate yet, so requests that
select an identity fail before any transport work.
Read each identity's certificate chain and hosts from its config store once
per inbound request, open the private key from its Secret Store as a handle
only when a backend must be registered, and call provide_client_certificate.
Fold the identity name and chain fingerprint into the backend name under the
ez_b31v2_ prefix, bypass the response cache for identity requests, and
reject identities combined with Image Optimizer or surrogate-key caching.
A new client-identity suite builds a fixture that selects a declared
identity through run_app, generates a per-run CA and client certificates,
and runs it under the pinned Viceroy against host-side rustls origins that
require client certificates. The origins record TCP accepts before TLS and
the certificate of each completed handshake, so cases that must fail before
I/O are checked against connections. The suite joins the Fastly ci suite.
Secret handles are not Clone, so Fastly opens the key once per backend
registration; hosts use the outbound allowlist grammar; errors carry no
fingerprint. The plan records evidence for every task.
This was referenced Nov 27, 2026

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.

Portable outbound mTLS client identity, implemented on Fastly first

4 participants