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
feat(pki): support wildcard DNS identifiers in ACME (#6565)
Saif Ur Rahman3a77744d200c
diff --git a/backend/src/db/migrations/20260519144500_add-wildcard-to-pki-acme-auths.ts b/backend/src/db/migrations/20260519144500_add-wildcard-to-pki-acme-auths.tsnew file mode 100644index 0000000000..f0483b2d29--- /dev/null+++ b/backend/src/db/migrations/20260519144500_add-wildcard-to-pki-acme-auths.ts@@ -0,0 +1,19 @@+import { Knex } from "knex";++import { TableName } from "../schemas";++export async function up(knex: Knex): Promise<void> {+ if (!(await knex.schema.hasColumn(TableName.PkiAcmeAuth, "wildcard"))) {+ await knex.schema.alterTable(TableName.PkiAcmeAuth, (t) => {+ t.boolean("wildcard").notNullable().defaultTo(false);+ });+ }+}++export async function down(knex: Knex): Promise<void> {+ if (await knex.schema.hasColumn(TableName.PkiAcmeAuth, "wildcard")) {+ await knex.schema.alterTable(TableName.PkiAcmeAuth, (t) => {+ t.dropColumn("wildcard");+ });+ }+}diff --git a/backend/src/db/schemas/pki-acme-auths.ts b/backend/src/db/schemas/pki-acme-auths.tsindex 7f20e0f24d..51fab740f6 100644--- a/backend/src/db/schemas/pki-acme-auths.ts+++ b/backend/src/db/schemas/pki-acme-auths.ts@@ -17,7 +17,8 @@ export const PkiAcmeAuthsSchema = z.object({expiresAt: z.date(),certificateId: z.string().uuid().nullable().optional(),createdAt: z.date(),- updatedAt: z.date()+ updatedAt: z.date(),+ wildcard: z.boolean().default(false)});export type TPkiAcmeAuths = z.infer<typeof PkiAcmeAuthsSchema>;diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 2694585cb9..af3a2c4552 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -6396,6 +6396,7 @@ interface CreateAcmeOrderEvent {identifiers: Array<{type: AcmeIdentifierType;value: string;+ wildcard?: boolean;}>;};}diff --git a/backend/src/ee/services/pki-acme/pki-acme-fns.test.ts b/backend/src/ee/services/pki-acme/pki-acme-fns.test.tsnew file mode 100644index 0000000000..1c6d00ea83--- /dev/null+++ b/backend/src/ee/services/pki-acme/pki-acme-fns.test.ts@@ -0,0 +1,30 @@+import { validateDnsIdentifier } from "./pki-acme-fns";++describe("validateDnsIdentifier", () => {+ test("accepts standard domain names", () => {+ expect(validateDnsIdentifier("example.com")).toBe(true);+ expect(validateDnsIdentifier("sub.example.com")).toBe(true);+ expect(validateDnsIdentifier("deep.sub.example.com")).toBe(true);+ expect(validateDnsIdentifier("a.b")).toBe(true);+ });++ test("accepts wildcard prefixes", () => {+ expect(validateDnsIdentifier("*.example.com")).toBe(true);+ expect(validateDnsIdentifier("*.sub.example.com")).toBe(true);+ });++ test("rejects invalid wildcard forms", () => {+ expect(validateDnsIdentifier("**.example.com")).toBe(false);+ expect(validateDnsIdentifier("a*.example.com")).toBe(false);+ expect(validateDnsIdentifier("*a.example.com")).toBe(false);+ expect(validateDnsIdentifier("*")).toBe(false);+ expect(validateDnsIdentifier("*.")).toBe(false);+ expect(validateDnsIdentifier("sub.*.example.com")).toBe(false);+ });++ test("rejects invalid domain labels", () => {+ expect(validateDnsIdentifier("-example.com")).toBe(false);+ expect(validateDnsIdentifier("example-.com")).toBe(false);+ expect(validateDnsIdentifier("")).toBe(false);+ });+});diff --git a/backend/src/ee/services/pki-acme/pki-acme-fns.ts b/backend/src/ee/services/pki-acme/pki-acme-fns.tsindex 537149ffd6..5f47077265 100644--- a/backend/src/ee/services/pki-acme/pki-acme-fns.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-fns.ts@@ -28,8 +28,18 @@ export const validateIpIdentifier = (identifier: string): boolean => {};export const validateDnsIdentifier = (identifier: string): boolean => {- // DNS label pattern: 1-63 chars, alphanumeric or hyphen, but not starting or ending with hyphen+ let domain = identifier;++ if (domain.startsWith("*.")) {+ domain = domain.slice(2);+ if (domain.length === 0) {+ return false;+ }+ } else if (domain.includes("*")) {+ return false;+ }+const labelPattern = new RE2(/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$/);- const labels = identifier.split(".");+ const labels = domain.split(".");return labels.every((label) => label.length >= 1 && label.length <= 63 && labelPattern.test(label));};diff --git a/backend/src/ee/services/pki-acme/pki-acme-order-dal.ts b/backend/src/ee/services/pki-acme/pki-acme-order-dal.tsindex cf7d96e876..97d37ff9c5 100644--- a/backend/src/ee/services/pki-acme/pki-acme-order-dal.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-order-dal.ts@@ -67,6 +67,7 @@ export const pkiAcmeOrderDALFactory = (db: TDbClient) => {db.ref("id").withSchema(TableName.PkiAcmeAuth).as("authId"),db.ref("identifierType").withSchema(TableName.PkiAcmeAuth).as("identifierType"),db.ref("identifierValue").withSchema(TableName.PkiAcmeAuth).as("identifierValue"),+ db.ref("wildcard").withSchema(TableName.PkiAcmeAuth).as("wildcard"),db.ref("expiresAt").withSchema(TableName.PkiAcmeAuth).as("authExpiresAt")).where(`${TableName.PkiAcmeOrder}.id`, orderId)@@ -84,10 +85,11 @@ export const pkiAcmeOrderDALFactory = (db: TDbClient) => {{key: "authId",label: "authorizations" as const,- mapper: ({ authId, identifierType, identifierValue, authExpiresAt }) => ({+ mapper: ({ authId, identifierType, identifierValue, wildcard, authExpiresAt }) => ({id: authId,identifierType,identifierValue,+ wildcard: wildcard as boolean,expiresAt: authExpiresAt})}diff --git a/backend/src/ee/services/pki-acme/pki-acme-schemas.ts b/backend/src/ee/services/pki-acme/pki-acme-schemas.tsindex f2c7760d15..8eb756b6e4 100644--- a/backend/src/ee/services/pki-acme/pki-acme-schemas.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-schemas.ts@@ -148,6 +148,7 @@ export const GetAcmeAuthorizationResponseSchema = z.object({type: z.string(),value: z.string()}),+ wildcard: z.boolean().optional(),challenges: z.array(z.object({type: z.enum(Object.values(AcmeChallengeType) as [string, ...string[]]),diff --git a/backend/src/ee/services/pki-acme/pki-acme-service.ts b/backend/src/ee/services/pki-acme/pki-acme-service.tsindex eab6ce38b7..62810349b3 100644--- a/backend/src/ee/services/pki-acme/pki-acme-service.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts@@ -378,6 +378,7 @@ export const pkiAcmeServiceFactory = ({id: string;identifierType: string;identifierValue: string;+ wildcard?: boolean;expiresAt: Date;}[];};@@ -390,7 +391,7 @@ export const pkiAcmeServiceFactory = ({notAfter: order.notAfter?.toISOString(),identifiers: order.authorizations.map((auth) => ({type: auth.identifierType,- value: auth.identifierValue+ value: auth.wildcard ? `*.${auth.identifierValue}` : auth.identifierValue})),authorizations: order.authorizations.map((auth) => buildUrl(profileId, `/authorizations/${auth.id}`)),finalize: buildUrl(profileId, `/orders/${order.id}/finalize`),@@ -746,10 +747,13 @@ export const pkiAcmeServiceFactory = ({// TODO: ideally, we should return an error with subproblems if we have multiple unsupported identifiersfor (const identifier of payload.identifiers) {if (identifier.type === AcmeIdentifierType.DNS) {+ if (!validateDnsIdentifier(identifier.value)) {+ throw new AcmeUnsupportedIdentifierError({ message: "Invalid DNS identifier" });+ }+ const strippedValue = identifier.value.startsWith("*.") ? identifier.value.slice(2) : identifier.value;if (- !validateDnsIdentifier(identifier.value) ||- isPrivateIp(identifier.value) ||- (!getConfig().isDevelopmentMode && identifier.value.toLowerCase() === "localhost")+ isPrivateIp(strippedValue) ||+ (!getConfig().isDevelopmentMode && strippedValue.toLowerCase() === "localhost")) {throw new AcmeUnsupportedIdentifierError({ message: "Invalid DNS identifier" });}@@ -791,18 +795,23 @@ export const pkiAcmeServiceFactory = ({});}} else if (identifier.type === AcmeIdentifierType.DNS) {- if (isPrivateIp(identifier.value)) {+ const stripped = identifier.value.startsWith("*.") ? identifier.value.slice(2) : identifier.value;+ if (isPrivateIp(stripped)) {throw new AcmeUnsupportedIdentifierError({ message: "Private IP addresses are not allowed" });}} else {throw new AcmeUnsupportedIdentifierError({ message: "Only DNS and IP identifiers are supported" });}+ const isWildcard = identifier.type === AcmeIdentifierType.DNS && identifier.value.startsWith("*.");+ const identifierValue = isWildcard ? identifier.value.slice(2) : identifier.value;+const auth = await acmeAuthDAL.create({accountId: account.id,status: skipDnsOwnershipVerification ? AcmeAuthStatus.Valid : AcmeAuthStatus.Pending,identifierType: identifier.type,- identifierValue: identifier.value,+ identifierValue,+ wildcard: isWildcard,// RFC 8555 suggests a token with at least 128 bits of entropy// We are using 256 bits of entropy here, should be enough for now// ref: https://datatracker.ietf.org/doc/html/rfc8555#section-11.3@@ -813,11 +822,14 @@ export const pkiAcmeServiceFactory = ({tx);if (!skipDnsOwnershipVerification) {- // IP identifiers only support HTTP-01 challenges (DNS-01 doesn't apply per RFC 8738)- const challengeTypes =- identifier.type === AcmeIdentifierType.IP- ? [AcmeChallengeType.HTTP_01]- : [AcmeChallengeType.HTTP_01, AcmeChallengeType.DNS_01];+ let challengeTypes: AcmeChallengeType[];+ if (identifier.type === AcmeIdentifierType.IP) {+ challengeTypes = [AcmeChallengeType.HTTP_01];+ } else if (isWildcard) {+ challengeTypes = [AcmeChallengeType.DNS_01];+ } else {+ challengeTypes = [AcmeChallengeType.HTTP_01, AcmeChallengeType.DNS_01];+ }for (const challengeType of challengeTypes) {// eslint-disable-next-line no-await-in-loopawait acmeChallengeDAL.create(@@ -857,7 +869,8 @@ export const pkiAcmeServiceFactory = ({orderId: createdOrder.id,identifiers: authorizations.map((auth) => ({type: auth.identifierType as AcmeIdentifierType,- value: auth.identifierValue+ value: auth.wildcard ? `*.${auth.identifierValue}` : auth.identifierValue,+ ...(auth.wildcard ? { wildcard: true } : {})}))}}@@ -1135,9 +1148,10 @@ export const pkiAcmeServiceFactory = ({}if (csrIdentifierPairs.size !== orderWithAuthorizations.authorizations.length ||- !orderWithAuthorizations.authorizations.every((auth) =>- csrIdentifierPairs.has(`${auth.identifierType}:${auth.identifierValue.toLowerCase()}`)- )+ !orderWithAuthorizations.authorizations.every((auth) => {+ const value = auth.wildcard ? `*.${auth.identifierValue}` : auth.identifierValue;+ return csrIdentifierPairs.has(`${auth.identifierType}:${value.toLowerCase()}`);+ })) {throw new AcmeBadCSRError({ message: "Invalid CSR: Common name + SANs mismatch with order identifiers" });}@@ -1531,6 +1545,7 @@ export const pkiAcmeServiceFactory = ({type: auth.identifierType,value: auth.identifierValue},+ ...(auth.wildcard ? { wildcard: true } : {}),challenges: auth.challenges.map((challenge) => {return {type: challenge.type,