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
fix(secret-rotation): name Connect permissions when Stripe rejects a key
Calvinb4c0e1145801
diff --git a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.test.ts b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.test.tsindex 24bbbea442..50387b20ad 100644--- a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.test.ts+++ b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.test.ts@@ -50,16 +50,19 @@ const UNUSED_DEPENDENCIES = [{}, {}, {}, {}] as unknown as [// The factory reads these four fields of the rotation row and nothing else, so the rest of the row// is left off rather than filled with placeholders that would read as though they mattered.-const rotation = (activeIndex: number) =>+const rotation = (activeIndex: number, connectPermissions: string[]) =>({connection: { id: "connection-id", credentials: { accountId: "acct_123" } },- parameters: { permissions: ["customer_read"], connectPermissions: [] },+ parameters: { permissions: ["customer_read"], connectPermissions },secretsMapping: { apiKey: "STRIPE_API_KEY" },activeIndex}) as unknown as TStripeApiKeyRotationWithConnection;-const makeFactory = ({ activeIndex = 0 }: { activeIndex?: number } = {}) =>- stripeApiKeyRotationFactory(rotation(activeIndex), ...UNUSED_DEPENDENCIES);+const makeFactory = ({+ activeIndex = 0,+ connectPermissions = []+}: { activeIndex?: number; connectPermissions?: string[] } = {}) =>+ stripeApiKeyRotationFactory(rotation(activeIndex, connectPermissions), ...UNUSED_DEPENDENCIES);const isCreate = (url: string) => url.endsWith("/v2/iam/api_keys");const isExpire = (url: string) => url.endsWith("/expire");@@ -277,6 +280,34 @@ describe("stripeApiKeyRotationFactory", () => {});});+ describe("connect permissions", () => {+ // Nothing readable on the account says whether it is a Connect platform, so a rejected create+ // is the only place a user learns that Connect permissions were the problem.+ it("names Connect permissions as the likely cause when Stripe rejects the create", async () => {+ postMock.mockRejectedValue(httpError(400, "Invalid permissions"));++ await expect(makeFactory({ connectPermissions: ["customer_read"] }).issueCredentials(commit)).rejects.toThrow(+ /not a Connect platform, remove the Connect permissions/+ );+ });++ it("leaves a rejection alone when no Connect permissions were sent", async () => {+ postMock.mockRejectedValue(httpError(400, "Invalid permissions"));++ await expect(makeFactory().issueCredentials(commit)).rejects.toThrow(+ /Infisical cannot manage API keys on Stripe account/+ );+ });++ it("keeps the reinstall remedy when the failure is an authorization one", async () => {+ postMock.mockRejectedValue(httpError(403, "app removed"));++ await expect(makeFactory({ connectPermissions: ["customer_read"] }).issueCredentials(commit)).rejects.toThrow(+ /reinstall it and reconnect/+ );+ });+ });+describe("checkActiveCredentials", () => {it("treats 403 as a live key and 401 as a dead one", async () => {getMock.mockRejectedValueOnce(httpError(403, "Insufficient permissions"));diff --git a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.tsindex 2e530234ab..61fd77eef4 100644--- a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.ts+++ b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.ts@@ -136,6 +136,16 @@ export const stripeApiKeyRotationFactory: TRotationFactory<withIdempotencyKey(getStripeAppRequestConfig(accountId))));} catch (error) {+ // Stripe rejects connect_permissions on an account that is not a Connect platform, without+ // naming the parameter at fault, and nothing we can read off the account says whether it is+ // one. So the rejection carries the likely cause. Only a 400 qualifies: the auth and+ // availability failures have their own remedy and keep it.+ if (connectPermissions?.length && getStripeErrorStatus(error) === 400) {+ throw new BadRequestError({+ message: `Stripe rejected the API key for account '${accountId}': ${getStripeErrorMessage(error)}. If this Stripe account is not a Connect platform, remove the Connect permissions from this rotation and try again.`+ });+ }+return throwStripeApiKeyManagementError(accountId, error);}