Skip to content

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

Address greptile comments

Carlos Monastyrski16b802a83f85
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 0bad5bce55..030e675feb 100644
--- a/backend/src/services/app-connection/adcs/adcs-connection-fns.ts
+++ b/backend/src/services/app-connection/adcs/adcs-connection-fns.ts
@@ -116,7 +116,8 @@ type TAdcsConnectionTarget = {
const assertAdcsCaIsReachable = async (
caName: string,
target: TAdcsConnectionTarget,
- deps: TADCSGatewayDeps
+ deps: TADCSGatewayDeps,
+ wasDiscovered: boolean
): Promise<void> => {
try {
await executeAdcsGatewayOperation<AdcsTemplatesResult>({ ...target, endpoint: "/v1/templates", caName }, deps);
@@ -125,9 +126,10 @@ const assertAdcsCaIsReachable = async (
// 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}`
- });
+ const guidance = wasDiscovered
+ ? `The certificate authority name "${caName}" was discovered from the host, but the gateway could not reach the certificate authority to list its templates. Verify the gateway can connect to the AD CS host over DCOM (MS-WCCE).`
+ : `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.`;
+ throw new BadRequestError({ message: `${guidance}${extraDetail}` });
}
};
@@ -148,7 +150,7 @@ export const resolveAdcsCaName = async (
if (caName) {
if (ensureReachable) {
- await assertAdcsCaIsReachable(caName, await getTarget(), deps);
+ await assertAdcsCaIsReachable(caName, await getTarget(), deps, false);
}
return caName;
}
@@ -165,8 +167,11 @@ export const resolveAdcsCaName = async (
});
}
+ // Discovery above proves SMB/registry reachability plus credentials; this second check proves the CA is
+ // reachable over the different DCOM/MS-WCCE path and can list templates, which is what issuance actually
+ // needs. A CA that discovers but cannot list templates is exactly the broken state we reject up front.
if (ensureReachable) {
- await assertAdcsCaIsReachable(discovered.caName, target, deps);
+ await assertAdcsCaIsReachable(discovered.caName, target, deps, true);
}
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 a8bb143db5..16367d4b5b 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
@@ -298,15 +298,25 @@ export const ADCSCertificateAuthorityFns = ({
);
}
- // Resolve and validate the CA name outside the transaction
- const resolvedUpdateCaName = configuration
- ? await resolveAdcsCaName(
+ let resolvedUpdateCaName: string | undefined;
+ if (configuration) {
+ const existingConfig = ca.externalCa.configuration as { caName?: string } | null;
+ const existingCaName = existingConfig?.caName;
+ const normalizedNewCaName = configuration.caName?.trim() || undefined;
+ const configChanged =
+ configuration.appConnectionId !== ca.externalCa.appConnectionId || normalizedNewCaName !== existingCaName;
+
+ if (!configChanged && existingCaName) {
+ resolvedUpdateCaName = existingCaName;
+ } else {
+ resolvedUpdateCaName = await resolveAdcsCaName(
configuration.caName,
() => getAdcsConnectionCredentials(configuration.appConnectionId, appConnectionDAL, kmsService),
{ gatewayV2Service, gatewayPoolService },
{ ensureReachable: true }
- )
- : undefined;
+ );
+ }
+ }
const updatedCa = await certificateAuthorityDAL.transaction(async (tx) => {
if (configuration) {