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
check all nodes
Thiago Araujo da Silva9debb4ade3c3
diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.tsindex 211b24e2fe..0159d15950 100644--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts@@ -356,6 +356,8 @@ describe("verifyClientCertificateChain", () => {.toBER(false));+ const clientAuthEku = (usages: string[]) => new x509.ExtendedKeyUsageExtension(usages, true);+const makeLeaf = async (name: string,issuer: TIssued,@@ -662,6 +664,90 @@ describe("verifyClientCertificateChain", () => {expect(result).toEqual({ ok: true });});+ test("rejects a clientAuth leaf issued through a serverAuth-only intermediate", async () => {+ // A CA's EKU restricts the purposes of everything beneath it, so a serverAuth-only intermediate+ // cannot delegate client authentication no matter what the leaf itself asserts.+ const serverOnly = await makeIntermediate("ServerAuth Only CA", root, {+ serialNumber: "40",+ extraExtensions: [clientAuthEku(["1.3.6.1.5.5.7.3.1"])]+ });+ const leaf = await makeLeaf("workload", serverOnly);++ const result = await verifyClientCertificateChain({+ leaf: toNative(leaf.cert),+ presentedChain: [toNative(serverOnly.cert)],+ trustAnchor: toNative(root.cert),+ now: NOW+ });+ expect(result).toEqual({ ok: false, reasonCode: "issuer_client_auth_usage_not_allowed" });+ });++ test("rejects a leaf issued directly by a codeSigning-only configured anchor", async () => {+ const codeSigningOnly = await makeIntermediate("CodeSigning Only CA", root, {+ serialNumber: "41",+ extraExtensions: [clientAuthEku(["1.3.6.1.5.5.7.3.3"])]+ });+ const leaf = await makeLeaf("workload", codeSigningOnly);++ const result = await verifyClientCertificateChain({+ leaf: toNative(leaf.cert),+ presentedChain: [],+ trustAnchor: toNative(codeSigningOnly.cert),+ now: NOW+ });+ expect(result).toEqual({ ok: false, reasonCode: "issuer_client_auth_usage_not_allowed" });+ });++ test("accepts a chain whose CAs assert clientAuth or anyExtendedKeyUsage", async () => {+ const clientAuthCa = await makeIntermediate("ClientAuth CA", root, {+ serialNumber: "42",+ extraExtensions: [clientAuthEku(["1.3.6.1.5.5.7.3.1", "1.3.6.1.5.5.7.3.2"])]+ });+ const anyPurposeCa = await makeIntermediate("Any Purpose CA", clientAuthCa, {+ serialNumber: "43",+ extraExtensions: [clientAuthEku(["2.5.29.37.0"])]+ });+ const leaf = await makeLeaf("workload", anyPurposeCa);++ const result = await verifyClientCertificateChain({+ leaf: toNative(leaf.cert),+ presentedChain: [toNative(clientAuthCa.cert), toNative(anyPurposeCa.cert)],+ trustAnchor: toNative(root.cert),+ now: NOW+ });+ expect(result).toEqual({ ok: true });+ });++ test("builds a path through an alternative issuer when one candidate forbids client auth", async () => {+ // Two CAs share a subject and key, so both verify as the leaf's issuer; only one permits+ // client authentication. The EKU check must not strand the chain on the wrong candidate.+ const usableKeys = await crypto.webcrypto.subtle.generateKey(alg, true, ["sign", "verify"]);+ const makeSibling = async (serialNumber: string, usages: string[]) =>+ x509.X509CertificateGenerator.create({+ serialNumber,+ subject: "CN=Shared Subject CA",+ issuer: root.cert.subject,+ notBefore: NOT_BEFORE,+ notAfter: FAR_FUTURE,+ signingKey: root.keys.privateKey,+ publicKey: usableKeys.publicKey,+ signingAlgorithm: alg,+ extensions: [new x509.BasicConstraintsExtension(true, undefined, true), clientAuthEku(usages)]+ });++ const serverOnly = await makeSibling("50", ["1.3.6.1.5.5.7.3.1"]);+ const clientCapable = await makeSibling("51", ["1.3.6.1.5.5.7.3.2"]);+ const leaf = await makeLeaf("workload", { cert: clientCapable, keys: usableKeys });++ const result = await verifyClientCertificateChain({+ leaf: toNative(leaf.cert),+ presentedChain: [toNative(serverOnly), toNative(clientCapable)],+ trustAnchor: toNative(root.cert),+ now: NOW+ });+ expect(result).toEqual({ ok: true });+ });+test("rejects when the intermediate has expired", async () => {const expiredIntermediate = await makeIntermediate("Expired Intermediate", root, {notAfter: new Date("2026-06-10T00:00:00Z")diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.tsindex 8182fc3d8f..3ecb8d3350 100644--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts@@ -19,6 +19,7 @@ export type TVerifyClientCertificateChainResult =| "ca_verification_failed"| "certificate_expired"| "certificate_not_yet_valid"+ | "issuer_client_auth_usage_not_allowed"| "name_constraint_violation"| "path_length_exceeded";};@@ -112,6 +113,22 @@ const enforceNameConstraints = async (orderedPath: TNativeX509[], now: Date): Prreturn { ok: false, reasonCode: "ca_verification_failed" };};+/**+ * RFC 5280 4.2.1.12: an Extended Key Usage extension is the exhaustive list of purposes its+ * certificate may be used for. Without this check a leaf issued for serverAuth or codeSigning+ * authenticates an identity, so anyone holding a server certificate under the configured CA can+ * impersonate the machine identity pinned to it.+ *+ * A certificate that omits the extension is unconstrained and stays accepted, which is how OpenSSL+ * and Go read a missing EKU and what keeps existing leaves that carry no EKU working. Only a+ * certificate that explicitly enumerates purposes and leaves client authentication out is rejected.+ */+export const permitsClientAuth = (cert: TNativeX509): boolean => {+ const usages = new x509.X509Certificate(cert.raw).getExtension(x509.ExtendedKeyUsageExtension)?.usages;+ if (!usages) return true;+ return usages.some((oid) => oid === CLIENT_AUTH_EKU_OID || oid === ANY_PURPOSE_EKU_OID);+};+/*** Validate the presented client certificate chain against a configured trust anchor.*@@ -119,8 +136,9 @@ const enforceNameConstraints = async (orderedPath: TNativeX509[], now: Date): Pr* path from the leaf through the presented intermediates up to the configured trust anchor and* verifies, at every hop: the issuer relationship (subject/issuer match + signature), that each* issuer is a CA (including the trust anchor itself), and that every certificate on the path is- * within its validity window. The resulting path is then checked against the RFC 5280 delegation- * constraints its CAs assert: `pathLenConstraint` and name constraints.+ * within its validity window, and that every issuer's extended key usage permits client+ * authentication. The resulting path is then checked against the RFC 5280 delegation constraints+ * its CAs assert: `pathLenConstraint` and name constraints.** The trust anchor is the only trusted input. Presented intermediates are untrusted: a forged or* unrelated intermediate cannot create a path to the anchor, so it is rejected. This mirrors how@@ -212,6 +230,8 @@ export const verifyClientCertificateChain = async ({ok: false,reasonCode: now < new Date(trustAnchor.validFrom) ? "certificate_not_yet_valid" : "certificate_expired"};+ } else if (!permitsClientAuth(trustAnchor)) {+ result = { ok: false, reasonCode: "issuer_client_auth_usage_not_allowed" };} else {result = { ok: true, issuers: [trustAnchor] };}@@ -224,7 +244,9 @@ export const verifyClientCertificateChain = async ({for (const candidate of presentedChain) {// An issuer on the path must be a CA and have signed the current certificate.if (candidate.ca && issuedBy(current, candidate)) {- const candidateResult = walk(candidate);+ const candidateResult: TPathSearchResult = permitsClientAuth(candidate)+ ? walk(candidate)+ : { ok: false, reasonCode: "issuer_client_auth_usage_not_allowed" };if (candidateResult.ok) {result = { ok: true, issuers: [candidate, ...candidateResult.issuers] };break;@@ -255,22 +277,6 @@ export const verifyClientCertificateChain = async ({}};-/**- * RFC 5280 4.2.1.12: an Extended Key Usage extension is the exhaustive list of purposes its- * certificate may be used for. Without this check a leaf issued for serverAuth or codeSigning- * authenticates an identity, so anyone holding a server certificate under the configured CA can- * impersonate the machine identity pinned to it.- *- * A certificate that omits the extension is unconstrained and stays accepted, which is how OpenSSL- * and Go read a missing EKU and what keeps existing leaves that carry no EKU working. Only a- * certificate that explicitly enumerates purposes and leaves client authentication out is rejected.- */-export const permitsClientAuth = (cert: TNativeX509): boolean => {- const usages = new x509.X509Certificate(cert.raw).getExtension(x509.ExtendedKeyUsageExtension)?.usages;- if (!usages) return true;- return usages.some((oid) => oid === CLIENT_AUTH_EKU_OID || oid === ANY_PURPOSE_EKU_OID);-};-export const parseSubjectDetails = (data?: string | null) => {const values: Record<string, string> = {};if (!data) return values;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 02c39b5526..4914926b98 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@@ -62,6 +62,8 @@ const CHAIN_FAILURE_MESSAGES: Record<ca_verification_failed: "Access denied: Certificate chain could not be validated against the provided CA.",certificate_expired: "Access denied: A certificate in the chain is outside its validity period.",certificate_not_yet_valid: "Access denied: A certificate in the chain is outside its validity period.",+ issuer_client_auth_usage_not_allowed:+ "Access denied: A CA in the certificate chain is not permitted to issue client authentication certificates.",name_constraint_violation:"Access denied: The client certificate's name is outside the namespace its issuing CA is permitted to certify.",path_length_exceeded: "Access denied: The certificate chain has more intermediate CAs than a CA in it permits."@@ -188,6 +190,18 @@ export const identityTlsCertAuthServiceFactory = ({identityName: identity.name}});++ if (!permitsClientAuth(caCertificateX509)) {+ throw new UnauthorizedError({+ message: CHAIN_FAILURE_MESSAGES.issuer_client_auth_usage_not_allowed,+ detail: {+ reasonCode: "issuer_client_auth_usage_not_allowed",+ identityId: identity.id,+ orgId: identity.orgId,+ identityName: identity.name+ }+ });+ }}// Require an end-entity certificate issued by the configured CA, not the CA certificatediff --git a/docs/documentation/platform/identities/tls-cert-auth.mdx b/docs/documentation/platform/identities/tls-cert-auth.mdxindex 82b89eeb5a..5019719339 100644--- a/docs/documentation/platform/identities/tls-cert-auth.mdx+++ b/docs/documentation/platform/identities/tls-cert-auth.mdx@@ -93,8 +93,8 @@ Now create a new TLS Certificate Auth Method.Here's some information about each field:-- **CA Certificate:** A PEM encoded CA Certificate used to validate incoming TLS request client certificate.-- **Verify Client Certificate Chain (default is disabled):** By default, the CA Certificate must be the **direct issuer** of the client's leaf certificate. Enable this to instead treat the CA Certificate as a **trust anchor** and accept any client whose presented chain (leaf followed by intermediates) builds a valid path up to it. This is helpful when the issuing intermediate rotates beneath a long-lived root, such as a **SPIRE X.509-SVID**: you can pin the stable root here once and let the workload present its current intermediate alongside its leaf, rather than updating the CA Certificate on every rotation. Either way the trust anchor is the only certificate trusted, the client certificate must still be an end-entity certificate, and the Common Name and Subject Alternative Name checks below still apply to the leaf. Restrictions that the CAs on the path place on their subordinates are honored: a client certificate whose name falls outside an issuing CA's name constraints is rejected, as is a chain with more intermediates than a CA's path length permits.+- **CA Certificate:** A PEM encoded CA Certificate used to validate incoming TLS request client certificate. Both the CA Certificate and the client certificate must permit client authentication: a certificate that lists an Extended Key Usage without `clientAuth` (or `anyExtendedKeyUsage`) is rejected, since a CA's key usages also limit what the certificates beneath it may be used for. A certificate that lists no Extended Key Usage is unrestricted and is accepted.+- **Verify Client Certificate Chain (default is disabled):** By default, the CA Certificate must be the **direct issuer** of the client's leaf certificate. Enable this to instead treat the CA Certificate as a **trust anchor** and accept any client whose presented chain (leaf followed by intermediates) builds a valid path up to it. This is helpful when the issuing intermediate rotates beneath a long-lived root, such as a **SPIRE X.509-SVID**: you can pin the stable root here once and let the workload present its current intermediate alongside its leaf, rather than updating the CA Certificate on every rotation. Either way the trust anchor is the only certificate trusted, the client certificate must still be an end-entity certificate, and the Common Name and Subject Alternative Name checks below still apply to the leaf. Restrictions that the CAs on the path place on their subordinates are honored: a client certificate whose name falls outside an issuing CA's name constraints is rejected, as is a chain with more intermediates than a CA's path length permits, or one that passes through a CA whose Extended Key Usage does not permit client authentication.- **Allowed Common Names:** A comma separated list of client certificate common names allowed.- **Allowed Subject Alternative Names:** A comma separated list of client certificate subject alternative names (SANs) allowed. This is useful when the client certificate carries its identity in a SAN rather than the Subject Common Name, such as a SPIFFE X.509-SVID whose identity is a URI SAN (`spiffe://trust-domain/path`) with an empty Subject. Matching is type-aware, so an entry only matches a SAN of the same type:- **Type-prefixed entries** are matched against the corresponding SAN type, e.g. `URI:spiffe://example.org/svc`, `IP:10.0.0.1`, `EMAIL:[email protected]`.