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
address review comments
adilson5a1b286fcae4
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 b1de7f4631..93d382514c 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@@ -359,7 +359,7 @@ describe("GithubSyncFns.syncSecrets", () => {});describe("GitHub permission errors", () => {- it("names the missing repository permission for the secret type and stops retrying", async () => {+ it("returns GitHub's 403 message for a token connection and stops retrying", async () => {requestMock.mockRejectedValueOnce(httpError(403, { data: { message: "Resource not accessible by integration" } }));const error = await runSync(makeSync(repoConfig(GitHubSyncSecretType.Dependabot)), makePayload(["A"])).catch(@@ -367,75 +367,65 @@ describe("GitHub permission errors", () => {);expect(error).toBeInstanceOf(SecretSyncError);- expect(error).toMatchObject({ shouldRetry: false });- expect((error as SecretSyncError).message).toContain(- "lacks permissions to access Dependabot secrets for repository 'acme/app'"- );- expect((error as SecretSyncError).message).toContain(- "read and write access to the 'Dependabot secrets' permission"- );- expect((error as SecretSyncError).message).toContain("'repo' scope");+ expect(error).toMatchObject({+ shouldRetry: false,+ message: "Resource not accessible by integration"+ });+ expect((error as SecretSyncError).message).not.toContain("GitHub App installation");});- it("names the organization permission and the admin:org scope at organization scope", async () => {+ it("uses a fallback when GitHub's 403 has no message", async () => {paginatedMock.mockRejectedValueOnce(httpError(403));await expect(runSync(makeSync(orgConfig(GitHubSyncSecretType.Codespaces)), makePayload(["A"]))).rejects.toMatchObject({shouldRetry: false,- message: expect.stringMatching(- /lacks permissions to access Codespaces secrets for organization 'acme'.*the 'Organization codespaces secrets' permission.*'admin:org' scope/- )+ message: "GitHub refused this request."});});- it("names GitHub's Secrets permission for an Actions sync, which has no 'Actions secrets' permission", async () => {- paginatedMock.mockRejectedValueOnce(httpError(403));-- const error = await runSync(makeSync(repoConfig(GitHubSyncSecretType.Actions)), makePayload(["A"])).catch(- (err: unknown) => err+ it.each([+ [+ "github.com",+ undefined,+ "https://github.com/settings/installations/172172533 (personal) or https://github.com/organizations/acme/settings/installations/172172533 (organization)"+ ],+ [+ "GitHub Enterprise Server",+ "github.example.com",+ "https://github.example.com/settings/installations/172172533 (personal) or https://github.example.com/organizations/acme/settings/installations/172172533 (organization)"+ ]+ ])("links both GitHub App installation pages on %s", async (_label, host, installationLinks) => {+ appTokenMock.mockResolvedValue("app-token");+ paginatedMock.mockRejectedValueOnce(+ httpError(403, { data: { message: "Resource not accessible by integration" } }));-- expect((error as SecretSyncError).message).toContain("read and write access to the 'Secrets' permission");- expect((error as SecretSyncError).message).not.toContain("access to Actions secrets");- });-- it("names the Actions secret type for an environment sync", async () => {- paginatedMock.mockRejectedValueOnce(httpError(403));- const environmentConfig = {- scope: GitHubSyncScope.RepositoryEnvironment,- owner: "acme",- repo: "app",- env: "prod",- secretType: GitHubSyncSecretType.Actions+ const sync = {+ ...makeSync(repoConfig(GitHubSyncSecretType.Codespaces)),+ connection: { method: "github-app", credentials: { installationId: "172172533", host } }};- const error = await runSync(makeSync(environmentConfig), makePayload(["A"])).catch((err: unknown) => err);-- expect(error).toMatchObject({ shouldRetry: false });- expect((error as SecretSyncError).message).toContain(- "lacks permissions to access Actions secrets for environment 'prod' in repository 'acme/app'"- );- expect((error as SecretSyncError).message).toContain(- "read and write access to the 'Secrets' and 'Environments' permissions"- );+ await expect(runSync(sync, makePayload(["A"]))).rejects.toMatchObject({+ shouldRetry: false,+ message: `Resource not accessible by integration GitHub App installation: ${installationLinks}`+ });});- 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) => {+ it("uses the organization name in the organization installation link", async () => {appTokenMock.mockResolvedValue("app-token");- paginatedMock.mockRejectedValueOnce(httpError(403));+ paginatedMock.mockRejectedValueOnce(+ httpError(403, { data: { message: "Resource not accessible by integration" } })+ );const sync = {- ...makeSync(repoConfig(GitHubSyncSecretType.Codespaces)),- connection: { method: "github-app", credentials: { installationId: "172172533", host } }+ ...makeSync(orgConfig(GitHubSyncSecretType.Codespaces, { org: "widgets" })),+ connection: { method: "github-app", credentials: { installationId: "172172533" } }};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}`+ message:+ "Resource not accessible by integration GitHub App installation: https://github.com/settings/installations/172172533 (personal) or https://github.com/organizations/widgets/settings/installations/172172533 (organization)"});});@@ -452,9 +442,10 @@ describe("GitHub permission errors", () => {});});- it("names the permission when a write is refused, rather than blaming the secret", async () => {+ it("returns GitHub's message when a write is refused, rather than blaming the secret", async () => {requestMock.mockImplementation(async (_gateway: unknown, _service: unknown, config: any) => {- if (config.method === "PUT") throw httpError(403);+ if (config.method === "PUT")+ throw httpError(403, { data: { message: "Resource not accessible by integration" } });return { data: { key_id: "key-1", key: sodium.to_base64(keyPair.publicKey, sodium.base64_variants.ORIGINAL) } };});@@ -463,7 +454,7 @@ describe("GitHub permission errors", () => {).rejects.toMatchObject({shouldRetry: false,secretKey: undefined,- message: expect.stringContaining("read and write access to the 'Codespaces secrets' permission")+ message: "Resource not accessible by integration"});});diff --git a/backend/src/services/secret-sync/github/github-sync-fns.ts b/backend/src/services/secret-sync/github/github-sync-fns.tsindex 21ee5eee48..a8de9ed65a 100644--- a/backend/src/services/secret-sync/github/github-sync-fns.ts+++ b/backend/src/services/secret-sync/github/github-sync-fns.ts@@ -36,33 +36,27 @@ type TGitHubSyncDeps = {gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;};-type TGitHubOrgOrRepoValues = { organization: string; repository: string };-type TGitHubSecretTypeDefinition = {name: string;pathSegment: string;- permission: TGitHubOrgOrRepoValues;- limit: Record<keyof TGitHubOrgOrRepoValues, number>;+ limit: { organization: number; repository: number };};const GITHUB_SECRET_TYPES: Record<GitHubSyncSecretType, TGitHubSecretTypeDefinition> = {[GitHubSyncSecretType.Actions]: {name: "Actions",pathSegment: "actions",- permission: { organization: "Secrets", repository: "Secrets" },limit: { organization: 1000, repository: 100 }},// GitHub publishes no Dependabot-specific limits, so these mirror the Actions limits[GitHubSyncSecretType.Dependabot]: {name: "Dependabot",pathSegment: "dependabot",- permission: { organization: "Organization dependabot secrets", repository: "Dependabot secrets" },limit: { organization: 1000, repository: 100 }},[GitHubSyncSecretType.Codespaces]: {name: "Codespaces",pathSegment: "codespaces",- permission: { organization: "Organization codespaces secrets", repository: "Codespaces secrets" },limit: { organization: 100, repository: 100 }}};@@ -153,6 +147,24 @@ const isGitHubRateLimitError = (error: AxiosError) => {return typeof message === "string" && message.toLowerCase().includes("rate limit");};+const GITHUB_REFUSED_MESSAGE = "GitHub refused this request.";++const gitHubResponseMessage = (error: AxiosError) => {+ const message = (error.response?.data as { message?: unknown } | undefined)?.message;+ return typeof message === "string" && message.trim() ? message.trim() : GITHUB_REFUSED_MESSAGE;+};++const gitHubSyncAccountLogin = (destinationConfig: TGitHubSyncDestinationConfig) =>+ destinationConfig.scope === GitHubSyncScope.Organization ? destinationConfig.org : destinationConfig.owner;++const gitHubAppInstallationLinks = (host: string | undefined, installationId: string, accountLogin: string) => {+ const webHost = host || "github.com";+ const encodedInstallationId = encodeURIComponent(installationId);+ const personalUrl = `https://${webHost}/settings/installations/${encodedInstallationId}`;+ const organizationUrl = `https://${webHost}/organizations/${encodeURIComponent(accountLogin)}/settings/installations/${encodedInstallationId}`;+ return `${personalUrl} (personal) or ${organizationUrl} (organization)`;+};+export const toGitHubSecretsError = (error: unknown,{ destinationConfig, connection }: Pick<TGitHubSyncWithCredentials, "destinationConfig" | "connection">@@ -163,24 +175,24 @@ export const toGitHubSecretsError = (if (status !== 403 && status !== 404) return error;if (status === 403 && isGitHubRateLimitError(error)) return error;- const { name, permission } = GITHUB_SECRET_TYPES[getGitHubSyncSecretType(destinationConfig)];- const { target, missing } = describeGitHubSecretsTarget(destinationConfig);- const isOrganization = destinationConfig.scope === GitHubSyncScope.Organization;- const classicScope = isOrganization ? "admin:org" : "repo";- const requiredPermissions =- destinationConfig.scope === GitHubSyncScope.RepositoryEnvironment- ? `the '${permission.repository}' and 'Environments' permissions`- : `the '${isOrganization ? permission.organization : permission.repository}' permission`;-- 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 { name } = GITHUB_SECRET_TYPES[getGitHubSyncSecretType(destinationConfig)];+ const { target, missing } = describeGitHubSecretsTarget(destinationConfig);+ return new SecretSyncError({+ error,+ shouldRetry: false,+ message: `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 = gitHubResponseMessage(error);+ 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.`;+ message = `${message} GitHub App installation: ${gitHubAppInstallationLinks(+ host,+ installationId,+ gitHubSyncAccountLogin(destinationConfig)+ )}`;}return new SecretSyncError({ error, message, shouldRetry: false });