Skip to content

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

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

ChristianPavilonis wants to merge 27 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.
Bring in PR #464's round 12 head, which carries the review fixes of the
whole identity chain below it, including the surrogate cache-tag
rejection, record, Geo and Axum hosting fixes, and PR #275's Viceroy
absent-key repair.

crates/edgezero-adapter-cloudflare/src/outbound.rs: both sides changed
the same cfg-gated outbound import. #524 adds ClientIdentityError for
its unsupported client identity rejection, and #464 widens the import
to OutboundCachePolicy for its tagged-default tests. Keep both imports.
The unsupported client identity test sat directly above the capability
matrix test. The after-response line (PR #509 and up) adds a
too_many_lines expectation on that matrix test. In rc/identity, the two
insertions are adjacent, so a plain merge conflicts. Moving the
test below the matrix keeps both changes apart. The test itself is
unchanged.
Bring in PR #464's new head, which carries the lockfile updates and PR
#514's Spin geo hardening through PR #517. The merge is clean.
aram356 added a commit that referenced this pull request Dec 3, 2026
Take PR #524's new head, which adds outbound mTLS client identities,
implemented on Fastly, on top of PR #464.
@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Round 15 identity realignment: rc/identity is now at ef5cbf308. This branch fast-forwarded from 96b37bfa2 to 4f46386bd:

This PR is back in rc/identity, because Trusted Server's client certificates for auction providers (IABTechLab/trusted-server#1667) are in its preramp release. e3ff7c88e merges #464's head, and af7354feb moves this PR's unchanged client_identities_are_unsupported test away from a line #509 also changes, so rc/identity takes this PR as a plain merge. The 2026-11-27 revert drops none of this PR's current change: the merge base is now after the revert, and the change over #464 matches file for file. Fastly backend names now start with ez_b31v2_.

Each merge message says what it carries and how any conflict was resolved.

# Conflicts:
#	crates/edgezero-test-harness/src/main.rs
A registered identity backend keeps the key it was registered with for the rest of the sandbox, so writing the certificate first can leave a reused sandbox failing until it ends.
The response body named the identity, upstream origins and binding state; Display and client_identity_error() keep that detail for logs.
Router state replaces the request client after dispatch attaches the policy, so declared identities failed as Undeclared.
No hosts entry can list an http origin, so an upstream downgrade is a 502 HostNotAllowed hop instead of a 500 RequiresHttps.
Also records the Fastly backend prefix change from ez_b31v1_ to ez_b31v2_.
# Conflicts:
#	crates/edgezero-adapter-fastly/src/outbound.rs
#	crates/edgezero-test-harness/src/evidence/cutover/reviewed_owners.json
#	crates/edgezero-test-harness/src/runners.rs
@aram356

aram356 commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Review follow-up: fixes committed to this branch

A full review of this PR turned up the problems below; each would otherwise have needed a follow-up ticket, so it is fixed on this branch instead. Every item names its commit.

Fixed in an earlier pass:

  • mTLS bindings were cached across inbound requests. 6a69c36 moves the identity binding cache into the captured request/callback family, keeping within-request sharing and backend reuse; tests cover retained clients across callbacks, repaired errors, rotation and overlapping scopes.
  • The client-identity fixture build ran unsupervised. dc0872d uses the supervised process/capture path for that build, with direct cancellation coverage for the suite.

Fixed in this pass:

  • The rotation guidance was wrong under serve_app. The key is read only when a backend is registered, and the backend name covers the chain but not the key, so a sandbox that sees the new certificate before the new key registers a mismatched pair and reuses it until the sandbox ends. f0197da rewrites the guide: write the key first, then the certificate once the key has propagated, with the reason and the remaining failure window. Docs only; the existing warm-registry test shows the reuse.
  • Client identity refusals exposed internal detail in public 5xx bodies: the identity name, the internal upstream origin, and binding state such as "private key is missing". Every other server error already uses fixed text. 7412d74 returns fixed text for the status ("internal server error", "service unavailable" or "bad gateway"); Display, logs and client_identity_error() keep the detail. client_identity_wire_messages_do_not_expose_identity_or_origin checks each reason.
  • A router-state HttpClient lost the identity policy. Dispatch attaches the app policy to the request's client, but router state replaces that client, so an app registering its own HttpClient with RouterBuilder::with_state had every declared identity fail as Undeclared (500). 8daa8c4 gives a router-state client without a policy the app policy in App::from_router after configure and keeps an explicit policy; the guide covers clients held in app-owned state. router_state_clients_receive_the_app_policy covers both cases.
  • A redirect to http:// was reported as an application error. The hop failed as RequiresHttps (500), classing an upstream choice as an app bug. f3195f7 fails it as HostNotAllowed { redirect: true } (502) with origin http://host:port, like any other unlisted redirect target. a_redirect_to_http_fails_as_a_redirect_failure asserts hop 1, 502, and that the hop is never sent.
  • No release note for client identities or the backend rename. 2277e27 adds an ### Outbound client identities (mTLS) section: manifest table and name rules, capability matrix, OutboundRequest::client_identity, EdgeError::ClientIdentity statuses and fixed body text, policy for router-state and app-held clients, Fastly binding entries, Adapter::validate_client_identities, key-first rotation, and the ez_b31v1_ → ez_b31v2_ rename (hashes for backends without an identity are unchanged).
  • Lint follow-up. 0856797 orders the binding cache entry fields as clippy's item-ordering lint requires under -p edgezero-adapter-fastly --features cli --all-targets (the per-request binding cache change above introduced the order).

Fixes made on the PRs below this one in the stack were merged into this branch with merge commits. bb1bb7b keeps both the client-identity and outbound-lifetimes Fastly harness dispatches after the Viceroy pin check, re-pins the reviewed_owners.json fingerprint for that dispatch, and drops a test-only import #275 removed.

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