Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Add SAN validation for workload identity

Carlos Monastyrski6cd81ae22e1d
diff --git a/backend/src/db/migrations/20260619120000_add-allowed-subject-alt-names-to-identity-tls-cert-auth.ts b/backend/src/db/migrations/20260619120000_add-allowed-subject-alt-names-to-identity-tls-cert-auth.ts
new file mode 100644
index 0000000000..cfa66fb746
--- /dev/null
+++ b/backend/src/db/migrations/20260619120000_add-allowed-subject-alt-names-to-identity-tls-cert-auth.ts
@@ -0,0 +1,21 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+export async function up(knex: Knex): Promise<void> {
+ const hasColumn = await knex.schema.hasColumn(TableName.IdentityTlsCertAuth, "allowedSubjectAltNames");
+ if (!hasColumn) {
+ await knex.schema.alterTable(TableName.IdentityTlsCertAuth, (t) => {
+ t.text("allowedSubjectAltNames").nullable();
+ });
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ const hasColumn = await knex.schema.hasColumn(TableName.IdentityTlsCertAuth, "allowedSubjectAltNames");
+ if (hasColumn) {
+ await knex.schema.alterTable(TableName.IdentityTlsCertAuth, (t) => {
+ t.dropColumn("allowedSubjectAltNames");
+ });
+ }
+}
diff --git a/backend/src/db/sanitized-schema.yaml b/backend/src/db/sanitized-schema.yaml
index a46c75c2f0..f5d05dd316 100644
--- a/backend/src/db/sanitized-schema.yaml
+++ b/backend/src/db/sanitized-schema.yaml
@@ -463,6 +463,7 @@ tables:
- updatedAt
- identityId
- allowedCommonNames
+ - allowedSubjectAltNames
- name: identity_token_auths
source: public.identity_token_auths
diff --git a/backend/src/db/schemas/identity-tls-cert-auths.ts b/backend/src/db/schemas/identity-tls-cert-auths.ts
index c907ead733..4fb15491b4 100644
--- a/backend/src/db/schemas/identity-tls-cert-auths.ts
+++ b/backend/src/db/schemas/identity-tls-cert-auths.ts
@@ -19,6 +19,7 @@ export const IdentityTlsCertAuthsSchema = z.object({
updatedAt: z.date(),
identityId: z.string().uuid(),
allowedCommonNames: z.string().nullable().optional(),
+ allowedSubjectAltNames: z.string().nullable().optional(),
encryptedCaCertificate: zodBuffer
});
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index e287fc1deb..fd6666b920 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -1899,6 +1899,7 @@ interface AddIdentityTlsCertAuthEvent {
metadata: {
identityId: string;
allowedCommonNames: string | null | undefined;
+ allowedSubjectAltNames: string | null | undefined;
accessTokenTTL: number;
accessTokenMaxTTL: number;
accessTokenNumUsesLimit: number;
@@ -1918,6 +1919,7 @@ interface UpdateIdentityTlsCertAuthEvent {
metadata: {
identityId: string;
allowedCommonNames: string | null | undefined;
+ allowedSubjectAltNames: string | null | undefined;
accessTokenTTL?: number;
accessTokenMaxTTL?: number;
accessTokenNumUsesLimit?: number;
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 28f9bd966c..bbd01e7d8c 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -417,6 +417,8 @@ export const TLS_CERT_AUTH = {
identityId: "The ID of the machine identity to attach the configuration onto.",
allowedCommonNames:
"The comma-separated list of trusted common names that are allowed to authenticate with Infisical.",
+ allowedSubjectAltNames:
+ "The comma-separated list of trusted subject alternative names that are allowed to authenticate with Infisical. Prefix entries by type (URI:, DNS:, IP:, EMAIL:). Bare entries are treated as DNS names.",
caCertificate: "The PEM-encoded CA certificate to validate client certificates.",
accessTokenTTL: "The lifetime for an access token in seconds.",
accessTokenMaxTTL: "The maximum lifetime for an access token in seconds.",
@@ -427,6 +429,8 @@ export const TLS_CERT_AUTH = {
identityId: "The ID of the machine identity to update the auth method for.",
allowedCommonNames:
"The comma-separated list of trusted common names that are allowed to authenticate with Infisical.",
+ allowedSubjectAltNames:
+ "The comma-separated list of trusted subject alternative names that are allowed to authenticate with Infisical. Prefix entries by type (URI:, DNS:, IP:, EMAIL:). Bare entries are treated as DNS names.",
caCertificate: "The PEM-encoded CA certificate to validate client certificates.",
accessTokenTTL: "The new lifetime for an access token in seconds.",
accessTokenMaxTTL: "The new maximum lifetime for an access token in seconds.",
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.ts
index 572951b4e6..c67ffc619a 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
@@ -13,6 +13,7 @@ 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 { TIdentityTrustedIp } from "@app/services/identity/identity-types";
+import { isValidAllowedSubjectAltNameEntry } from "@app/services/identity-tls-cert-auth/identity-tls-cert-auth-fns";
import { isSuperAdmin } from "@app/services/super-admin/super-admin-fns";
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
@@ -27,6 +28,34 @@ const validateCommonNames = z
.join(",")
);
+const validateSubjectAltNames = z
+ .string()
+ .min(1)
+ .trim()
+ .superRefine((val, ctx) => {
+ const invalidEntries = val
+ .split(",")
+ .map((i) => i.trim())
+ .filter(Boolean)
+ .filter((entry) => !isValidAllowedSubjectAltNameEntry(entry));
+
+ if (invalidEntries.length) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: `Invalid subject alternative name ${
+ invalidEntries.length > 1 ? "entries" : "entry"
+ }: ${invalidEntries.join(", ")}. Prefix non-DNS values with their type (e.g. "URI:spiffe://...", "IP:10.0.0.1", "EMAIL:[email protected]").`
+ });
+ }
+ })
+ .transform((el) =>
+ el
+ .split(",")
+ .map((i) => i.trim())
+ .filter(Boolean)
+ .join(",")
+ );
+
const validateCaCertificate = (caCert: string) => {
if (!caCert) return true;
try {
@@ -176,6 +205,10 @@ export const registerIdentityTlsCertAuthRouter = async (server: FastifyZodProvid
.optional()
.nullable()
.describe(TLS_CERT_AUTH.ATTACH.allowedCommonNames),
+ allowedSubjectAltNames: validateSubjectAltNames
+ .optional()
+ .nullable()
+ .describe(TLS_CERT_AUTH.ATTACH.allowedSubjectAltNames),
caCertificate: z
.string()
.min(1)
@@ -240,6 +273,7 @@ export const registerIdentityTlsCertAuthRouter = async (server: FastifyZodProvid
metadata: {
identityId: identityTlsCertAuth.identityId,
allowedCommonNames: identityTlsCertAuth.allowedCommonNames,
+ allowedSubjectAltNames: identityTlsCertAuth.allowedSubjectAltNames,
accessTokenTTL: identityTlsCertAuth.accessTokenTTL,
accessTokenMaxTTL: identityTlsCertAuth.accessTokenMaxTTL,
accessTokenTrustedIps: identityTlsCertAuth.accessTokenTrustedIps as TIdentityTrustedIp[],
@@ -300,6 +334,10 @@ export const registerIdentityTlsCertAuthRouter = async (server: FastifyZodProvid
.optional()
.nullable()
.describe(TLS_CERT_AUTH.UPDATE.allowedCommonNames),
+ allowedSubjectAltNames: validateSubjectAltNames
+ .optional()
+ .nullable()
+ .describe(TLS_CERT_AUTH.UPDATE.allowedSubjectAltNames),
accessTokenTrustedIps: z
.object({
ipAddress: z.string().trim()
@@ -357,6 +395,7 @@ export const registerIdentityTlsCertAuthRouter = async (server: FastifyZodProvid
metadata: {
identityId: identityTlsCertAuth.identityId,
allowedCommonNames: identityTlsCertAuth.allowedCommonNames,
+ allowedSubjectAltNames: identityTlsCertAuth.allowedSubjectAltNames,
accessTokenTTL: identityTlsCertAuth.accessTokenTTL,
accessTokenMaxTTL: identityTlsCertAuth.accessTokenMaxTTL,
accessTokenTrustedIps: identityTlsCertAuth.accessTokenTrustedIps as TIdentityTrustedIp[],
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.ts
new file mode 100644
index 0000000000..a0c503066e
--- /dev/null
+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts
@@ -0,0 +1,226 @@
+import { describe, expect, test } from "vitest";
+
+import {
+ isSubjectAltNameAllowed,
+ isValidAllowedSubjectAltNameEntry,
+ normalizeAllowedSubjectAltName,
+ parseCertificateSubjectAltNames,
+ parseSubjectDetails,
+ TCertificateSanItem
+} from "./identity-tls-cert-auth-fns";
+
+describe("parseSubjectDetails", () => {
+ test("parses a single CN field", () => {
+ expect(parseSubjectDetails("CN=my-service")).toEqual({ CN: "my-service" });
+ });
+
+ test("parses multiple newline-separated fields", () => {
+ expect(parseSubjectDetails("CN=svc\nO=MyOrg\nC=US")).toEqual({ CN: "svc", O: "MyOrg", C: "US" });
+ });
+
+ test("trims whitespace around key and value", () => {
+ expect(parseSubjectDetails("CN = svc\nO = MyOrg")).toEqual({ CN: "svc", O: "MyOrg" });
+ });
+
+ test("preserves values that contain an equals sign", () => {
+ expect(parseSubjectDetails("CN=a=b=c")).toEqual({ CN: "a=b=c" });
+ });
+
+ test("returns empty object for empty string", () => {
+ expect(parseSubjectDetails("")).toEqual({});
+ });
+
+ test("returns empty object for undefined/null (cert with empty Subject, e.g. SPIFFE SVID)", () => {
+ expect(parseSubjectDetails(undefined)).toEqual({});
+ expect(parseSubjectDetails(null)).toEqual({});
+ });
+
+ test("skips lines missing an equals sign", () => {
+ expect(parseSubjectDetails("CN=svc\nmalformed")).toEqual({ CN: "svc" });
+ });
+});
+
+describe("parseCertificateSubjectAltNames", () => {
+ test("returns empty array for undefined input", () => {
+ expect(parseCertificateSubjectAltNames(undefined)).toEqual([]);
+ });
+
+ test("returns empty array for empty input", () => {
+ expect(parseCertificateSubjectAltNames([])).toEqual([]);
+ });
+
+ test("maps a URI SAN (peculiar 'url' type) to a canonical uri token", () => {
+ expect(parseCertificateSubjectAltNames([{ type: "url", value: "spiffe://example.org/svc" }])).toEqual([
+ "uri:spiffe://example.org/svc"
+ ]);
+ });
+
+ test("lower-cases DNS SAN values (case-insensitive per RFC 5280)", () => {
+ expect(parseCertificateSubjectAltNames([{ type: "dns", value: "SVC.EXAMPLE.COM" }])).toEqual([
+ "dns:svc.example.com"
+ ]);
+ });
+
+ test("preserves IP SAN values", () => {
+ expect(parseCertificateSubjectAltNames([{ type: "ip", value: "10.0.0.1" }])).toEqual(["ip:10.0.0.1"]);
+ });
+
+ test("does not lower-case URI SAN values", () => {
+ expect(parseCertificateSubjectAltNames([{ type: "url", value: "spiffe://example.org/MyService" }])).toEqual([
+ "uri:spiffe://example.org/MyService"
+ ]);
+ });
+
+ test("handles multiple SANs of mixed types", () => {
+ const items: TCertificateSanItem[] = [
+ { type: "dns", value: "svc.example.com" },
+ { type: "url", value: "spiffe://example.org/svc" },
+ { type: "ip", value: "10.0.0.1" }
+ ];
+ expect(parseCertificateSubjectAltNames(items)).toEqual([
+ "dns:svc.example.com",
+ "uri:spiffe://example.org/svc",
+ "ip:10.0.0.1"
+ ]);
+ });
+
+ test("skips unsupported SAN types (dn, guid, upn, registeredId)", () => {
+ const items: TCertificateSanItem[] = [
+ { type: "guid", value: "{00000000-0000-0000-0000-000000000000}" },
+ { type: "dns", value: "svc.example.com" }
+ ];
+ expect(parseCertificateSubjectAltNames(items)).toEqual(["dns:svc.example.com"]);
+ });
+
+ test("preserves URI values containing commas (no naive string split)", () => {
+ expect(parseCertificateSubjectAltNames([{ type: "url", value: "spiffe://example.org/a,b" }])).toEqual([
+ "uri:spiffe://example.org/a,b"
+ ]);
+ });
+
+ test("lower-cases only the domain part of an email SAN (RFC 5321 local-part is case-sensitive)", () => {
+ expect(parseCertificateSubjectAltNames([{ type: "email", value: "[email protected]" }])).toEqual([
+ ]);
+ });
+});
+
+describe("isValidAllowedSubjectAltNameEntry", () => {
+ test("accepts a bare DNS name", () => {
+ expect(isValidAllowedSubjectAltNameEntry("svc.example.com")).toBe(true);
+ });
+
+ test("accepts recognized type-prefixed entries", () => {
+ expect(isValidAllowedSubjectAltNameEntry("URI:spiffe://example.org/svc")).toBe(true);
+ expect(isValidAllowedSubjectAltNameEntry("IP:2001:db8::1")).toBe(true);
+ expect(isValidAllowedSubjectAltNameEntry("EMAIL:[email protected]")).toBe(true);
+ expect(isValidAllowedSubjectAltNameEntry("URL:spiffe://example.org/svc")).toBe(true);
+ });
+
+ test("rejects a bare URI missing its type prefix", () => {
+ expect(isValidAllowedSubjectAltNameEntry("spiffe://example.org/svc")).toBe(false);
+ });
+
+ test("rejects a bare IPv6 missing its type prefix", () => {
+ expect(isValidAllowedSubjectAltNameEntry("2001:db8::1")).toBe(false);
+ });
+
+ test("rejects an empty entry", () => {
+ expect(isValidAllowedSubjectAltNameEntry(" ")).toBe(false);
+ });
+});
+
+describe("normalizeAllowedSubjectAltName", () => {
+ test("returns null for an empty entry", () => {
+ expect(normalizeAllowedSubjectAltName("")).toBeNull();
+ expect(normalizeAllowedSubjectAltName(" ")).toBeNull();
+ });
+
+ test("defaults a bare value to a DNS SAN", () => {
+ expect(normalizeAllowedSubjectAltName("svc.example.com")).toEqual("dns:svc.example.com");
+ });
+
+ test("lower-cases a bare DNS value", () => {
+ expect(normalizeAllowedSubjectAltName("SVC.Example.COM")).toEqual("dns:svc.example.com");
+ });
+
+ test("keeps a type-prefixed URI entry", () => {
+ expect(normalizeAllowedSubjectAltName("URI:spiffe://example.org/svc")).toEqual("uri:spiffe://example.org/svc");
+ });
+
+ test("accepts URL: as an alias for URI:", () => {
+ expect(normalizeAllowedSubjectAltName("URL:spiffe://example.org/svc")).toEqual("uri:spiffe://example.org/svc");
+ });
+
+ test("normalizes an IP-prefixed entry", () => {
+ expect(normalizeAllowedSubjectAltName("IP:10.0.0.1")).toEqual("ip:10.0.0.1");
+ });
+
+ test("treats an unrecognized prefix as part of a bare DNS value", () => {
+ // A bare URI without a recognized prefix becomes a DNS entry that cannot match a URI SAN.
+ expect(normalizeAllowedSubjectAltName("spiffe://example.org/svc")).toEqual("dns:spiffe://example.org/svc");
+ });
+});
+
+describe("isSubjectAltNameAllowed", () => {
+ test("matches a type-prefixed allow-list entry against the certificate", () => {
+ expect(
+ isSubjectAltNameAllowed("URI:spiffe://example.org/svc", [{ type: "url", value: "spiffe://example.org/svc" }])
+ ).toBe(true);
+ });
+
+ test("matches a bare DNS allow-list entry against a DNS SAN", () => {
+ expect(isSubjectAltNameAllowed("svc.example.com", [{ type: "dns", value: "svc.example.com" }])).toBe(true);
+ });
+
+ test("matches DNS SANs case-insensitively", () => {
+ expect(isSubjectAltNameAllowed("svc.example.com", [{ type: "dns", value: "SVC.EXAMPLE.COM" }])).toBe(true);
+ });
+
+ test("matches email SAN domain case-insensitively but local-part case-sensitively", () => {
+ // domain casing differs -> still matches
+ expect(isSubjectAltNameAllowed("EMAIL:[email protected]", [{ type: "email", value: "[email protected]" }])).toBe(true);
+ // local-part casing differs -> must NOT match
+ expect(isSubjectAltNameAllowed("EMAIL:[email protected]", [{ type: "email", value: "[email protected]" }])).toBe(false);
+ });
+
+ test("does not conflate SAN types (bare value defaults to DNS and must not match a URI SAN)", () => {
+ expect(
+ isSubjectAltNameAllowed("spiffe://example.org/svc", [{ type: "url", value: "spiffe://example.org/svc" }])
+ ).toBe(false);
+ });
+
+ test("does not match a same-string SAN of a different type", () => {
+ // Allow-list wants a URI SAN; a DNS SAN with the same string must not pass.
+ expect(
+ isSubjectAltNameAllowed("URI:spiffe://example.org/svc", [{ type: "dns", value: "spiffe://example.org/svc" }])
+ ).toBe(false);
+ });
+
+ test("matches when any one of several allow-list entries is satisfied", () => {
+ expect(
+ isSubjectAltNameAllowed("URI:spiffe://example.org/other, svc.example.com", [
+ { type: "dns", value: "svc.example.com" }
+ ])
+ ).toBe(true);
+ });
+
+ test("returns false when no certificate SAN matches", () => {
+ expect(
+ isSubjectAltNameAllowed("URI:spiffe://example.org/svc", [{ type: "url", value: "spiffe://example.org/other" }])
+ ).toBe(false);
+ });
+
+ test("returns false when the certificate has no SANs", () => {
+ expect(isSubjectAltNameAllowed("svc.example.com", undefined)).toBe(false);
+ expect(isSubjectAltNameAllowed("svc.example.com", [])).toBe(false);
+ });
+
+ test("tolerates whitespace in the allow-list", () => {
+ expect(
+ isSubjectAltNameAllowed(" svc.example.com , URI:spiffe://example.org/svc ", [
+ { type: "dns", value: "svc.example.com" }
+ ])
+ ).toBe(true);
+ });
+});
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.ts
new file mode 100644
index 0000000000..4b5fefb2ad
--- /dev/null
+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts
@@ -0,0 +1,119 @@
+export const parseSubjectDetails = (data?: string | null) => {
+ const values: Record<string, string> = {};
+ if (!data) return values;
+ data.split("\n").forEach((el) => {
+ const eqIdx = el.indexOf("=");
+ if (eqIdx === -1) return;
+ const key = el.slice(0, eqIdx).trim();
+ // Slice on the first "=" only so values that themselves contain "=" are preserved.
+ const value = el.slice(eqIdx + 1).trim();
+ if (key && value) {
+ values[key] = value;
+ }
+ });
+ return values;
+};
+
+type CanonicalSanType = "dns" | "ip" | "email" | "uri";
+
+export type TCertificateSanItem = { type: string; value: string };
+
+const peculiarTypeToCanonical = (type: string): CanonicalSanType | null => {
+ switch (type.trim().toLowerCase()) {
+ case "dns":
+ return "dns";
+ case "ip":
+ return "ip";
+ case "email":
+ return "email";
+ // peculiar represents URI SANs (e.g. SPIFFE IDs) under the "url" type.
+ case "url":
+ return "uri";
+ default:
+ return null;
+ }
+};
+
+const allowedPrefixToCanonical = (prefix: string): CanonicalSanType | null => {
+ switch (prefix.trim().toLowerCase()) {
+ case "dns":
+ return "dns";
+ case "ip":
+ return "ip";
+ case "email":
+ return "email";
+ case "uri":
+ case "url":
+ return "uri";
+ default:
+ return null;
+ }
+};
+
+const normalizeSanValue = (type: CanonicalSanType, value: string): string => {
+ const trimmed = value.normalize("NFC").trim();
+ // DNS names are case-insensitive (RFC 5280).
+ if (type === "dns") return trimmed.toLowerCase();
+ // For email, only the domain part is case-insensitive (RFC 5321). Lowercasing the
+ // local-part would weaken the allow-list (it would accept addresses differing only in
+ // local-part casing), so preserve it and lowercase the domain only.
+ if (type === "email") {
+ const atIdx = trimmed.lastIndexOf("@");
+ if (atIdx === -1) return trimmed;
+ return `${trimmed.slice(0, atIdx)}@${trimmed.slice(atIdx + 1).toLowerCase()}`;
+ }
+ // URI and IP values are matched exactly.
+ return trimmed;
+};
+
+const toCanonicalSan = (type: CanonicalSanType, value: string): string => `${type}:${normalizeSanValue(type, value)}`;
+
+export const parseCertificateSubjectAltNames = (sanItems?: ReadonlyArray<TCertificateSanItem>): string[] => {
+ if (!sanItems) return [];
+ const tokens: string[] = [];
+ for (const item of sanItems) {
+ const type = peculiarTypeToCanonical(item.type);
+ if (type && item.value.trim()) tokens.push(toCanonicalSan(type, item.value));
+ }
+ return tokens;
+};
+
+export const normalizeAllowedSubjectAltName = (allowedSan: string): string | null => {
+ const trimmed = allowedSan.trim();
+ if (!trimmed) return null;
+
+ const separatorIdx = trimmed.indexOf(":");
+ if (separatorIdx !== -1) {
+ const type = allowedPrefixToCanonical(trimmed.slice(0, separatorIdx));
+ if (type) {
+ return toCanonicalSan(type, trimmed.slice(separatorIdx + 1));
+ }
+ }
+
+ return toCanonicalSan("dns", trimmed);
+};
+
+export const isValidAllowedSubjectAltNameEntry = (entry: string): boolean => {
+ const trimmed = entry.trim();
+ if (!trimmed) return false;
+
+ const separatorIdx = trimmed.indexOf(":");
+ if (separatorIdx === -1) return true; // bare DNS name
+
+ // Has a colon: the text before the first colon must be a recognized type prefix.
+ return allowedPrefixToCanonical(trimmed.slice(0, separatorIdx)) !== null;
+};
+
+export const isSubjectAltNameAllowed = (
+ allowedSubjectAltNames: string,
+ certificateSanItems?: ReadonlyArray<TCertificateSanItem>
+): boolean => {
+ const certificateSans = new Set(parseCertificateSubjectAltNames(certificateSanItems));
+ if (certificateSans.size === 0) return false;
+
+ return allowedSubjectAltNames
+ .split(",")
+ .map(normalizeAllowedSubjectAltName)
+ .filter((san): san is string => san !== null)
+ .some((allowedSan) => certificateSans.has(allowedSan));
+};
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.ts
index 1b41681f43..2c7f1105c3 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
@@ -1,5 +1,6 @@
import { ForbiddenError, subject } from "@casl/ability";
import { requestContext } from "@fastify/request-context";
+import * as x509 from "@peculiar/x509";
import { AccessScope, ActionProjectType, IdentityAuthMethod, OrganizationActionScope } from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
@@ -41,6 +42,7 @@ import { TMembershipIdentityDALFactory } from "../membership-identity/membership
import { TOrgDALFactory } from "../org/org-dal";
import { validateIdentityUpdateForSuperAdminPrivileges } from "../super-admin/super-admin-fns";
import { TIdentityTlsCertAuthDALFactory } from "./identity-tls-cert-auth-dal";
+import { isSubjectAltNameAllowed, parseSubjectDetails } from "./identity-tls-cert-auth-fns";
import { TIdentityTlsCertAuthServiceFactory } from "./identity-tls-cert-auth-types";
type TIdentityTlsCertAuthServiceFactoryDep = {
@@ -61,17 +63,6 @@ type TIdentityTlsCertAuthServiceFactoryDep = {
>;
};
-const parseSubjectDetails = (data: string) => {
- const values: Record<string, string> = {};
- data.split("\n").forEach((el) => {
- const [key, value] = el.split("=");
- if (key && value) {
- values[key.trim()] = value.trim();
- }
- });
- return values;
-};
-
export const identityTlsCertAuthServiceFactory = ({
identityDAL,
identityAccessTokenDAL,
@@ -199,6 +190,28 @@ export const identityTlsCertAuthServiceFactory = ({
}
}
+ if (identityTlsCertAuth.allowedSubjectAltNames) {
+ const sanExtension = new x509.X509Certificate(leafCertificate).getExtension(
+ x509.SubjectAlternativeNameExtension
+ );
+
+ const isValidSubjectAltName = isSubjectAltNameAllowed(
+ identityTlsCertAuth.allowedSubjectAltNames,
+ sanExtension?.names.items
+ );
+ if (!isValidSubjectAltName) {
+ throw new UnauthorizedError({
+ message: "Access denied: TLS Certificate Auth subject alternative name not allowed.",
+ detail: {
+ reasonCode: "subject_alt_name_not_allowed",
+ identityId: identity.id,
+ orgId: identity.orgId,
+ identityName: identity.name
+ }
+ });
+ }
+ }
+
if (organizationSlug && org.slug !== organizationSlug) {
if (!isSubOrgIdentity) {
const subOrg = await orgDAL.findOne({ rootOrgId: org.id, slug: organizationSlug });
@@ -337,7 +350,8 @@ export const identityTlsCertAuthServiceFactory = ({
actorOrgId,
isActorSuperAdmin,
caCertificate,
- allowedCommonNames
+ allowedCommonNames,
+ allowedSubjectAltNames
}) => {
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
@@ -421,6 +435,7 @@ export const identityTlsCertAuthServiceFactory = ({
identityId: identityMembershipOrg.identity.id,
accessTokenMaxTTL,
allowedCommonNames,
+ allowedSubjectAltNames,
accessTokenTTL,
encryptedCaCertificate: encryptor({ plainText: Buffer.from(caCertificate) }).cipherTextBlob,
accessTokenNumUsesLimit,
@@ -437,6 +452,7 @@ export const identityTlsCertAuthServiceFactory = ({
identityId,
caCertificate,
allowedCommonNames,
+ allowedSubjectAltNames,
accessTokenTTL,
accessTokenMaxTTL,
accessTokenNumUsesLimit,
@@ -524,6 +540,7 @@ export const identityTlsCertAuthServiceFactory = ({
const updatedTlsCertAuth = await identityTlsCertAuthDAL.updateById(identityTlsCertAuth.id, {
allowedCommonNames,
+ allowedSubjectAltNames,
encryptedCaCertificate: caCertificate
? encryptor({ plainText: Buffer.from(caCertificate) }).cipherTextBlob
: undefined,
diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-types.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-types.ts
index b2b6d2b8a8..fb2bc5d2fc 100644
--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-types.ts
+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-types.ts
@@ -11,6 +11,7 @@ export type TAttachTlsCertAuthDTO = {
identityId: string;
caCertificate: string;
allowedCommonNames?: string | null;
+ allowedSubjectAltNames?: string | null;
accessTokenTTL: number;
accessTokenMaxTTL: number;
accessTokenNumUsesLimit: number;
@@ -22,6 +23,7 @@ export type TUpdateTlsCertAuthDTO = {
identityId: string;
caCertificate?: string;
allowedCommonNames?: string | null;
+ allowedSubjectAltNames?: string | null;
accessTokenTTL?: number;
accessTokenMaxTTL?: number;
accessTokenNumUsesLimit?: number;
diff --git a/docs/documentation/platform/identities/tls-cert-auth.mdx b/docs/documentation/platform/identities/tls-cert-auth.mdx
index f52ad3c518..12409218b0 100644
--- a/docs/documentation/platform/identities/tls-cert-auth.mdx
+++ b/docs/documentation/platform/identities/tls-cert-auth.mdx
@@ -35,7 +35,7 @@ To be more specific:
1. The client sends a TLS request with the client certificate to Infisical at the `/api/v1/auth/tls-cert-auth/login` endpoint.
2. Infisical verifies the incoming request using the provided CA certificate.
-3. Infisical checks the user's properties against set criteria such as Allowed Common Names.
+3. Infisical checks the user's properties against set criteria such as Allowed Common Names and Allowed Subject Alternative Names.
4. If all checks pass, Infisical returns a short-lived access token that the client can use to make authenticated requests to the Infisical API.
<Accordion title="TLS with Load Balancer/Proxy">
@@ -95,6 +95,11 @@ Here's some information about each field:
- **CA Certificate:** A PEM encoded CA Certificate used to validate incoming TLS request client certificate.
- **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]`.
+ - **Bare entries** (no prefix) are treated as **DNS** names, e.g. `svc.example.com`. DNS and email matching is case-insensitive; URI and IP values are matched exactly.
+
+ When both Allowed Common Names and Allowed Subject Alternative Names are set, the certificate must satisfy both checks. Leave empty to skip SAN validation.
- **Access Token TTL (default is `2592000` equivalent to 30 days):** The lifetime for an access token in seconds. This value will be referenced at renewal time.
- **Access Token Max TTL (default is `2592000` equivalent to 30 days):** The maximum lifetime for an access token in seconds. This value will be referenced at renewal time.
- **Access Token Max Number of Uses (default is `0`):** The maximum number of times that an access token can be used; a value of `0` implies an infinite number of uses.
diff --git a/frontend/src/hooks/api/identities/mutations.tsx b/frontend/src/hooks/api/identities/mutations.tsx
index 7fdeba7e52..c8fc689f05 100644
--- a/frontend/src/hooks/api/identities/mutations.tsx
+++ b/frontend/src/hooks/api/identities/mutations.tsx
@@ -801,6 +801,7 @@ export const useAddIdentityTlsCertAuth = () => {
mutationFn: async ({
identityId,
allowedCommonNames,
+ allowedSubjectAltNames,
caCertificate,
accessTokenTTL,
accessTokenMaxTTL,
@@ -813,6 +814,7 @@ export const useAddIdentityTlsCertAuth = () => {
`/api/v1/auth/tls-cert-auth/identities/${identityId}`,
{
allowedCommonNames,
+ allowedSubjectAltNames,
caCertificate,
accessTokenTTL,
accessTokenMaxTTL,
@@ -851,6 +853,7 @@ export const useUpdateIdentityTlsCertAuth = () => {
mutationFn: async ({
identityId,
allowedCommonNames,
+ allowedSubjectAltNames,
caCertificate,
accessTokenTTL,
accessTokenMaxTTL,
@@ -864,6 +867,7 @@ export const useUpdateIdentityTlsCertAuth = () => {
{
caCertificate,
allowedCommonNames,
+ allowedSubjectAltNames,
accessTokenTTL,
accessTokenMaxTTL,
accessTokenNumUsesLimit,
diff --git a/frontend/src/hooks/api/identities/types.ts b/frontend/src/hooks/api/identities/types.ts
index cde4250a6e..aa1b31904c 100644
--- a/frontend/src/hooks/api/identities/types.ts
+++ b/frontend/src/hooks/api/identities/types.ts
@@ -574,6 +574,7 @@ export type IdentityTlsCertAuth = {
identityId: string;
caCertificate: string;
allowedCommonNames: string;
+ allowedSubjectAltNames: string | null;
accessTokenTTL: number;
accessTokenMaxTTL: number;
accessTokenNumUsesLimit: number;
@@ -586,6 +587,7 @@ export type AddIdentityTlsCertAuthDTO = {
identityId: string;
caCertificate: string;
allowedCommonNames?: string;
+ allowedSubjectAltNames?: string;
accessTokenTTL: number;
accessTokenMaxTTL: number;
accessTokenNumUsesLimit: number;
@@ -600,6 +602,7 @@ export type UpdateIdentityTlsCertAuthDTO = {
identityId: string;
caCertificate: string;
allowedCommonNames?: string | null;
+ allowedSubjectAltNames?: string | null;
accessTokenTTL?: number;
accessTokenMaxTTL?: number;
accessTokenNumUsesLimit?: number;
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.tsx
index 67344e070f..b11c193b22 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
@@ -46,6 +46,7 @@ const buildSchema = (maxAccessTokenTTL: number) =>
z
.object({
allowedCommonNames: z.string().optional(),
+ allowedSubjectAltNames: z.string().optional(),
caCertificate: z.string().min(1),
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
@@ -117,6 +118,7 @@ export const IdentityTlsCertAuthForm = ({
reset({
caCertificate: data.caCertificate,
allowedCommonNames: data.allowedCommonNames || undefined,
+ allowedSubjectAltNames: data.allowedSubjectAltNames || undefined,
accessTokenTTL: String(data.accessTokenTTL),
accessTokenMaxTTL: String(data.accessTokenMaxTTL),
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
@@ -142,6 +144,7 @@ export const IdentityTlsCertAuthForm = ({
const onFormSubmit = async ({
caCertificate,
allowedCommonNames,
+ allowedSubjectAltNames,
accessTokenTTL,
accessTokenMaxTTL,
accessTokenNumUsesLimit,
@@ -154,6 +157,7 @@ export const IdentityTlsCertAuthForm = ({
...(projectId ? { projectId } : { organizationId: orgId }),
caCertificate,
allowedCommonNames: allowedCommonNames || null,
+ allowedSubjectAltNames: allowedSubjectAltNames || null,
identityId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
@@ -166,6 +170,7 @@ export const IdentityTlsCertAuthForm = ({
identityId,
caCertificate,
allowedCommonNames: allowedCommonNames || undefined,
+ allowedSubjectAltNames: allowedSubjectAltNames || undefined,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit || "0"),
@@ -245,6 +250,39 @@ export const IdentityTlsCertAuthForm = ({
</Field>
)}
/>
+
+ <Controller
+ control={control}
+ defaultValue=""
+ name="allowedSubjectAltNames"
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel
+ htmlFor="allowedSubjectAltNames"
+ className="inline-flex items-center gap-1.5"
+ >
+ Allowed Subject Alternative Names (optional)
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <InfoIcon className="size-3.5 text-muted" />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-md">
+ Comma separated subject alternative names allowed to authenticate against
+ the identity. Prefix entries by type (URI:, DNS:, IP:, EMAIL:). Bare entries
+ are treated as DNS names. Leave empty to skip SAN validation.
+ </TooltipContent>
+ </Tooltip>
+ </FieldLabel>
+ <Input
+ {...field}
+ id="allowedSubjectAltNames"
+ type="text"
+ isError={Boolean(error)}
+ />
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ )}
+ />
<AccessTokenTtlFields control={control} maxAccessTokenTTL={maxAccessTokenTTL} />
<AccessTokenNumUsesLimitField control={control} />
</FieldGroup>
diff --git a/frontend/src/views/IdentityAuthMethods/content/IdentityTlsCertAuthContent.tsx b/frontend/src/views/IdentityAuthMethods/content/IdentityTlsCertAuthContent.tsx
index 8faefc0f6e..62365e4c3b 100644
--- a/frontend/src/views/IdentityAuthMethods/content/IdentityTlsCertAuthContent.tsx
+++ b/frontend/src/views/IdentityAuthMethods/content/IdentityTlsCertAuthContent.tsx
@@ -65,6 +65,12 @@ export const IdentityTlsCertAuthContent = ({ identityId }: ViewAuthMethodProps)
.map((cn) => cn.trim())
.join(", ")}
</IdentityAuthFieldDisplay>
+ <IdentityAuthFieldDisplay className="col-span-2" label="Allowed Subject Alternative Names">
+ {data.allowedSubjectAltNames
+ ?.split(",")
+ .map((san) => san.trim())
+ .join(", ")}
+ </IdentityAuthFieldDisplay>
</div>
);
};