Repository navigation
Add outbound mTLS client identities, implemented on Fastly - #524
ChristianPavilonis wants to merge 10 commits into
Conversation
|
For the identity integration branch (#495), I pushed |
|
For the identity integration branch (#495), I pushed |
|
For the identity integration branch (#495), I pushed |
prk-Jr
left a comment
There was a problem hiding this comment.
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::preparebefore 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::checkchecks, so aHostoverride can't send the certificate to an origin outside the list. - Private key: opened as a
Secrethandle 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.
- Host check: the backend connects to the URI's host and port, which is exactly what
- Fastly SDK 0.13.3:
BackendBuilder::provide_client_certificate(impl ToString, Secret)matches how it is used here, including taking theSecretby value (the reason the key handle isn't cached). - Other adapters: Axum, Cloudflare and Spin reject identity requests as
Unsupportedbefore 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-sideclient_identity(7), Axum (1). - Broken-code check: I stopped redirect replay from keeping the identity, and
redirects_keep_the_identity_and_recheck_every_hopfailed as it should. - Hosted CI at
d1c6bea1: all completed jobs passed. Thefastly wasm testsjob ran the newclient-identityViceroy 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()) { |
There was a problem hiding this comment.
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.
Summary
OutboundRequest::client_identity(name). Application code never holds certificate or key bytes.Appbuilds an identity policy from the baked manifest once, and dispatch attaches it to each request'sHttpClient, 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.provide_client_certificate. Cloudflare, Spin and Axum reject identity requests before I/O until their bindings land.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
edgezero-coremanifest[capabilities.outbound.client-identities.<name>]with optionalconfig-storeandsecret-store, name rules, store validation,AtomicHost::permits, and theoutbound-client-identitycapability.edgezero-coreoutboundclient_identitymodule:ClientIdentityName,ClientIdentityPolicy,ClientIdentityHosts,ClientCertificateChainandClientIdentityError.OutboundRequest::client_identity.dispatch::preparerejects 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.HttpClientcarries an optional policy.edgezero-coreapp and errorAppbuilds the policy fromHooks::manifest()and attaches it at dispatch unless the client already has one. NewEdgeError::ClientIdentity { name, reason }; the reason chooses 500, 503 or 502.base64joins core's dependencies (already pinned in the workspace).edgezero-adapter/edgezero-cliAdapter::validate_client_identitieshook, run in the CLI's required-capability check.edgezero-adapter-fastlyprovide_client_certificate; backend names include the identity and chain fingerprint underez_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 isNative.edgezero-adapter-{cloudflare,spin,axum}Unsupportedbefore any transport work.edgezero-test-harnessclient-identitysuite, now part of the Fastlycisuite. Arun_appfixture runs against host-side rustls origins that require client certificates, with per-run certificates fromrcgen. Reviewed owner fingerprints updated for the new dispatch. The harness gainsrcgenandrustls; the main workspace gains no packages.docs/guide/*,scripts/check_outbound_docs_contract.mjsbase64edge in every workspace that builds core by path; the harness lockfile forrcgenandrustls.Decisions made during implementation
These differ from the agreed spec and are recorded in it and in the plan:
fastly::secret_store::Secretis neitherClonenorSync, andprovide_client_certificatetakes 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.Hooks::manifest()rather than usingapp!, because the fixture workspace has noedgezero.tomllayout for the macro.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-identitycases 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 ignoredcargo clippy --workspace --all-targets --all-features -- -D warnings, plus every Fastly, Cloudflare and Spin wasm feature set fromformat.yml, Fastlycliand no-default, the harness, and the fixturescargo fmt --all -- --check(root, harness, fixtures)cargo check --workspace --all-targets --features "fastly cloudflare spin"wasm32-wasip2checkexamples/app-demoworkspace:cargo test --workspace --all-targetsand the three adapter checksnpm run lint && npm run format && npm run build; outbound docs contractedgezero serve --adapter axum: not applicable, Axum rejects identitiesscripts/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.--suite ci.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
{id}syntax (not:id)edgezero_core(nothttpcrate)run_appdoes