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 final comments
adilson054ec5bbd592
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 992024b773..11c71d114c 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@@ -221,6 +221,24 @@ describe("GithubSyncFns.syncSecrets", () => {]);});+ it("treats a stale secret already removed on GitHub as deleted and keeps pruning", async () => {+ paginatedMock.mockResolvedValue([{ name: "GONE" }, { name: "STALE" }]);+ requestMock.mockImplementation(async (_gateway: unknown, _service: unknown, config: any) => {+ if (config.method === "DELETE" && config.url.endsWith("/GONE")) throw httpError(404);+ if (config.method === "GET") {+ return { data: { key_id: "key-1", key: sodium.to_base64(keyPair.publicKey, sodium.base64_variants.ORIGINAL) } };+ }+ return { data: {} };+ });++ await runSync(makeSync(repoConfig(GitHubSyncSecretType.Dependabot)), makePayload(["A"]));++ expect(callsWith("DELETE").map((c) => c.url)).toEqual([+ "https://api.github.com/repos/acme/app/dependabot/secrets/GONE",+ "https://api.github.com/repos/acme/app/dependabot/secrets/STALE"+ ]);+ });+it("deletes nothing when secret deletion is disabled", async () => {paginatedMock.mockResolvedValue([{ name: "STALE" }]);@@ -353,7 +371,9 @@ describe("GitHub permission errors", () => {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 Dependabot secrets");+ expect((error as SecretSyncError).message).toContain(+ "read and write access to the 'Dependabot secrets' permission"+ );expect((error as SecretSyncError).message).toContain("'repo' scope");});@@ -365,11 +385,22 @@ describe("GitHub permission errors", () => {).rejects.toMatchObject({shouldRetry: false,message: expect.stringMatching(- /lacks permissions to access Codespaces secrets for organization 'acme'.*'admin:org' scope/+ /lacks permissions to access Codespaces secrets for organization 'acme'.*the 'Organization codespaces secrets' permission.*'admin:org' scope/)});});+ 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+ );++ 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 = {@@ -380,12 +411,15 @@ describe("GitHub permission errors", () => {secretType: GitHubSyncSecretType.Actions};- await expect(runSync(makeSync(environmentConfig), makePayload(["A"]))).rejects.toMatchObject({- shouldRetry: false,- message: expect.stringContaining(- "lacks permissions to access Actions secrets for environment 'prod' in repository 'acme/app'"- )- });+ 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"+ );});it("reports a 404 as a missing target or permission", async () => {@@ -412,7 +446,7 @@ describe("GitHub permission errors", () => {).rejects.toMatchObject({shouldRetry: false,secretKey: undefined,- message: expect.stringContaining("read and write access to Codespaces secrets")+ message: expect.stringContaining("read and write access to the 'Codespaces secrets' permission")});});@@ -459,6 +493,27 @@ describe("GithubSyncFns.removeSecrets", () => {"https://api.github.com/orgs/acme/dependabot/secrets/B"]);});++ it("keeps removing when a secret is already gone on GitHub", async () => {+ paginatedMock.mockResolvedValue([{ name: "A" }, { name: "B" }]);+ requestMock.mockImplementation(async (_gateway: unknown, _service: unknown, config: any) => {+ if (config.url.endsWith("/A")) throw httpError(404);+ return { data: {} };+ });++ await GithubSyncFns.removeSecrets(+ makeSync(repoConfig(GitHubSyncSecretType.Codespaces)),+ makePayload(["A", "B"]),+ gatewayV2Service,+ gatewayPoolService,+ gitHubAppDeps+ );++ expect(callsWith("DELETE").map((c) => c.url)).toEqual([+ "https://api.github.com/repos/acme/app/codespaces/secrets/A",+ "https://api.github.com/repos/acme/app/codespaces/secrets/B"+ ]);+ });});describe("gitHubPreSaveTransformDestinationConfig", () => {diff --git a/backend/src/services/secret-sync/github/github-sync-fns.ts b/backend/src/services/secret-sync/github/github-sync-fns.tsindex 5392671d95..a956d01551 100644--- a/backend/src/services/secret-sync/github/github-sync-fns.ts+++ b/backend/src/services/secret-sync/github/github-sync-fns.ts@@ -160,13 +160,18 @@ export const toGitHubSecretsError = (error: unknown, destinationConfig: TGitHubSif (status !== 403 && status !== 404) return error;if (status === 403 && isGitHubRateLimitError(error)) return error;- const { name } = GITHUB_SECRET_TYPES[getGitHubSyncSecretType(destinationConfig)];+ const { name, permission } = GITHUB_SECRET_TYPES[getGitHubSyncSecretType(destinationConfig)];const { target, missing } = describeGitHubSecretsTarget(destinationConfig);- const classicScope = destinationConfig.scope === GitHubSyncScope.Organization ? "admin:org" : "repo";+ 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`;const message =status === 403- ? `The GitHub connection lacks permissions to access ${name} secrets for ${target}. Grant read and write access to ${name} secrets 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.`+ ? `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.`;return new SecretSyncError({ error, message, shouldRetry: false });@@ -239,16 +244,23 @@ const getPublicKey = (secretSync: TGitHubSyncWithCredentials, deps: TGitHubSyncDpath: "/public-key"});-const deleteSecret = (+const deleteSecret = async (secretSync: TGitHubSyncWithCredentials,deps: TGitHubSyncDeps,token: string,encryptedSecret: TGitHubSecret-) =>- requestGitHubSecretsApi(secretSync, deps, token, {- method: "DELETE",- path: `/${encodeURIComponent(encryptedSecret.name)}`- });+) => {+ try {+ await requestGitHubSecretsApi(secretSync, deps, token, {+ method: "DELETE",+ path: `/${encodeURIComponent(encryptedSecret.name)}`+ });+ } catch (error) {+ // The secret was removed on GitHub after it was listed, which is the state this delete wanted+ if (error instanceof SecretSyncError && isAxiosError(error.error) && error.error.response?.status === 404) return;+ throw error;+ }+};const putSecret = (secretSync: TGitHubSyncWithCredentials,diff --git a/tests/suites/secretmanager/syncs/github_test.go b/tests/suites/secretmanager/syncs/github_test.goindex 152caf4e4b..0935390c69 100644--- a/tests/suites/secretmanager/syncs/github_test.go+++ b/tests/suites/secretmanager/syncs/github_test.go@@ -274,7 +274,7 @@ func TestGitHubSync_Create(t *testing.T) {// Assertrequire.NoError(t, err)- require.Equalf(t, http.StatusBadRequest, res.StatusCode(), "%s", apierr.Body(res.Body))+ require.Equalf(t, http.StatusUnprocessableEntity, res.StatusCode(), "%s", apierr.Body(res.Body))require.Contains(t, string(res.Body), "Repository environment scope is only available for Actions secrets")gh.ExpectNoEvent[github.SecretCreated](t, nil)})