Pular para o conteúdo principal
Versão: main (dev) 🚧

ADR-017 — Service callers by registered client certificate (mTLS)

Date: 2026-10-02 Status: Accepted Extends: ADR-006 (dual scheme), ADR-015 (system permissions). Library side: DevPack ADR-014 (Identity/Authentication/ClientCertificate, 10.19.0). Origin: ABBC Hub backport, wave W5 (C1).

Context​

Machine-to-machine partners want to call the API with the client certificate their TLS stack already presents, not a shared secret. The ABBC hub did this with a middleware that resolved the caller and let requests without a certificate through (fail-open), leaving each endpoint to check. The template authorizes by scheme + RequireAuthorization(), so a caller that does not authenticate gets 401 before any endpoint runs.

Decision​

A registered client certificate authenticates as a service of one tenant, through a scheme in the Smart selector. Off by default (Authentication:ClientCertificate:Enabled).

  • Registry: ClientCertificate aggregate (identity.ClientCertificates): tenant, label, the group (role) granted in that tenant, SHA-256 thumbprint, subject and the certificate's own validity — read from the PEM, never typed. Revoking is final. Managed at /v1/client-certificates with ClientCertificates.Read/Manage, both [SystemPermission]: a registered certificate acts in a tenant, so only the system administrator registers one. Only the public certificate is accepted; a PEM carrying a private key is refused.
  • Scheme: the DevPack ClientCertificate scheme; ClientCertificateCredentialStore returns a credential only when the certificate is not revoked, inside its validity and its tenant is active. The principal carries sub/client_id (mtls-<thumbprint prefix>), tenant, the granted role and auth_method=mtls, so permission resolution works as for any caller.
  • Routing: the selector sends a request to the certificate scheme only when nothing else speaks for the caller — no Authorization header and no session cookie.

Ingress (operations)​

  • The app does not validate chains: it trusts the registration. Chain, revocation and the TLS handshake belong to the ingress that terminates mTLS (e.g. Azure Container Apps clientCertificateMode: require).
  • Behind such an ingress set TrustForwardedHeader: true; the certificate then comes from X-Forwarded-Client-Cert. Only when the ingress requires client certificates and overwrites the header, and the app is reachable through it alone — otherwise any caller can type a registered thumbprint into the header. Pair it with ForwardedHeaders KnownProxies/KnownNetworks restricted to the ingress.
  • With Kestrel terminating TLS itself, enable ClientCertificateMode.AllowCertificate and leave TrustForwardedHeader off.

Signed requests​

A route can also require the body signed (DevPack Middleware/RequestSigning, detached JWS over the raw body, htm/htu, iat window, jti kept against replay). RequestSigning:Enabled marks POST /v1/orders as the example.

  • The key is the caller's registered certificate. RegisteredCertificateSigningKeyResolver answers only for a principal of this scheme (auth_method=mtls): the connection certificate when TLS reached the app, otherwise the PEM stored at registration, read by credential_id. The DevPack default — whatever certificate the connection carries — would let a caller authenticated another way sign with any key it holds, and the signature would bind the body to no one.
  • The registration therefore keeps the public PEM (CertificatePem, re-exported so no chain or text rides along).
  • Nonces live in identity.SignatureNonces (DevPack EF store); the unique jti settles the race between replicas.

Consequences​

  • Two migrations (AddClientCertificates, AddRequestSigning). ClientCertificate is allowlisted in AssertEveryMultiTenantEntityIsFiltered: it is looked up while authenticating, before any tenant exists.
  • Nothing changes for existing callers: the scheme is off by default and, when on, only picks requests that present a certificate and nothing else.

Alternatives considered​

  • Microsoft.AspNetCore.Authentication.Certificate: always validates the chain against a trust store — the opposite of trusting a registration.
  • A fail-open resolver middleware (the hub's shape): pushes the refusal into every endpoint.