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): detect disabled cloud dns api by error reason
bernie-ga52c4e8767b9
diff --git a/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.test.ts b/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.test.tsindex bf4437d391..981540ac27 100644--- a/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.test.ts+++ b/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.test.ts@@ -28,13 +28,13 @@ const ZONE_URL = `https://dns.googleapis.com/dns/v1/${ZONE}`;const RECORD = "_acme-challenge.example.com";const FQDN = `${RECORD}.`;-const axiosError = (status: number, message = `status ${status}`) =>+const axiosError = (status: number, message = `status ${status}`, extra: Record<string, unknown> = {}) =>new AxiosError("request failed", String(status), undefined, undefined, {status,statusText: "",headers: {},config: { headers: new AxiosHeaders() },- data: { error: { message } }+ data: { error: { message, ...extra } }});const existingRecordSet = (rrdatas: string[]) => ({ data: { name: FQDN, type: "TXT", ttl: 60, rrdatas } });@@ -153,6 +153,26 @@ describe("gcpCloudDnsInsertTxtRecord", () => {);});+ it("detects a disabled API from Google's error reason, whatever the message says", async () => {+ getMock.mockRejectedValueOnce(+ axiosError(403, "Cloud DNS API is disabled.", {+ details: [{ "@type": "type.googleapis.com/google.rpc.ErrorInfo", reason: "SERVICE_DISABLED" }]+ })+ );++ await expect(gcpCloudDnsInsertTxtRecord(connection, ZONE, RECORD, '"token-a"')).rejects.toThrow(+ "The Cloud DNS API is not enabled on GCP project 'my-project'"+ );+ });++ it("does not treat other disabled resources as a disabled API", async () => {+ getMock.mockRejectedValueOnce(axiosError(403, "The billing account for the project is disabled."));++ await expect(gcpCloudDnsInsertTxtRecord(connection, ZONE, RECORD, '"token-a"')).rejects.toThrow(+ "Grant it the DNS Administrator role"+ );+ });+it("surfaces the provider message on other failures", async () => {getMock.mockRejectedValueOnce(axiosError(400));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 777dadcef8..8caa911c6d 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@@ -39,14 +39,27 @@ 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) => {if (isAxiosError(error)) {- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access- const message = (error.response?.data?.error?.message || error.message || "Unknown error") as string;+ const body = error.response?.data as TGoogleApiErrorBody | undefined;+ const message = body?.error?.message || error.message || "Unknown error";if (error.response?.status === 403) {const [, gcpProjectId, , zoneName] = hostedZoneId.split("/");- if (message.includes("has not been used in project")) {+ if (isServiceDisabledError(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.`);