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
improve error message
adilsonc34fb82bb632
diff --git a/backend/src/services/secret-sync/github/github-sync-fns.test.ts b/backend/src/services/secret-sync/github/github-sync-fns.test.tsindex 11c71d114c..b1de7f4631 100644--- a/backend/src/services/secret-sync/github/github-sync-fns.test.ts+++ b/backend/src/services/secret-sync/github/github-sync-fns.test.ts@@ -422,6 +422,23 @@ describe("GitHub permission errors", () => {);});+ it.each([+ ["github.com", undefined, "https://github.com/settings/installations/172172533"],+ ["GitHub Enterprise Server", "github.example.com", "https://github.example.com/settings/installations/172172533"]+ ])("links the GitHub App installation on %s", async (_label, host, installationUrl) => {+ appTokenMock.mockResolvedValue("app-token");+ paginatedMock.mockRejectedValueOnce(httpError(403));+ const sync = {+ ...makeSync(repoConfig(GitHubSyncSecretType.Codespaces)),+ connection: { method: "github-app", credentials: { installationId: "172172533", host } }+ };++ await expect(runSync(sync, makePayload(["A"]))).rejects.toMatchObject({+ shouldRetry: false,+ message: `The GitHub connection lacks permissions to access Codespaces secrets for repository 'acme/app'. Grant read and write access to the 'Codespaces secrets' permission on the GitHub App installation: ${installationUrl}`+ });+ });+it("reports a 404 as a missing target or permission", async () => {paginatedMock.mockRejectedValueOnce(httpError(404));diff --git a/backend/src/services/secret-sync/github/github-sync-fns.ts b/backend/src/services/secret-sync/github/github-sync-fns.tsindex a956d01551..21ee5eee48 100644--- a/backend/src/services/secret-sync/github/github-sync-fns.ts+++ b/backend/src/services/secret-sync/github/github-sync-fns.ts@@ -153,7 +153,10 @@ const isGitHubRateLimitError = (error: AxiosError) => {return typeof message === "string" && message.toLowerCase().includes("rate limit");};-export const toGitHubSecretsError = (error: unknown, destinationConfig: TGitHubSyncDestinationConfig) => {+export const toGitHubSecretsError = (+ error: unknown,+ { destinationConfig, connection }: Pick<TGitHubSyncWithCredentials, "destinationConfig" | "connection">+) => {if (!isAxiosError(error) || !error.response) return error;const { status } = error.response;@@ -169,10 +172,16 @@ export const toGitHubSecretsError = (error: unknown, destinationConfig: TGitHubS? `the '${permission.repository}' and 'Environments' permissions`: `the '${isOrganization ? permission.organization : permission.repository}' permission`;- const message =- status === 403- ? `The GitHub connection lacks permissions to access ${name} secrets for ${target}. Grant read and write access to ${requiredPermissions} on the GitHub App or fine-grained token, or use the '${classicScope}' scope for OAuth and classic tokens. An owner of a GitHub App installation must also approve newly requested permissions.`- : `GitHub could not find the ${name} secrets for ${target}. Check that ${missing} and that the GitHub connection has the permissions to access it.`;+ let message: string;+ if (status === 404) {+ message = `GitHub could not find the ${name} secrets for ${target}. Check that ${missing} and that the GitHub connection has the permissions to access it.`;+ } else if (connection.method === GitHubConnectionMethod.App) {+ const { host, installationId } = connection.credentials;+ const installationUrl = `https://${host || "github.com"}/settings/installations/${encodeURIComponent(installationId)}`;+ message = `The GitHub connection lacks permissions to access ${name} secrets for ${target}. Grant read and write access to ${requiredPermissions} on the GitHub App installation: ${installationUrl}`;+ } else {+ message = `The GitHub connection lacks permissions to access ${name} secrets for ${target}. Grant read and write access to ${requiredPermissions} on the fine-grained token, or use the '${classicScope}' scope for OAuth and classic tokens.`;+ }return new SecretSyncError({ error, message, shouldRetry: false });};@@ -213,7 +222,7 @@ const requestGitHubSecretsApi = async <T>(return response.data;} catch (error) {- throw toGitHubSecretsError(error, destinationConfig);+ throw toGitHubSecretsError(error, secretSync);}};@@ -234,7 +243,7 @@ const getEncryptedSecrets = async ((data) => data.secrets);} catch (error) {- throw toGitHubSecretsError(error, destinationConfig);+ throw toGitHubSecretsError(error, secretSync);}};