Skip to content

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

add permissions on error message

adilsond88e9004713b
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.ts
index 93d382514c..5c8057c72e 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
@@ -369,7 +369,8 @@ describe("GitHub permission errors", () => {
expect(error).toBeInstanceOf(SecretSyncError);
expect(error).toMatchObject({
shouldRetry: false,
- message: "Resource not accessible by integration"
+ message:
+ "Resource not accessible by integration. Grant read and write access to the 'Dependabot secrets' permission."
});
expect((error as SecretSyncError).message).not.toContain("GitHub App installation");
});
@@ -381,7 +382,39 @@ describe("GitHub permission errors", () => {
runSync(makeSync(orgConfig(GitHubSyncSecretType.Codespaces)), makePayload(["A"]))
).rejects.toMatchObject({
shouldRetry: false,
- message: "GitHub refused this request."
+ message:
+ "GitHub refused this request. Grant read and write access to the 'Organization codespaces secrets' permission."
+ });
+ });
+
+ it("names GitHub's Secrets permission for an Actions sync", async () => {
+ paginatedMock.mockRejectedValueOnce(
+ httpError(403, { data: { message: "Resource not accessible by integration" } })
+ );
+
+ const error = await runSync(makeSync(repoConfig(GitHubSyncSecretType.Actions)), makePayload(["A"])).catch(
+ (err: unknown) => err
+ );
+
+ expect((error as SecretSyncError).message).toContain("the 'Secrets' permission");
+ expect((error as SecretSyncError).message).not.toContain("Actions secrets");
+ });
+
+ it("names the Secrets and Environments permissions for an environment sync", async () => {
+ paginatedMock.mockRejectedValueOnce(
+ httpError(403, { data: { message: "Resource not accessible by integration" } })
+ );
+ const environmentConfig = {
+ scope: GitHubSyncScope.RepositoryEnvironment,
+ owner: "acme",
+ repo: "app",
+ env: "prod",
+ secretType: GitHubSyncSecretType.Actions
+ };
+
+ await expect(runSync(makeSync(environmentConfig), makePayload(["A"]))).rejects.toMatchObject({
+ shouldRetry: false,
+ message: expect.stringContaining("the 'Secrets' and 'Environments' permissions")
});
});
@@ -408,7 +441,7 @@ describe("GitHub permission errors", () => {
await expect(runSync(sync, makePayload(["A"]))).rejects.toMatchObject({
shouldRetry: false,
- message: `Resource not accessible by integration GitHub App installation: ${installationLinks}`
+ message: `Resource not accessible by integration. Grant read and write access to the 'Codespaces secrets' permission. GitHub App installation: ${installationLinks}`
});
});
@@ -425,7 +458,7 @@ describe("GitHub permission errors", () => {
await expect(runSync(sync, makePayload(["A"]))).rejects.toMatchObject({
shouldRetry: false,
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)"
+ "Resource not accessible by integration. Grant read and write access to the 'Organization codespaces secrets' permission. GitHub App installation: https://github.com/settings/installations/172172533 (personal) or https://github.com/organizations/widgets/settings/installations/172172533 (organization)"
});
});
@@ -454,7 +487,8 @@ describe("GitHub permission errors", () => {
).rejects.toMatchObject({
shouldRetry: false,
secretKey: undefined,
- message: "Resource not accessible by integration"
+ message:
+ "Resource not accessible by integration. Grant read and write access to the 'Codespaces secrets' permission."
});
});
diff --git a/backend/src/services/secret-sync/github/github-sync-fns.ts b/backend/src/services/secret-sync/github/github-sync-fns.ts
index a8de9ed65a..1f5d700cce 100644
--- a/backend/src/services/secret-sync/github/github-sync-fns.ts
+++ b/backend/src/services/secret-sync/github/github-sync-fns.ts
@@ -39,6 +39,7 @@ type TGitHubSyncDeps = {
type TGitHubSecretTypeDefinition = {
name: string;
pathSegment: string;
+ permission: { organization: string; repository: string };
limit: { organization: number; repository: number };
};
@@ -46,17 +47,20 @@ const GITHUB_SECRET_TYPES: Record<GitHubSyncSecretType, TGitHubSecretTypeDefinit
[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 }
}
};
@@ -157,6 +161,19 @@ const gitHubResponseMessage = (error: AxiosError) => {
const gitHubSyncAccountLogin = (destinationConfig: TGitHubSyncDestinationConfig) =>
destinationConfig.scope === GitHubSyncScope.Organization ? destinationConfig.org : destinationConfig.owner;
+const requiredGitHubSecretPermission = (destinationConfig: TGitHubSyncDestinationConfig) => {
+ const { permission } = GITHUB_SECRET_TYPES[getGitHubSyncSecretType(destinationConfig)];
+ if (destinationConfig.scope === GitHubSyncScope.RepositoryEnvironment) {
+ return `the '${permission.repository}' and 'Environments' permissions`;
+ }
+
+ const permissionName =
+ destinationConfig.scope === GitHubSyncScope.Organization ? permission.organization : permission.repository;
+ return `the '${permissionName}' permission`;
+};
+
+const joinSentences = (lead: string, rest: string) => (/[.!?]$/.test(lead) ? `${lead} ${rest}` : `${lead}. ${rest}`);
+
const gitHubAppInstallationLinks = (host: string | undefined, installationId: string, accountLogin: string) => {
const webHost = host || "github.com";
const encodedInstallationId = encodeURIComponent(installationId);
@@ -185,7 +202,8 @@ export const toGitHubSecretsError = (
});
}
- let message = gitHubResponseMessage(error);
+ const requiredPermission = `Grant read and write access to ${requiredGitHubSecretPermission(destinationConfig)}.`;
+ let message = joinSentences(gitHubResponseMessage(error), requiredPermission);
if (connection.method === GitHubConnectionMethod.App) {
const { host, installationId } = connection.credentials;
message = `${message} GitHub App installation: ${gitHubAppInstallationLinks(