Skip to content

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

Add PKI DNS CNAME Delegation support

Carlos Monastyrski531461cc8545
diff --git a/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts b/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts
index 9616b30903..f2b41c7b34 100644
--- a/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts
@@ -1,11 +1,13 @@
import * as x509 from "@peculiar/x509";
import acme, { CsrBuffer } from "acme-client";
+import dns from "dns";
import { Knex } from "knex";
import RE2 from "re2";
import { TableName } from "@app/db/schemas";
import { getConfig } from "@app/lib/config/env";
import { crypto } from "@app/lib/crypto/cryptography";
+import { delay } from "@app/lib/delay";
import { BadRequestError, CryptographyError, NotFoundError } from "@app/lib/errors";
import { ProcessedPermissionRules } from "@app/lib/knex/permission-filter-utils";
import { OrgServiceActor } from "@app/lib/types";
@@ -181,11 +183,56 @@ export const castDbEntryToAcmeCertificateAuthority = (
};
};
-const getAcmeChallengeRecord = (
+const DNS_PROPAGATION_MAX_RETRIES = 3;
+const DNS_PROPAGATION_INTERVAL_MS = 2000;
+const CNAME_MAX_DEPTH = 10;
+
+const resolveAcmeChallengeCname = async (recordName: string): Promise<string> => {
+ let current = recordName;
+ let depth = 0;
+ let resolved = true;
+
+ while (depth < CNAME_MAX_DEPTH && resolved) {
+ depth += 1;
+ try {
+ // eslint-disable-next-line no-await-in-loop
+ const [target] = await dns.promises.resolveCname(current);
+ if (!target) {
+ resolved = false;
+ } else {
+ current = target;
+ }
+ } catch {
+ resolved = false;
+ }
+ }
+
+ return current;
+};
+
+const waitForDnsPropagation = async (lookupName: string, expectedValue: string): Promise<void> => {
+ const unquotedExpected = expectedValue.replace(new RE2('^"|"$', "g"), "");
+ let attempts = 0;
+
+ while (attempts < DNS_PROPAGATION_MAX_RETRIES) {
+ attempts += 1;
+
+ const found = await dns.promises // eslint-disable-line no-await-in-loop
+ .resolveTxt(lookupName)
+ .then((records) => records.some((chunks) => chunks.join("") === unquotedExpected))
+ .catch(() => false);
+
+ if (found) return;
+
+ await delay(DNS_PROPAGATION_INTERVAL_MS); // eslint-disable-line no-await-in-loop
+ }
+};
+
+const getAcmeChallengeRecord = async (
provider: AcmeDnsProvider,
identifierValue: string,
keyAuthorization: string
-): { recordName: string; recordValue: string } => {
+): Promise<{ recordName: string; recordValue: string }> => {
let recordName: string;
if (provider === AcmeDnsProvider.DNSMadeEasy) {
// For DNS Made Easy, we don't need to provide the domain name in the record name.
@@ -193,6 +240,11 @@ const getAcmeChallengeRecord = (
} else {
recordName = `_acme-challenge.${identifierValue}`; // e.g., "_acme-challenge.example.com"
}
+
+ if (provider !== AcmeDnsProvider.DNSMadeEasy) {
+ recordName = await resolveAcmeChallengeCname(recordName);
+ }
+
const recordValue = `"${keyAuthorization}"`; // must be double quoted
return { recordName, recordValue };
};
@@ -331,7 +383,7 @@ export const orderCertificate = async (
throw new Error("Unsupported challenge type");
}
- const { recordName, recordValue } = getAcmeChallengeRecord(
+ const { recordName, recordValue } = await getAcmeChallengeRecord(
acmeCa.configuration.dnsProviderConfig.provider,
authz.identifier.value,
keyAuthorization
@@ -369,9 +421,15 @@ export const orderCertificate = async (
throw new Error(`Unsupported DNS provider: ${acmeCa.configuration.dnsProviderConfig.provider as string}`);
}
}
+
+ const lookupName =
+ acmeCa.configuration.dnsProviderConfig.provider === AcmeDnsProvider.DNSMadeEasy
+ ? recordName
+ : `_acme-challenge.${authz.identifier.value}`;
+ await waitForDnsPropagation(lookupName, recordValue);
},
challengeRemoveFn: async (authz, challenge, keyAuthorization) => {
- const { recordName, recordValue } = getAcmeChallengeRecord(
+ const { recordName, recordValue } = await getAcmeChallengeRecord(
acmeCa.configuration.dnsProviderConfig.provider,
authz.identifier.value,
keyAuthorization
diff --git a/docs/documentation/platform/pki/ca/acme-ca.mdx b/docs/documentation/platform/pki/ca/acme-ca.mdx
index 7f2290ff63..9ece984818 100644
--- a/docs/documentation/platform/pki/ca/acme-ca.mdx
+++ b/docs/documentation/platform/pki/ca/acme-ca.mdx
@@ -214,6 +214,28 @@ In the following steps, we explore how to connect Infisical to an ACME-compatibl
</Steps>
+## DNS CNAME Delegation
+
+CNAME delegation is an industry-standard pattern that lets you redirect ACME DNS-01 challenge records to a separate DNS zone. Instead of granting Infisical write access to your main domain zone, you point `_acme-challenge` via a CNAME to a dedicated zone where Infisical creates the TXT records.
+
+### How It Works
+
+If you have a CNAME record pointing `_acme-challenge.example.com` to another domain (e.g., `_acme-challenge.ssl.example.com`), Infisical will automatically follow the CNAME chain and create the TXT record at the final target. The ACME CA also follows CNAMEs during validation, so it finds the TXT record at the delegated location.
+
+To use CNAME delegation, you need to:
+
+1. **Create a CNAME record** in your domain's DNS that points `_acme-challenge.{your-domain}` to a target in the zone configured with Infisical. For subdomains, create additional CNAMEs as needed (e.g., `_acme-challenge.app.example.com` CNAME to `_acme-challenge.ssl.example.com`).
+
+2. **Register the ACME CA** in Infisical with the **hosted zone ID** of the zone where the CNAME target lives.
+
+Infisical will automatically resolve the CNAME, create the TXT record at the target, wait for DNS propagation, and clean up after validation completes.
+
+### Common Use Cases
+
+- **Least-privilege access**: Grant Infisical write access only to a dedicated subdomain zone instead of your entire domain zone.
+- **Cross-provider setups**: Keep your domain DNS on one provider while using a different, Infisical-supported provider for ACME challenges.
+- **Centralized challenge management**: Point `_acme-challenge` CNAMEs from multiple domains to a single zone for simplified operations.
+
## FAQ
<AccordionGroup>
@@ -244,4 +266,8 @@ In the following steps, we explore how to connect Infisical to an ACME-compatibl
<Accordion title="Can I use multiple ACME providers?">
Yes. You can register multiple ACME CAs in the same project.
</Accordion>
+ <Accordion title="Does Infisical support DNS CNAME delegation for ACME challenges?">
+ Yes. Infisical automatically follows CNAME records when creating DNS-01 challenge TXT records. This allows you to delegate
+ `_acme-challenge` to a different DNS zone or provider. See the [DNS CNAME Delegation](#dns-cname-delegation) section above for setup instructions.
+ </Accordion>
</AccordionGroup>