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
test(tls-cert-auth): route-level coverage for certificate binding
bernie-g5336d8f11188
diff --git a/backend/AGENTS.md b/backend/AGENTS.mdindex 59d352893f..b1650797df 100644--- a/backend/AGENTS.md+++ b/backend/AGENTS.md@@ -285,6 +285,7 @@ Auth extraction happens in `src/server/plugins/auth/`:**Auth modes** (defined in `AuthMode` enum):- **JWT** — user browser sessions (decoded from `Authorization: Bearer` header)- **IDENTITY_ACCESS_TOKEN** — machine-to-machine identity tokens+ A TLS Certificate Auth token may carry an RFC 8705 `cnf` (`x5t#S256`) claim. `fnValidateIdentityAccessTokenFast` and renewal then reject it unless the proxy-forwarded client certificate matches (`assertCertificateBinding`).- **SCIM_TOKEN** — SCIM provisioning tokens- **OAUTH** — delegated user tokens from the `oauth-client` module. Same JWT shape and session binding as`JWT`, told apart by an `oauthClientId` claim. See [Delegated OAuth tokens](#delegated-oauth-tokens).diff --git a/backend/e2e-test/routes/v1/identity-tls-cert-auth.spec.ts b/backend/e2e-test/routes/v1/identity-tls-cert-auth.spec.tsindex d74ef0394a..b561bf46c0 100644--- a/backend/e2e-test/routes/v1/identity-tls-cert-auth.spec.ts+++ b/backend/e2e-test/routes/v1/identity-tls-cert-auth.spec.ts@@ -1,3 +1,5 @@+import crypto from "node:crypto";+import * as x509 from "@peculiar/x509";import { GeneralName, GeneralSubtree, NameConstraints } from "pkijs";@@ -379,4 +381,109 @@ describe("Identity TLS certificate auth v1", async () => {});});});+ describe("certificate-bound access tokens", async () => {+ const certHeader = (cert: x509.X509Certificate) => encodeURIComponent(toPem(cert));+ const thumbprint = (cert: x509.X509Certificate) =>+ crypto.createHash("sha256").update(Buffer.from(cert.rawData)).digest("base64url");+ const cnfOf = (accessToken: string) =>+ (JSON.parse(Buffer.from(accessToken.split(".")[1], "base64url").toString()) as { cnf?: Record<string, string> })+ .cnf;++ const setBinding = async (identityId: string, bindAccessTokenToCertificate: boolean) => {+ const res = await testServer.inject({+ method: "PATCH",+ url: `/api/v1/auth/tls-cert-auth/identities/${identityId}`,+ headers: { authorization: `Bearer ${jwtAuthToken}` },+ body: { bindAccessTokenToCertificate }+ });+ expect(res.statusCode).toBe(200);+ };++ const getDetails = (accessToken: string, cert?: x509.X509Certificate) =>+ testServer.inject({+ method: "GET",+ url: "/api/v1/identities/details",+ headers: {+ authorization: `Bearer ${accessToken}`,+ ...(cert ? { "x-identity-tls-cert-auth-client-cert": certHeader(cert) } : {})+ }+ });++ const renew = (accessToken: string, cert?: x509.X509Certificate) =>+ testServer.inject({+ method: "POST",+ url: "/api/v1/auth/token/renew",+ headers: cert ? { "x-identity-tls-cert-auth-client-cert": certHeader(cert) } : {},+ body: { accessToken }+ });++ // Revocation compares second-precision iat against the marker, so a token signed in the same second is revoked too.+ const waitPastRevocationSecond = () =>+ new Promise<void>((resolve) => {+ setTimeout(resolve, 1100);+ });++ test("binds the token to the login certificate on every request and renewal", async () => {+ const ca = await makeRoot("Binding CA");+ const leaf = await makeLeaf("workload", ca, { usages: [CLIENT_AUTH_EKU] });+ const other = await makeLeaf("other-workload", ca, { usages: [CLIENT_AUTH_EKU] });++ await withIdentity({ caCertificate: ca.cert, verifyChain: false }, async (identityId) => {+ await setBinding(identityId, true);+ await waitPastRevocationSecond();++ const loginRes = await login(identityId, [leaf.cert]);+ expect(loginRes.statusCode).toBe(200);+ const { accessToken } = loginRes.json() as { accessToken: string };+ expect(cnfOf(accessToken)).toEqual({ "x5t#S256": thumbprint(leaf.cert) });++ expect((await getDetails(accessToken, leaf.cert)).statusCode).toBe(200);++ const missing = await getDetails(accessToken);+ expect(missing.statusCode).toBe(401);+ expect(missing.json().message).toContain("no client certificate was presented");++ const mismatched = await getDetails(accessToken, other.cert);+ expect(mismatched.statusCode).toBe(401);+ expect(mismatched.json().message).toContain("does not match");++ expect((await renew(accessToken)).statusCode).toBe(401);+ expect((await renew(accessToken, other.cert)).statusCode).toBe(401);+ const renewed = await renew(accessToken, leaf.cert);+ expect(renewed.statusCode).toBe(200);+ expect(cnfOf(renewed.json().accessToken as string)).toEqual({ "x5t#S256": thumbprint(leaf.cert) });+ });+ });++ test("issues unbound tokens while the setting is off", async () => {+ const ca = await makeRoot("Unbound CA");+ const leaf = await makeLeaf("workload", ca, { usages: [CLIENT_AUTH_EKU] });++ await withIdentity({ caCertificate: ca.cert, verifyChain: false }, async (identityId) => {+ const { accessToken } = (await login(identityId, [leaf.cert])).json() as { accessToken: string };+ expect(cnfOf(accessToken)).toBeUndefined();+ expect((await getDetails(accessToken)).statusCode).toBe(200);+ });+ });++ test("revokes existing tokens when binding is turned on, and not when it is saved again", async () => {+ const ca = await makeRoot("Revocation CA");+ const leaf = await makeLeaf("workload", ca, { usages: [CLIENT_AUTH_EKU] });++ await withIdentity({ caCertificate: ca.cert, verifyChain: false }, async (identityId) => {+ const { accessToken: unbound } = (await login(identityId, [leaf.cert])).json() as { accessToken: string };+ expect((await getDetails(unbound)).statusCode).toBe(200);++ await setBinding(identityId, true);+ const revoked = await getDetails(unbound);+ expect(revoked.statusCode).toBe(401);+ expect(revoked.json().message).toContain("revoked");++ await waitPastRevocationSecond();+ const { accessToken: bound } = (await login(identityId, [leaf.cert])).json() as { accessToken: string };+ await setBinding(identityId, true);+ expect((await getDetails(bound, leaf.cert)).statusCode).toBe(200);+ });+ });+ });});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 1a85038d7d..a46092291d 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@@ -247,7 +247,7 @@ Throughout this guide, replace `<namespace>` with the namespace where your worklkey: tls.key```- On Infisical Cloud, set `url` to port `8443`, for example `https://app.infisical.com:8443`. On a self-hosted instance, the proxy in front of Infisical must forward the client certificate on every API request. See [Security requirements for self-hosted deployments](/documentation/platform/identities/tls-cert-auth#security-requirements-for-self-hosted-deployments).+ `url` must use `https://`, since the client certificate is presented over TLS. On Infisical Cloud, set `url` to port `8443`, for example `https://app.infisical.com:8443`. On a self-hosted instance, the proxy in front of Infisical must forward the client certificate on every API request. See [Security requirements for self-hosted deployments](/documentation/platform/identities/tls-cert-auth#security-requirements-for-self-hosted-deployments).</Tab></Tabs>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 5c00154947..56cebc5fef 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@@ -364,8 +364,8 @@ export const IdentityTlsCertAuthForm = ({Access tokens only work on requests that present the same clientcertificate used to log in. Your TLS-terminating proxy must forward thecertificate on every API request. On Infisical Cloud, send requests to- port 8443. Turning this on revokes the identity's existing TLS Certificate- Auth access tokens.+ port 8443. Turning this on revokes the identity's existing TLS+ Certificate Auth access tokens.</TooltipContent></Tooltip></FieldLabel>