Skip to content

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

Add ADCS validation on CA names for External Authorities

Carlos Monastyrski9f2ef92439d1
diff --git a/backend/src/services/app-connection/adcs/adcs-connection-fns.ts b/backend/src/services/app-connection/adcs/adcs-connection-fns.ts
index 1d6d336cba..0bad5bce55 100644
--- a/backend/src/services/app-connection/adcs/adcs-connection-fns.ts
+++ b/backend/src/services/app-connection/adcs/adcs-connection-fns.ts
@@ -3,7 +3,7 @@ import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gatewa
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { BadRequestError } from "@app/lib/errors";
import { GatewayProxyProtocol } from "@app/lib/gateway/types";
-import { AdcsRpcEndpoint, callAdcsEndpoint } from "@app/lib/gateway-v2/adcs-rpc";
+import { AdcsRpcEndpoint, AdcsTemplatesResult, callAdcsEndpoint } from "@app/lib/gateway-v2/adcs-rpc";
import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
@@ -107,17 +107,51 @@ type TAdcsConnectionTarget = {
credentials: { host: string; username: string; password: string };
};
+/**
+ * Confirms the certificate authority name is correct and reachable by listing its templates over
+ * the gateway. AD CS rejects an unknown authority name with E_INVALIDARG, so a successful listing
+ * proves both that the gateway/credentials work and that the name matches a CA published on the
+ * host. Throws an actionable BadRequestError otherwise.
+ */
+const assertAdcsCaIsReachable = async (
+ caName: string,
+ target: TAdcsConnectionTarget,
+ deps: TADCSGatewayDeps
+): Promise<void> => {
+ try {
+ await executeAdcsGatewayOperation<AdcsTemplatesResult>({ ...target, endpoint: "/v1/templates", caName }, deps);
+ } catch (error) {
+ // A wrong name surfaces as E_INVALIDARG, whose message repeats the same guidance, so only append
+ // the underlying detail when it adds something (e.g. a transport failure like an SMB/DCOM timeout).
+ const detail = (error as Error)?.message ?? "";
+ const extraDetail = detail && !detail.includes("E_INVALIDARG") ? ` (${detail})` : "";
+ throw new BadRequestError({
+ message: `Could not reach certificate authority "${caName}" through the gateway. Verify the certificate authority name is correct and that the gateway can connect to the AD CS host.${extraDetail}`
+ });
+ }
+};
+
/**
* Returns the caller-supplied CA name, or discovers it from the CA host's registry over the
- * gateway (the CertSvc "Active" value) when omitted. `getTarget` is only invoked when discovery
- * is needed, so callers that already have a CA name pay no gateway/credential cost.
+ * gateway (the CertSvc "Active" value) when omitted. `getTarget` is only invoked when a gateway
+ * call is needed, so callers that already have a CA name and do not request validation pay no
+ * gateway/credential cost. When `ensureReachable` is set, the resolved name is validated against
+ * the CA before it is returned.
*/
export const resolveAdcsCaName = async (
caName: string | undefined,
getTarget: () => Promise<TAdcsConnectionTarget>,
- deps: TADCSGatewayDeps
+ deps: TADCSGatewayDeps,
+ options?: { ensureReachable?: boolean }
): Promise<string> => {
- if (caName) return caName;
+ const ensureReachable = options?.ensureReachable ?? false;
+
+ if (caName) {
+ if (ensureReachable) {
+ await assertAdcsCaIsReachable(caName, await getTarget(), deps);
+ }
+ return caName;
+ }
const target = await getTarget();
const discovered = await executeAdcsGatewayOperation<{ caName: string }>(
@@ -130,6 +164,11 @@ export const resolveAdcsCaName = async (
"Could not automatically discover the certificate authority name from the host. Provide the Certificate Authority name explicitly."
});
}
+
+ if (ensureReachable) {
+ await assertAdcsCaIsReachable(discovered.caName, target, deps);
+ }
+
return discovered.caName;
};
diff --git a/backend/src/services/certificate-authority/adcs/adcs-certificate-authority-fns.ts b/backend/src/services/certificate-authority/adcs/adcs-certificate-authority-fns.ts
index 6fb65f8730..a8bb143db5 100644
--- a/backend/src/services/certificate-authority/adcs/adcs-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/adcs/adcs-certificate-authority-fns.ts
@@ -213,7 +213,8 @@ export const ADCSCertificateAuthorityFns = ({
const resolvedCaName = await resolveAdcsCaName(
caName,
() => getAdcsConnectionCredentials(appConnectionId, appConnectionDAL, kmsService),
- { gatewayV2Service, gatewayPoolService }
+ { gatewayV2Service, gatewayPoolService },
+ { ensureReachable: true }
);
const caEntity = await certificateAuthorityDAL.transaction(async (tx) => {
@@ -297,12 +298,13 @@ export const ADCSCertificateAuthorityFns = ({
);
}
- // Resolve the CA name outside the transaction (discovery is a gateway call).
+ // Resolve and validate the CA name outside the transaction
const resolvedUpdateCaName = configuration
? await resolveAdcsCaName(
configuration.caName,
() => getAdcsConnectionCredentials(configuration.appConnectionId, appConnectionDAL, kmsService),
- { gatewayV2Service, gatewayPoolService }
+ { gatewayV2Service, gatewayPoolService },
+ { ensureReachable: true }
)
: undefined;
diff --git a/docs/documentation/platform/pki/ca/adcs.mdx b/docs/documentation/platform/pki/ca/adcs.mdx
index e7d68cd3ff..2deb294b87 100644
--- a/docs/documentation/platform/pki/ca/adcs.mdx
+++ b/docs/documentation/platform/pki/ca/adcs.mdx
@@ -12,7 +12,13 @@ Before setting up a Microsoft ADCS certificate authority, configure a [Microsoft
You can use AD CS in a few ways: as an **External CA** that issues certificates directly, to back a **code signing signer**, or to **sign internal intermediate CAs** so you can build an Infisical-managed CA hierarchy backed by your AD CS server. In every case the certificate template is chosen by the issuance flow (profile, signer, or intermediate CA), not by the CA itself.
<Note>
- The certificate authority name is discovered automatically from the CA host. Provide it explicitly only when discovery cannot run in your environment.
+ Enter the certificate authority name (for example `corp-ca01-CA`). To find it, run this on the AD CS server:
+
+ ```powershell
+ certutil -getreg CA\CommonName
+ ```
+
+ You can leave it blank only if the Gateway can reach the CA host over SMB (TCP 445), which lets Infisical discover the name for you. Infisical checks the name when you save, so a wrong or unreachable name fails right away instead of creating a broken CA.
</Note>
<Tabs>
@@ -27,7 +33,9 @@ You can use AD CS in a few ways: as an **External CA** that issues certificates
- **Type**: Choose **Microsoft ADCS**
- **Name**: Friendly name for this CA (for example, `production-adcs`)
- **Microsoft ADCS Connection**: Choose your Microsoft ADCS connection
- - **Certificate Authority**: Optional. Leave blank to discover it automatically from the CA host.
+ - **Certificate Authority**: The CA common name, for example `corp-ca01-CA` (run `certutil -getreg CA\CommonName` on the AD CS server to find it). Leave it blank only if the Gateway can reach the CA host over SMB (TCP 445) for automatic discovery.
+
+ Infisical contacts the CA through the Gateway when you save, so a wrong name or an unreachable host is rejected here rather than surfacing later as a CA that cannot list templates or issue.
</Step>
<Step title="Create a Certificate Profile">
@@ -184,7 +192,10 @@ You can use AD CS in a few ways: as an **External CA** that issues certificates
The connection account does not have Enroll permission on the requested template. Grant Enroll to the account on the template's security settings.
</Accordion>
<Accordion title="The certificate authority name could not be discovered">
- Discovery reads the CA name from the host's registry over the network, which requires the Remote Registry service to be running and reachable from the Gateway. If it cannot run, set the certificate authority name explicitly on the external CA.
+ Automatic discovery reads the CA name from the host's registry over SMB (TCP 445), which requires the Remote Registry service to be running and reachable from the Gateway. If SMB is not open to the Gateway, leave discovery aside and set the certificate authority name explicitly on the external CA. Run `certutil -getreg CA\CommonName` on the AD CS server to find it.
+ </Accordion>
+ <Accordion title="Could not reach certificate authority through the gateway">
+ When you create or update the CA, Infisical validates the certificate authority name against the CA over the Gateway. This error means the name does not match a CA on the host, or the Gateway cannot reach the AD CS server. Confirm the name with `certutil -getreg CA\CommonName` on the AD CS server and that the Gateway can connect to the host over DCOM (MS-WCCE).
</Accordion>
<Accordion title="Signer rejected: missing Code Signing extended key usage">
The template used for a code signing signer does not produce a code-signing certificate. Point the signer at a template that carries the Code Signing extended key usage.
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx
index 6eb522f172..a2311c8dfc 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx
@@ -1235,9 +1235,26 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
isError={Boolean(error)}
errorText={error?.message}
isOptional
- tooltipText="The AD CS certificate authority name (the CA's common name), e.g. corp-ca01-CA. Leave blank to discover it automatically from the CA host."
+ tooltipClassName="max-w-sm"
+ tooltipText={
+ <div className="flex flex-col gap-2">
+ <p>
+ The AD CS certificate authority name (the CA&apos;s common name), for
+ example <span className="font-mono">corp-ca01-CA</span>.
+ </p>
+ <p>
+ Leave blank only if the Gateway can reach the CA host over SMB (TCP 445)
+ to discover the name automatically. Otherwise enter it here.
+ </p>
+ <p>
+ To find the name, run this on the AD CS server:
+ <br />
+ <span className="font-mono">certutil -getreg CA\CommonName</span>
+ </p>
+ </div>
+ }
>
- <Input {...field} placeholder="Auto-discovered if left blank" />
+ <Input {...field} placeholder="Enter CA name (auto-discovered if left blank)" />
</FormControl>
)}
/>