Skip to content

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

fix: key name and permissions

varonix86d0728063c9
diff --git a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-constants.ts b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-constants.ts
index 63a5125432..3ecfca49ce 100644
--- a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-constants.ts
+++ b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-constants.ts
@@ -168,6 +168,8 @@ export const STRIPE_API_KEY_PERMISSIONS = [
"webhook_write"
] as const;
+export const STRIPE_API_KEY_NAME_MAX_LENGTH = 80;
+
export type TStripeApiKeyPermission = (typeof STRIPE_API_KEY_PERMISSIONS)[number];
export type TStripeApiKeyPermissionResource = {
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.ts
index 3644f11792..b9005d01b6 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
@@ -1,4 +1,5 @@
import { AxiosError } from "axios";
+import RE2 from "re2";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { TSecretRotationV2Raw } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";
@@ -30,6 +31,7 @@ type TCredential = TStripeApiKeyRotationGeneratedCredentials[number];
type TCreateKeyRequest = {
type: string;
+ name: string;
permissions: string[];
public_key: { pem_key: { data: string } };
};
@@ -50,16 +52,16 @@ 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, keyName?: string) =>
({
connection: { id: "connection-id", credentials: { accountId: "acct_123" } },
- parameters: { permissions: ["customer_read"] },
+ parameters: { permissions: ["customer_read"], keyName },
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, keyName }: { activeIndex?: number; keyName?: string } = {}) =>
+ stripeApiKeyRotationFactory(rotation(activeIndex, keyName), ...UNUSED_DEPENDENCIES);
const isCreate = (url: string) => url.endsWith("/v2/iam/api_keys");
const isExpire = (url: string) => url.endsWith("/expire");
@@ -159,6 +161,20 @@ describe("stripeApiKeyRotationFactory", () => {
expect(createBody?.public_key.pem_key.data).toContain("BEGIN PUBLIC KEY");
});
+ // The old and new key are both live after a rotation, so a fixed name alone would leave two keys
+ // in the Stripe dashboard that cannot be told apart.
+ it.each([
+ { source: "the default name", keyName: undefined, expected: "^infisical-managed-[0-9]{13}$" },
+ { source: "the configured key name", keyName: "payments-service", expected: "^payments-service-[0-9]{13}$" }
+ ])("names the key after $source with a timestamp suffix", async ({ keyName, expected }) => {
+ mockStripe();
+
+ await makeFactory({ keyName }).issueCredentials(commit);
+
+ const name = createBody?.name ?? "";
+ expect(new RE2(expected).test(name), `expected ${expected}, got "${name}"`).toBe(true);
+ });
+
// The key exists in Stripe before the row does, so both failure points after create have to
// take it with them.
it.each([
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.ts
index 96f7d590cd..b46c3cd1fb 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
@@ -40,10 +40,10 @@ export const stripeApiKeyRotationFactory: TRotationFactory<
const { accountId } = connection.credentials;
- // The factory is built without an id at create time, so the name comes from the mapped secret.
- // It is what makes a key stranded by a timed-out create identifiable in the Stripe dashboard.
- const $keyName = () =>
- `${keyName ?? `infisical-${secretsMapping.apiKey}-${Date.now()}`}`.slice(0, STRIPE_KEY_NAME_MAX_LENGTH);
+ // The default name leaves out the mapped secret's name, which would otherwise show in the Stripe
+ // dashboard. The timestamp keeps the old and new key apart while both are live, and is what makes
+ // a key stranded by a timed-out create identifiable there.
+ const $keyName = () => `${keyName ?? `infisical-managed`}-${Date.now()}`.slice(0, STRIPE_KEY_NAME_MAX_LENGTH);
/** No 404 on a double expire has ever been observed, so a non-404 failure on retiring a key that
* was already expired can't be told apart from a real failure by status code alone. This is only
diff --git a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-schemas.ts b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-schemas.ts
index c750c9b60a..7c8ccbd99a 100644
--- a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-schemas.ts
+++ b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-schemas.ts
@@ -10,7 +10,7 @@ import { SecretRotations } from "@app/lib/api-docs";
import { SecretNameSchema } from "@app/server/lib/schemas";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
-import { STRIPE_API_KEY_PERMISSIONS } from "./stripe-api-key-rotation-constants";
+import { STRIPE_API_KEY_NAME_MAX_LENGTH, STRIPE_API_KEY_PERMISSIONS } from "./stripe-api-key-rotation-constants";
export const StripeApiKeyPermissionSchema = z.enum(STRIPE_API_KEY_PERMISSIONS);
@@ -30,7 +30,13 @@ const StripeApiKeyPermissionListSchema = z
.transform((permissions) => [...new Set(permissions)]);
const StripeApiKeyRotationParametersSchema = z.object({
- keyName: z.string().optional().describe(SecretRotations.PARAMETERS.STRIPE_API_KEY.keyName),
+ keyName: z
+ .string()
+ .trim()
+ .min(1, "Key name cannot be empty. Omit it to use the default name.")
+ .max(STRIPE_API_KEY_NAME_MAX_LENGTH, `Key name must be ${STRIPE_API_KEY_NAME_MAX_LENGTH} characters or fewer.`)
+ .optional()
+ .describe(SecretRotations.PARAMETERS.STRIPE_API_KEY.keyName),
permissions: StripeApiKeyPermissionListSchema.describe(SecretRotations.PARAMETERS.STRIPE_API_KEY.permissions)
});
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 661975be59..1dbc961bbd 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -3650,7 +3650,8 @@ export const SecretRotations = {
modulusLength: "The modulus length in bits of the generated RSA key pairs. Defaults to 2048."
},
STRIPE_API_KEY: {
- keyName: "The name of the Stripe API key that will be created and rotated by Infisical.",
+ keyName:
+ "The name for each Stripe API key this rotation creates, up to 80 characters. Infisical appends a timestamp so the old and new key can be told apart. Defaults to 'infisical-managed'.",
permissions:
"The permissions granted to the generated Stripe API key. Stripe has no wildcard permission, so this is the full list of what the key may do."
}
diff --git a/docs/documentation/platform/secret-rotation/stripe-api-key.mdx b/docs/documentation/platform/secret-rotation/stripe-api-key.mdx
index 2e452eaf56..28b22f296e 100644
--- a/docs/documentation/platform/secret-rotation/stripe-api-key.mdx
+++ b/docs/documentation/platform/secret-rotation/stripe-api-key.mdx
@@ -6,7 +6,8 @@ description: "Learn how to automatically rotate Stripe restricted API keys."
<Note>
**Rotation Type: Dual-Phase**
- This rotation maintains two active credential sets with overlapping validity, ensuring zero-downtime during rotation cycles.
+This rotation maintains two active credential sets with overlapping validity, ensuring zero-downtime during rotation cycles.
+
</Note>
Stripe API key rotation mints a new [restricted key](https://docs.stripe.com/keys#limit-access-with-restricted-api-keys) on the interval you set, so your applications always have a working credential without a manual key swap. A few things about how it behaves are worth knowing before you set it up.
@@ -22,7 +23,7 @@ Stripe API key rotation mints a new [restricted key](https://docs.stripe.com/key
## Create a Stripe API key rotation in Infisical
<Tabs>
- <Tab title="Infisical UI">
+ <Tab title="Infisical UI">
1. Navigate to your Secrets Manager Project's Dashboard and select **Add Secret Rotation** from the actions dropdown.
![Secrets Manager Dashboard](/images/secret-rotations-v2/generic/add-secret-rotation.png)
@@ -43,14 +44,11 @@ Stripe API key rotation mints a new [restricted key](https://docs.stripe.com/key
4. Set the Stripe API key parameters, then select **Continue**.
- - **Permissions** - The permissions granted to the generated key. Stripe has no wildcard for "all access", so a key with full access is one where every permission in the list is selected. Use **Select All** to select every permission that matches your current search. If you already have an active Stripe API key with the permissions you want, you can select it from **Copy permissions from an existing key** instead of selecting them by hand.
+ - **Key Name** (optional) - The name of each key the rotation creates, as it appears in the Stripe dashboard. Infisical adds a timestamp to each name, so the old and new key stay distinct while both are valid. If you leave it empty, the name is `infisical-managed`.
+ - **Permissions** - The access the generated key has to each Stripe resource. Set a resource to **None**, **Read**, or **Write**. **Write** includes read access. Stripe has no wildcard for "all access", so grant only the resources your application uses. Use **Set all** to give one access level to every resource that matches your search.
![Rotation Parameters](/images/secret-rotations-v2/stripe-api-key/parameters.png)
- <Note>
- Connect permissions, which apply when the generated key acts on behalf of a connected account under [Stripe Connect](https://docs.stripe.com/connect), have no field in the Infisical UI yet. Set them through the [API](/api-reference/endpoints/secret-rotations/stripe-api-key/create) instead.
- </Note>
-
5. Specify the secret name that the rotated API key will be mapped to. Then select **Continue**.
- **API Key** - The name of the secret in Infisical where the generated restricted key's value will be stored.
@@ -69,10 +67,6 @@ Stripe API key rotation mints a new [restricted key](https://docs.stripe.com/key
![Rotation Review](/images/secret-rotations-v2/stripe-api-key/review.png)
8. Your **Stripe API Key** rotation is created. The current restricted key is available as a secret at the mapped path. Each rotation creates a new key, expires the key from two rotations ago, then switches the active secret to the new key, so two keys are always valid at once for zero-downtime rotation.
-
- <Note>
- Infisical only ever expires the keys it created. Your account's existing keys, including any key you were using before you set up this rotation, are left alone.
- </Note>
</Tab>
<Tab title="API">
To create a Stripe API Key rotation, call the [Create Stripe API Key Rotation](/api-reference/endpoints/secret-rotations/stripe-api-key/create) API endpoint.
@@ -97,6 +91,7 @@ Stripe API key rotation mints a new [restricted key](https://docs.stripe.com/key
"minutes": 0
},
"parameters": {
+ "keyName": "payments-service",
"permissions": ["charge_read", "charge_write", "customer_read", "customer_write"]
},
"secretsMapping": {
@@ -123,10 +118,18 @@ Stripe API key rotation mints a new [restricted key](https://docs.stripe.com/key
"rotateAtUtc": { "hours": 0, "minutes": 0 },
"type": "stripe-api-key",
"parameters": {
+ "keyName": "payments-service",
"permissions": ["charge_read", "charge_write", "customer_read", "customer_write"]
}
}
}
```
</Tab>
+
</Tabs>
+
+<Note>
+ Infisical only ever expires the keys it created. Your account's existing keys,
+ including any key you were using before you set up this rotation, are left
+ alone.
+</Note>
diff --git a/docs/images/secret-rotations-v2/stripe-api-key/parameters.png b/docs/images/secret-rotations-v2/stripe-api-key/parameters.png
index b0b693f999..3564a8258c 100644
Binary files a/docs/images/secret-rotations-v2/stripe-api-key/parameters.png and b/docs/images/secret-rotations-v2/stripe-api-key/parameters.png differ
diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/StripeApiKeyPermissionSelector.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/StripeApiKeyPermissionSelector.tsx
index 45054aa8de..44ffa37827 100644
--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/StripeApiKeyPermissionSelector.tsx
+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/StripeApiKeyPermissionSelector.tsx
@@ -189,7 +189,8 @@ export const StripeApiKeyPermissionSelector = ({ groups, value, onChange, isLoad
)}
</div>
<p className="text-xs text-muted">
- Grant the minimum access Infisical needs to create and revoke this key.
+ Grant only the access your application needs. The generated key gets exactly these
+ permissions.
</p>
<div
role="group"
diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/StripeApiKeyRotationParametersFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/StripeApiKeyRotationParametersFields.tsx
index ff169727d4..a518ff695e 100644
--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/StripeApiKeyRotationParametersFields.tsx
+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/StripeApiKeyRotationParametersFields.tsx
@@ -5,8 +5,8 @@ import { TSecretRotationV2Form } from "@app/components/secret-rotations-v2/forms
import { Field, FieldError, Input } from "@app/components/v3";
import { SecretRotation, useSecretRotationV2Option } from "@app/hooks/api/secretRotationsV2";
-import { StripeApiKeyPermissionSelector } from "./StripeApiKeyPermissionSelector";
import { FieldLabelWithTooltip } from "../shared";
+import { StripeApiKeyPermissionSelector } from "./StripeApiKeyPermissionSelector";
export const StripeApiKeyRotationParametersFields = () => {
const { control } = useFormContext<
@@ -26,14 +26,14 @@ export const StripeApiKeyRotationParametersFields = () => {
<Field data-invalid={Boolean(error)}>
<FieldLabelWithTooltip
htmlFor="secret-rotation-key-name"
- tooltip="The name of the key to use for the secret rotation. This is used to identify the key in the Stripe API. This is optional and will default to a random key name in Stripe."
+ tooltip="Optional. The name of each key this rotation creates in Stripe. Infisical adds a timestamp to each name so you can tell the old and new key apart. If empty, the name is infisical-managed."
>
Key Name
</FieldLabelWithTooltip>
<Input
id="secret-rotation-key-name"
- placeholder="Infisical Managed Stripe Key"
- value={value}
+ placeholder="e.g. payments-service"
+ value={value ?? ""}
onChange={onChange}
/>
<FieldError>{error?.message}</FieldError>
diff --git a/frontend/src/components/secret-rotations-v2/forms/schemas/stripe-api-key-rotation-schema.ts b/frontend/src/components/secret-rotations-v2/forms/schemas/stripe-api-key-rotation-schema.ts
index d95cd3bbc6..2883fde98d 100644
--- a/frontend/src/components/secret-rotations-v2/forms/schemas/stripe-api-key-rotation-schema.ts
+++ b/frontend/src/components/secret-rotations-v2/forms/schemas/stripe-api-key-rotation-schema.ts
@@ -8,7 +8,13 @@ export const StripeApiKeyRotationSchema = z
type: z.literal(SecretRotation.StripeApiKey),
parameters: z.object({
permissions: z.string().trim().array().min(1, "Grant at least one permission"),
- keyName: z.string().max(100, "Key name must be less than 100 characters").trim().optional()
+ // A cleared field would otherwise send "", which the API rejects, instead of the default name.
+ keyName: z
+ .string()
+ .trim()
+ .max(80, "Key name must be 80 characters or fewer")
+ .optional()
+ .transform((keyName) => keyName || undefined)
}),
secretsMapping: z.object({
apiKey: z.string().trim().min(1, "API Key secret name required")
diff --git a/frontend/src/hooks/api/secretRotationsV2/types/stripe-api-key-rotation.ts b/frontend/src/hooks/api/secretRotationsV2/types/stripe-api-key-rotation.ts
index a69b766f5b..adea13d53d 100644
--- a/frontend/src/hooks/api/secretRotationsV2/types/stripe-api-key-rotation.ts
+++ b/frontend/src/hooks/api/secretRotationsV2/types/stripe-api-key-rotation.ts
@@ -8,6 +8,7 @@ import {
export type TStripeApiKeyRotation = TSecretRotationV2Base & {
type: SecretRotation.StripeApiKey;
parameters: {
+ keyName?: string;
permissions: string[];
};
secretsMapping: {