Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(tls-cert-auth): address review feedback
bernie-gc191bacd68a9
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex a999ce4705..c16d7bad22 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -459,7 +459,7 @@ export const TLS_CERT_AUTH = {verifyClientCertificateChain:"When false (default), the CA certificate must be the direct issuer of the client's leaf certificate. When true, the CA certificate is treated as a trust anchor and the client-presented chain (leaf plus intermediates) is validated up to it, supporting issuers that rotate beneath a stable root such as SPIRE X.509-SVIDs.",bindAccessTokenToCertificate:- "When true, access tokens issued by this auth method are bound to the SHA-256 thumbprint of the client certificate used to log in (RFC 8705). Every request and renewal made with the token must present the same client certificate through the TLS-terminating proxy.",+ "When true, access tokens issued by this auth method are bound to the SHA-256 thumbprint of the client certificate used to log in (RFC 8705). Every request and renewal made with the token must present the same client certificate through the TLS-terminating proxy. Turning this on revokes the identity's existing TLS Certificate Auth access tokens.",accessTokenTTL: "The new lifetime for an access token in seconds.",accessTokenMaxTTL: "The new maximum lifetime for an access token in seconds.",accessTokenNumUsesLimit: "The new maximum number of times that an access token can be used.",diff --git a/backend/src/server/routes/v1/identity-tls-cert-auth-router.ts b/backend/src/server/routes/v1/identity-tls-cert-auth-router.tsindex ffc69bfbf3..d202d7fb39 100644--- a/backend/src/server/routes/v1/identity-tls-cert-auth-router.ts+++ b/backend/src/server/routes/v1/identity-tls-cert-auth-router.ts@@ -3,7 +3,6 @@ import { z } from "zod";import { IdentityAuthMethod, IdentityTlsCertAuthsSchema } from "@app/db/schemas";import { EventType } from "@app/ee/services/audit-log/audit-log-types";import { ApiDocsTags, TLS_CERT_AUTH } from "@app/lib/api-docs";-import { getConfig } from "@app/lib/config/env";import { crypto } from "@app/lib/crypto/cryptography";import { BadRequestError, UnauthorizedError } from "@app/lib/errors";import { logger } from "@app/lib/logger";@@ -12,6 +11,7 @@ import { slugSchema } from "@app/server/lib/schemas";import { getTelemetryDistinctId } from "@app/server/lib/telemetry";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { ActorType, AuthMode } from "@app/services/auth/auth-type";+import { readClientCertificateHeader } from "@app/services/identity-access-token/identity-access-token-fns";import {isValidAllowedSubjectAltNameEntry,parseAllowedSubjectAltNames@@ -105,8 +105,7 @@ export const registerIdentityTlsCertAuthRouter = async (server: FastifyZodProvid},handler: async (req) => {try {- const appCfg = getConfig();- const clientCertificate = req.headers[appCfg.IDENTITY_TLS_CERT_AUTH_CLIENT_CERTIFICATE_HEADER_KEY];+ const clientCertificate = readClientCertificateHeader(req.headers);if (!clientCertificate) {throw new BadRequestError({ message: "Missing TLS certificate in header" });}@@ -114,7 +113,7 @@ export const registerIdentityTlsCertAuthRouter = async (server: FastifyZodProvidconst { identityTlsCertAuth, accessToken, identityAccessToken, identity } =await server.services.identityTlsCertAuth.login({...req.body,- clientCertificate: clientCertificate as string+ clientCertificate});await server.services.auditLog.createAuditLog({diff --git a/backend/src/services/identity-access-token/identity-access-token-fns.ts b/backend/src/services/identity-access-token/identity-access-token-fns.tsindex f7fb30dd1f..2a1b1a70c1 100644--- a/backend/src/services/identity-access-token/identity-access-token-fns.ts+++ b/backend/src/services/identity-access-token/identity-access-token-fns.ts@@ -446,14 +446,14 @@ export const assertCertificateBinding = ({if (!clientCertificate) {throw new UnauthorizedError({- message: `${messagePrefix}: access token is bound to a client certificate, but no client certificate was presented`+ message: `${messagePrefix}: access token is bound to a client certificate, but no client certificate was presented. Send every request through the TLS-terminating proxy with the same client certificate used to log in`});}const leafDer = parsePresentedLeafCertificate(clientCertificate);if (!leafDer) {throw new UnauthorizedError({- message: `${messagePrefix}: the presented client certificate could not be parsed`+ message: `${messagePrefix}: the client certificate header could not be read. The TLS-terminating proxy must forward the URL-encoded certificate chain`});}diff --git a/backend/src/services/identity-access-token/identity-access-token-service.test.ts b/backend/src/services/identity-access-token/identity-access-token-service.test.tsindex f95597a0da..dd2f83988e 100644--- a/backend/src/services/identity-access-token/identity-access-token-service.test.ts+++ b/backend/src/services/identity-access-token/identity-access-token-service.test.ts@@ -1269,7 +1269,7 @@ describe("certificate-bound access tokens", () => {const claims = verifyAccessTokenJwt(signBoundToken());await expect(service.fnValidateIdentityAccessTokenFast(claims, "10.0.0.1", "%E0%A4%A")).rejects.toThrow(- "could not be parsed"+ "client certificate header could not be read");});diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.tsindex 740cbb9ace..ced9ae34ba 100644--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts@@ -719,6 +719,13 @@ export const identityTlsCertAuthServiceFactory = ({return doc;});+ // Tokens issued before binding was enabled carry no certificate claim, so they must not outlive the change.+ if (bindAccessTokenToCertificate && !identityTlsCertAuth.bindAccessTokenToCertificate) {+ await identityAccessTokenService.revokeTokensForIdentityAuthMethod({+ identityId,+ authMethod: IdentityAuthMethod.TLS_CERT_AUTH+ });+ }await identityAccessTokenService.invalidateTrustedIpsCache(identityId, IdentityAuthMethod.TLS_CERT_AUTH);return { ...updatedTlsCertAuth, orgId: identityMembershipOrg.scopeOrgId };};diff --git a/docs/documentation/platform/identities/tls-cert-auth.mdx b/docs/documentation/platform/identities/tls-cert-auth.mdxindex a4cc3cc9fa..d9a492f38f 100644--- a/docs/documentation/platform/identities/tls-cert-auth.mdx+++ b/docs/documentation/platform/identities/tls-cert-auth.mdx@@ -188,16 +188,16 @@ By default, an access token from TLS Certificate Auth is a bearer token: anyoneWith binding enabled:-- Every API request made with the token, including [token renewal](/api-reference/endpoints/universal-auth/renew-access-token), must present the same client certificate through the TLS-terminating proxy.-- A request with no client certificate, or a different one, is rejected with `401 Unauthorized` and a message stating which.-- Renewing the token keeps the binding.-- After the client certificate rotates, the client must log in again to get a token bound to the new certificate.+- Every API request made with the token, including [token renewal](/api-reference/endpoints/universal-auth/renew-access-token), must present the same client certificate through the TLS-terminating proxy+- A request with no client certificate, or a different one, is rejected with `401 Unauthorized`+- Renewing the token keeps the binding+- After the client certificate rotates, the client must log in again to get a token bound to the new certificate-The client must present its certificate on every API call, not only on login. A custom client using the login example below must reuse the same HTTPS agent for its later API calls. The [Infisical Issuer for cert-manager](/documentation/platform/pki/guides/applications/k8s-cert-manager-issuer) supports this through the `tlsCert` method.+The client must present its certificate on every API call, not only on login. A custom client using the [login example](#accessing-the-infisical-api-with-the-identity) must reuse the same HTTPS agent for its later API calls. The [Infisical Issuer for cert-manager](/documentation/platform/pki/guides/applications/k8s-cert-manager-issuer) supports this through the `tlsCert` method.On Infisical Cloud, send every API request made with a bound token to port `8443`, for example `https://app.infisical.com:8443`. Requests on port `443` carry no client certificate and are rejected.-Turning the setting on or off applies to tokens issued afterwards. Tokens issued earlier keep the behavior they were issued with until they expire.+Turning the setting on revokes the identity's existing TLS Certificate Auth tokens, which were issued without a binding. Tokens issued while the setting was on stay bound until they expire, even after it's turned off.## Security requirements for self-hosted deployments@@ -207,13 +207,15 @@ ALL TLS cert [login](/api-reference/endpoints/tls-cert-auth/login) requests **MU- **REQUIRED:** Ensure the load balancer **verifies the client possesses the private key** corresponding to the certificate (standard TLS behavior)- **NEVER** allow direct connections to Infisical for TLS cert auth, since this enables header injection attacks- **NEVER** forward certificate headers without requiring proper TLS certificate presentation-- **REQUIRED:** Always overwrite the client certificate header with the certificate from the TLS handshake, or with an empty value when none was presented. Never pass through a value sent by the client: certificates are public, so a client-supplied header lets anyone claim any certificate.+- **REQUIRED:** Always overwrite the client certificate header with the certificate from the TLS handshake, or with an empty value when none was presented (certificates are public, and a client-supplied header lets anyone claim any certificate)When **Bind Access Tokens to Client Certificate** is enabled on any identity, the proxy must set the header on **every** API request, not only on the login endpoint. Otherwise bound tokens are rejected on every request after login.```nginxserver {listen 443 ssl;+ ssl_certificate /etc/nginx/tls/server.crt;+ ssl_certificate_key /etc/nginx/tls/server.key;ssl_verify_client optional_no_ca;location /api {diff --git a/docs/documentation/platform/pki/guides/applications/k8s-cert-manager-acme.mdx b/docs/documentation/platform/pki/guides/applications/k8s-cert-manager-acme.mdxindex 7f0f20025c..7edef2a1eb 100644--- a/docs/documentation/platform/pki/guides/applications/k8s-cert-manager-acme.mdx+++ b/docs/documentation/platform/pki/guides/applications/k8s-cert-manager-acme.mdx@@ -7,7 +7,7 @@ description: "Automatically provision and manage TLS certificates in KubernetesIssue TLS certificates to your Kubernetes workloads using [cert-manager](https://cert-manager.io/) and Infisical over **ACME**. Certificates are requested via ACME with External Account Binding (EAB), stored in Kubernetes Secrets, and renewed automatically before expiration.<Info>- This is the **ACME** approach. If you would rather authenticate with an Infisical [machine identity](/documentation/platform/identities/machine-identities) (Universal Auth or Kubernetes Auth) instead of ACME/EAB, and want the CA chain populated in the Secret automatically, use the [Infisical Issuer guide](/documentation/platform/pki/guides/applications/k8s-cert-manager-issuer) instead.+ This is the **ACME** approach. If you would rather authenticate with an Infisical [machine identity](/documentation/platform/identities/machine-identities) (Universal Auth, Kubernetes Auth or TLS Certificate Auth) instead of ACME/EAB, and want the CA chain populated in the Secret automatically, use the [Infisical Issuer guide](/documentation/platform/pki/guides/applications/k8s-cert-manager-issuer) instead.This guide assumes you have an Application with [ACME enrollment](/documentation/platform/pki/applications/enrollment-methods/acme) configured.</Info>diff --git a/docs/documentation/platform/pki/guides/applications/k8s-cert-manager-issuer.mdx b/docs/documentation/platform/pki/guides/applications/k8s-cert-manager-issuer.mdxindex b1bc625229..1a85038d7d 100644--- a/docs/documentation/platform/pki/guides/applications/k8s-cert-manager-issuer.mdx+++ b/docs/documentation/platform/pki/guides/applications/k8s-cert-manager-issuer.mdx@@ -139,7 +139,7 @@ Throughout this guide, replace `<namespace>` with the namespace where your worklThe service account's name and namespace must be allowed by the identity's [Kubernetes Auth](/documentation/platform/identities/kubernetes-auth) configuration in Infisical (and the audience there must match), otherwise issuance fails authentication.</Tab><Tab title="TLS Certificate Auth">- Store the machine identity's **Identity ID**, and the client certificate and private key in a `kubernetes.io/tls` Secret:+ Store the machine identity's **Identity ID** in a generic Secret, and the client certificate and private key in a `kubernetes.io/tls` Secret:```bashkubectl create secret generic infisical-identity \@@ -218,7 +218,7 @@ Throughout this guide, replace `<namespace>` with the namespace where your workl```</Tab><Tab title="TLS Certificate Auth">- ```yaml issuer-infisical.yaml+ ```yaml issuer-infisical.yaml expandableapiVersion: infisical-issuer.infisical.com/v1alpha1kind: Issuermetadata:diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTlsCertAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTlsCertAuthForm.tsxindex 1496af45f4..dc6b2c21c3 100644--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTlsCertAuthForm.tsx+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTlsCertAuthForm.tsx@@ -363,7 +363,9 @@ export const IdentityTlsCertAuthForm = ({<TooltipContent className="max-w-md">Issued access tokens only work when the request presents the same clientcertificate used to log in (RFC 8705). Your TLS-terminating proxy must- forward the client certificate on every API request, not only on login.+ forward the client certificate on every API request, not only on login. On+ Infisical Cloud, send these requests to port 8443. Turning this on revokes+ the identity's existing TLS Certificate Auth access tokens.</TooltipContent></Tooltip></FieldLabel>diff --git a/nginx/default.conf b/nginx/default.confindex ccf35a831b..92610266fa 100644--- a/nginx/default.conf+++ b/nginx/default.conf@@ -85,6 +85,7 @@ server {proxy_set_header Host $http_host;proxy_set_header X-NginX-Proxy true;+ proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $http_x_amzn_mtls_clientcert;proxy_pass http://backend:4000;proxy_redirect off;@@ -98,6 +99,7 @@ server {proxy_set_header Host $http_host;proxy_set_header X-NginX-Proxy true;+ proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $http_x_amzn_mtls_clientcert;# specific for infisical cloud setup, needed for server-side mTLSproxy_set_header X-SSL-Client-Cert $http_x_amzn_mtls_clientcert;diff --git a/nginx/default.dev.conf b/nginx/default.dev.confindex 1d0ef55b48..b85c3ea396 100644--- a/nginx/default.dev.conf+++ b/nginx/default.dev.conf@@ -74,6 +74,7 @@ server {proxy_set_header Host $http_host;proxy_set_header X-NginX-Proxy true;+ proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $ssl_client_escaped_cert;proxy_pass http://api;proxy_redirect off;@@ -103,6 +104,7 @@ server {proxy_set_header Host $http_host;proxy_set_header X-NginX-Proxy true;+ proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $ssl_client_escaped_cert;proxy_pass http://api;proxy_redirect off;@@ -117,6 +119,7 @@ server {proxy_set_header Host $http_host;proxy_set_header X-NginX-Proxy true;+ proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $ssl_client_escaped_cert;proxy_set_header X-SSL-Client-Cert $ssl_client_escaped_cert;# proxy_set_header X-SSL-Client-Cert $http_x_ssl_client_cert;