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
fix(pki): share gcp disabled-api check and prefill only matching ca type
bernie-g94143ef3bd6b
diff --git a/backend/src/services/app-connection/gcp/gcp-connection-errors.test.ts b/backend/src/services/app-connection/gcp/gcp-connection-errors.test.tsnew file mode 100644index 0000000000..d6d8558344--- /dev/null+++ b/backend/src/services/app-connection/gcp/gcp-connection-errors.test.ts@@ -0,0 +1,23 @@+import { isGcpServiceDisabledError } from "./gcp-connection-errors";++describe("isGcpServiceDisabledError", () => {+ it("detects a disabled API from the SERVICE_DISABLED reason", () => {+ expect(+ isGcpServiceDisabledError({ error: { details: [{ reason: "SERVICE_DISABLED" }] } }, "Cloud DNS API is disabled.")+ ).toBe(true);+ });++ it("detects a disabled API from the accessNotConfigured reason", () => {+ expect(isGcpServiceDisabledError({ error: { errors: [{ reason: "accessNotConfigured" }] } }, "")).toBe(true);+ });++ it("falls back to Google's disabled-API message", () => {+ expect(+ isGcpServiceDisabledError(undefined, "Cloud DNS API has not been used in project 123 before or it is disabled.")+ ).toBe(true);+ });++ it("does not treat other disabled resources as a disabled API", () => {+ expect(isGcpServiceDisabledError(undefined, "The billing account for the project is disabled.")).toBe(false);+ });+});diff --git a/backend/src/services/app-connection/gcp/gcp-connection-errors.ts b/backend/src/services/app-connection/gcp/gcp-connection-errors.tsnew file mode 100644index 0000000000..bb3f047013--- /dev/null+++ b/backend/src/services/app-connection/gcp/gcp-connection-errors.ts@@ -0,0 +1,13 @@+export type TGoogleApiError = {+ error?: {+ status?: string;+ message?: string;+ errors?: { reason?: string }[];+ details?: { "@type"?: string; reason?: string }[];+ };+};++export const isGcpServiceDisabledError = (body: TGoogleApiError | undefined, message: string) =>+ Boolean(body?.error?.details?.some((detail) => detail.reason === "SERVICE_DISABLED")) ||+ Boolean(body?.error?.errors?.some((err) => err.reason === "accessNotConfigured")) ||+ message.includes("has not been used in project");diff --git a/backend/src/services/app-connection/gcp/gcp-connection-fns.ts b/backend/src/services/app-connection/gcp/gcp-connection-fns.tsindex 450d4a573a..65d90f7cbf 100644--- a/backend/src/services/app-connection/gcp/gcp-connection-fns.ts+++ b/backend/src/services/app-connection/gcp/gcp-connection-fns.ts@@ -14,6 +14,7 @@ import { IntegrationUrls } from "@app/services/integration-auth/integration-listimport { AppConnection } from "../app-connection-enums";import { GCP_GLOBAL_LOCATION } from "./gcp-connection-constants";import { GcpConnectionMethod } from "./gcp-connection-enums";+import { isGcpServiceDisabledError, TGoogleApiError } from "./gcp-connection-errors";import {GCPApp,GCPCloudDnsManagedZone,@@ -298,10 +299,6 @@ export const validateGcpConnectionCredentials = async (appConnection: TGcpConnecreturn appConnection.credentials;};-type TGoogleApiError = {- error?: { status?: string; message?: string };-};-const toGcpDiscoveryError = (error: unknown, context: { api: string; gcpProjectId?: string }) => {if (!(error instanceof AxiosError)) return error;@@ -310,7 +307,7 @@ const toGcpDiscoveryError = (error: unknown, context: { api: string; gcpProjectIconst scope = context.gcpProjectId ? `GCP project "${context.gcpProjectId}"` : "your GCP project";if (error.response?.status === 403) {- if (message.includes("has not been used in project") || message.includes("is disabled")) {+ if (isGcpServiceDisabledError(body, message)) {return new BadRequestError({message: `The ${context.api} API is not enabled on ${scope}. Enable it in the Google Cloud console and try again.`});diff --git a/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.ts b/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.tsindex 64613467e6..2caeb7f8bf 100644--- a/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.ts+++ b/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.ts@@ -6,6 +6,7 @@ import { delay } from "@app/lib/delay";import { BadRequestError } from "@app/lib/errors";import { logger } from "@app/lib/logger";import { GCP_CLOUD_DNS_ZONE_RESOURCE_PATTERN } from "@app/services/app-connection/gcp/gcp-connection-constants";+import { isGcpServiceDisabledError, TGoogleApiError } from "@app/services/app-connection/gcp/gcp-connection-errors";import { getGcpConnectionAuthToken } from "@app/services/app-connection/gcp/gcp-connection-fns";import { TGcpConnection } from "@app/services/app-connection/gcp/gcp-connection-types";import { IntegrationUrls } from "@app/services/integration-auth/integration-list";@@ -40,27 +41,14 @@ const toFqdn = (recordName: string) => (recordName.endsWith(".") ? recordName :const normalizeTxtValue = (value: string) => value.replace(QUOTES_REGEX, "");-type TGoogleApiErrorBody = {- error?: {- message?: string;- errors?: { reason?: string }[];- details?: { "@type"?: string; reason?: string }[];- };-};--const isServiceDisabledError = (body: TGoogleApiErrorBody | undefined, message: string) =>- Boolean(body?.error?.details?.some((detail) => detail.reason === "SERVICE_DISABLED")) ||- Boolean(body?.error?.errors?.some((err) => err.reason === "accessNotConfigured")) ||- message.includes("has not been used in project");-const toGcpDnsError = (error: unknown, hostedZoneId: string, fqdn: string) => {if (isAxiosError(error)) {- const body = error.response?.data as TGoogleApiErrorBody | undefined;+ const body = error.response?.data as TGoogleApiError | undefined;const message = body?.error?.message || error.message || "Unknown error";if (error.response?.status === 403) {const [, gcpProjectId, , zoneName] = hostedZoneId.split("/");- if (isServiceDisabledError(body, message)) {+ if (isGcpServiceDisabledError(body, message)) {return new Error(`The Cloud DNS API is not enabled on GCP project '${gcpProjectId}'. Enable dns.googleapis.com in the Google Cloud console and try again.`);diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsxindex a661c49e0e..df161d0b76 100644--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx@@ -560,7 +560,13 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {}, [popUp?.ca?.isOpen]);useEffect(() => {- if (ca && !isCaLoading && !isPending && prefilledCaIdRef.current !== ca.id) {+ if (+ ca &&+ !isCaLoading &&+ !isPending &&+ caType === ca.type &&+ prefilledCaIdRef.current !== ca.id+ ) {const prefill = (values: Parameters<typeof reset>[0]) => {reset(values);prefilledCaIdRef.current = ca.id;@@ -727,7 +733,7 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {});}}- }, [ca, availableConnections, reset, isCaLoading, isPending]);+ }, [ca, availableConnections, reset, isCaLoading, isPending, caType]);const digicertConnectionId =caType === CaType.DIGICERT && configuration && "digicertConnection" in configuration