Skip to content

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

fix(pki): clearer google cloud dns errors and project search hint

bernie-gd6c9b089f316
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.ts
index d9a4ba51e6..117520f503 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) =>
+const axiosError = (status: number, message = `status ${status}`) =>
new AxiosError("request failed", String(status), undefined, undefined, {
status,
statusText: "",
headers: {},
config: { headers: new AxiosHeaders() },
- data: { error: { message: `status ${status}` } }
+ data: { error: { message } }
});
const existingRecordSet = (rrdatas: string[]) => ({ data: { name: FQDN, type: "TXT", ttl: 60, rrdatas } });
@@ -119,6 +119,16 @@ describe("gcpCloudDnsInsertTxtRecord", () => {
expect(postMock).not.toHaveBeenCalled();
});
+ it("tells the user to enable the API when Cloud DNS is disabled on the project", async () => {
+ getMock.mockRejectedValueOnce(
+ axiosError(403, "Cloud DNS API has not been used in project 123456 before or it is disabled.")
+ );
+
+ await expect(gcpCloudDnsInsertTxtRecord(connection, ZONE, RECORD, '"token-a"')).rejects.toThrow(
+ "The Cloud DNS API is not enabled on GCP project 'my-project'"
+ );
+ });
+
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.ts
index 3059779355..89249fb812 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
@@ -41,14 +41,21 @@ const normalizeTxtValue = (value: string) => value.replace(QUOTES_REGEX, "");
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;
+
if (error.response?.status === 403) {
const [, gcpProjectId, , zoneName] = hostedZoneId.split("/");
+ if (message.includes("has not been used in project") || message.includes("is disabled")) {
+ 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.`
+ );
+ }
return new Error(
`The GCP connection's service account can't manage records in Google Cloud DNS zone '${zoneName}'. Grant it the DNS Administrator role (roles/dns.admin) on GCP project '${gcpProjectId}' and try again.`
);
}
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
- const message = (error.response?.data?.error?.message || error.message || "Unknown error") as string;
+
return new Error(`Google Cloud DNS request failed: ${message}`);
}
return error;
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/GcpCloudDnsZoneFields.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/GcpCloudDnsZoneFields.tsx
index 00267dee7e..dfb594d4bb 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/GcpCloudDnsZoneFields.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/GcpCloudDnsZoneFields.tsx
@@ -98,8 +98,10 @@ export const GcpCloudDnsZoneFields = ({ control, connectionId }: Props) => {
}}
options={projects}
placeholder="Select a project..."
- noOptionsMessage={() =>
- "No projects found. Grant the connection's service account the DNS Administrator role on your project and enable the Cloud DNS API there."
+ noOptionsMessage={({ inputValue }) =>
+ inputValue
+ ? "No matching projects"
+ : "No projects found. Grant the connection's service account the DNS Administrator role on your project and enable the Cloud DNS API there."
}
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}