Skip to content

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

chore: remove unused code

adilson213010a48bf7
diff --git a/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-constants.ts b/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-constants.ts
index b422643ab6..97cde7f8b9 100644
--- a/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-constants.ts
+++ b/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-constants.ts
@@ -9,6 +9,9 @@ export const CLOUDFLARE_R2_ACCESS_KEY_ROTATION_LIST_OPTION: TSecretRotationV2Lis
type: SecretRotation.CloudflareR2AccessKey,
connection: AppConnection.Cloudflare,
template: {
+ parameters: {
+ accessLevel: CloudflareR2AccessLevel.ObjectRead
+ },
secretsMapping: {
apiToken: "CLOUDFLARE_R2_API_TOKEN",
accessKeyId: "CLOUDFLARE_R2_ACCESS_KEY_ID",
diff --git a/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-fns.ts
index d6dbc41cc1..7dbcdecae8 100644
--- a/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-fns.ts
@@ -20,7 +20,6 @@ import {
getCloudflareErrorMessage,
listCloudflarePermissionGroups
} from "@app/services/app-connection/cloudflare/cloudflare-connection-fns";
-import { TCloudflarePermissionGroup } from "@app/services/app-connection/cloudflare/cloudflare-connection-types";
import {
CLOUDFLARE_R2_ACCESS_LEVEL_PERMISSION_GROUPS,
@@ -50,13 +49,12 @@ export const cloudflareR2AccessKeyRotationFactory: TRotationFactory<
* does not validate these keys when the token is created, so a bucket renamed or deleted after the
* rotation was configured yields a token that grants nothing rather than an error.
*/
- const $buildResources = (): Record<string, string> =>
- Object.fromEntries(
- buckets.map(({ name: bucketName, jurisdiction }) => [
- `com.cloudflare.edge.r2.bucket.${accountId}_${jurisdiction}_${bucketName}`,
- "*"
- ])
- );
+ const bucketResources = Object.fromEntries(
+ buckets.map(({ name: bucketName, jurisdiction }) => [
+ `${CLOUDFLARE_R2_BUCKET_PERMISSION_SCOPE}.${accountId}_${jurisdiction}_${bucketName}`,
+ "*"
+ ])
+ );
/**
* R2's S3-compatible secret access key is the hex sha256 of the API token's value, and the access key
@@ -65,7 +63,7 @@ export const cloudflareR2AccessKeyRotationFactory: TRotationFactory<
const $toSecretAccessKey = (tokenValue: string) =>
crypto.nativeCrypto.createHash("sha256").update(tokenValue).digest("hex");
- const $listPermissionGroups = async (): Promise<TCloudflarePermissionGroup[]> => {
+ const $listPermissionGroups = async () => {
try {
return await listCloudflarePermissionGroups(connection);
} catch (error: unknown) {
@@ -111,7 +109,7 @@ export const cloudflareR2AccessKeyRotationFactory: TRotationFactory<
policies: [
{
effect: CloudflareTokenPolicyEffect.Allow,
- resources: $buildResources(),
+ resources: bucketResources,
permissionGroupIds
}
]
diff --git a/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-schemas.ts b/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-schemas.ts
index 24fef7e5f9..197ef09092 100644
--- a/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-schemas.ts
+++ b/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-schemas.ts
@@ -57,19 +57,14 @@ const CloudflareR2AccessKeyRotationParametersSchema = z.object({
name: CloudflareTokenNameSchema.describe(SecretRotations.PARAMETERS.CLOUDFLARE_R2_ACCESS_KEY.name),
buckets: CloudflareR2BucketSchema.array()
.min(1, "At least one bucket is required")
- .superRefine((buckets, ctx) => {
- const keys = buckets.map(({ name, jurisdiction }) => `${jurisdiction}:${name}`);
-
- if (new Set(keys).size !== keys.length) {
- ctx.addIssue({
- code: z.ZodIssueCode.custom,
- message: "Buckets must be unique"
- });
- }
- })
+ .refine(
+ (buckets) => new Set(buckets.map(({ name, jurisdiction }) => `${jurisdiction}:${name}`)).size === buckets.length,
+ "Buckets must be unique"
+ )
.describe(SecretRotations.PARAMETERS.CLOUDFLARE_R2_ACCESS_KEY.buckets),
accessLevel: z
.nativeEnum(CloudflareR2AccessLevel)
+ .default(CloudflareR2AccessLevel.ObjectRead)
.describe(SecretRotations.PARAMETERS.CLOUDFLARE_R2_ACCESS_KEY.accessLevel),
allowedIps: CloudflareTokenIpRestrictionSchema.array()
.optional()
@@ -86,6 +81,10 @@ const CloudflareR2AccessKeyRotationSecretsMappingSchema = z.object({
});
export const CloudflareR2AccessKeyRotationTemplateSchema = z.object({
+ // seeds the create form; the least-privileged level is the right thing to land on by default
+ parameters: z.object({
+ accessLevel: z.nativeEnum(CloudflareR2AccessLevel)
+ }),
secretsMapping: z.object({
apiToken: z.string(),
accessKeyId: z.string(),
diff --git a/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-types.ts b/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-types.ts
index 09c30f5f60..185f6f438a 100644
--- a/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-types.ts
+++ b/backend/src/ee/services/secret-rotation-v2/cloudflare-r2-access-key/cloudflare-r2-access-key-rotation-types.ts
@@ -6,7 +6,6 @@ import {
CloudflareR2AccessKeyRotationGeneratedCredentialsSchema,
CloudflareR2AccessKeyRotationListItemSchema,
CloudflareR2AccessKeyRotationSchema,
- CloudflareR2BucketSchema,
CreateCloudflareR2AccessKeyRotationSchema
} from "./cloudflare-r2-access-key-rotation-schemas";
@@ -23,6 +22,3 @@ export type TCloudflareR2AccessKeyRotationWithConnection = TCloudflareR2AccessKe
export type TCloudflareR2AccessKeyRotationGeneratedCredentials = z.infer<
typeof CloudflareR2AccessKeyRotationGeneratedCredentialsSchema
>;
-
-/** A bucket as selected on the rotation, distinct from the app connection's richer listing type. */
-export type TCloudflareR2AccessKeyBucket = z.infer<typeof CloudflareR2BucketSchema>;
diff --git a/backend/src/ee/services/secret-rotation-v2/shared/cloudflare-token/cloudflare-token-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/shared/cloudflare-token/cloudflare-token-rotation-fns.ts
index 17743bfc8a..2e1f7b62e8 100644
--- a/backend/src/ee/services/secret-rotation-v2/shared/cloudflare-token/cloudflare-token-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/shared/cloudflare-token/cloudflare-token-rotation-fns.ts
@@ -19,7 +19,7 @@ import {
TCloudflareVerifyTokenResponse
} from "./cloudflare-token-rotation-types";
-export const getCloudflareTokenExpiresOn = (rotationInterval: number) => {
+const getCloudflareTokenExpiresOn = (rotationInterval: number) => {
const days = Math.max(rotationInterval * 2 + 1, CLOUDFLARE_TOKEN_MIN_TTL_DAYS);
const expiresOn = new Date();
@@ -31,7 +31,7 @@ export const getCloudflareTokenExpiresOn = (rotationInterval: number) => {
};
// an empty `in` list would deny every request, so we omit either side rather than sending []
-export const buildCloudflareTokenCondition = ({
+const buildCloudflareTokenCondition = ({
allowedIps,
disallowedIps
}: TCloudflareTokenRestrictions): TCloudflareTokenCondition | undefined => {
diff --git a/backend/src/server/routes/v1/app-connection-routers/cloudflare-connection-router.ts b/backend/src/server/routes/v1/app-connection-routers/cloudflare-connection-router.ts
index 2126edcf02..ea67db5ace 100644
--- a/backend/src/server/routes/v1/app-connection-routers/cloudflare-connection-router.ts
+++ b/backend/src/server/routes/v1/app-connection-routers/cloudflare-connection-router.ts
@@ -157,10 +157,7 @@ export const registerCloudflareConnectionRouter = async (server: FastifyZodProvi
200: z
.object({
name: z.string(),
- jurisdiction: z.nativeEnum(CloudflareR2Jurisdiction),
- location: z.string().optional(),
- storageClass: z.string().optional(),
- creationDate: z.string().optional()
+ jurisdiction: z.nativeEnum(CloudflareR2Jurisdiction)
})
.array()
}
diff --git a/backend/src/services/app-connection/cloudflare/cloudflare-connection-fns.ts b/backend/src/services/app-connection/cloudflare/cloudflare-connection-fns.ts
index bacf908e80..3d4dc71b89 100644
--- a/backend/src/services/app-connection/cloudflare/cloudflare-connection-fns.ts
+++ b/backend/src/services/app-connection/cloudflare/cloudflare-connection-fns.ts
@@ -22,8 +22,8 @@ import {
const CLOUDFLARE_PER_PAGE = 50;
const CLOUDFLARE_MAX_PAGES = 100;
-// R2 accepts up to 1000 per page; 100 keeps responses small while rarely needing a second request
-const CLOUDFLARE_R2_BUCKETS_PER_PAGE = 100;
+// R2's maximum. Cursor pagination is strictly sequential, so a large page keeps round-trips down.
+const CLOUDFLARE_R2_BUCKETS_PER_PAGE = 1000;
export const getCloudflareAuthHeaders = (apiToken: string) => ({
Authorization: `Bearer ${apiToken}`,
@@ -124,11 +124,7 @@ export const listCloudflareZones = async (appConnection: TCloudflareConnection):
}));
};
-/**
- * Unlike the other list endpoints, token permission groups don't reliably report
- * `result_info.total_pages`, so this paginates on its own: keep requesting while a page comes back
- * full and stop on the first partial page.
- */
+/** This endpoint returns the account's full set of token permission groups in one response. */
export const listCloudflarePermissionGroups = async (
appConnection: TCloudflareConnection
): Promise<TCloudflarePermissionGroup[]> => {
@@ -138,7 +134,6 @@ export const listCloudflarePermissionGroups = async (
const { data } = await safeRequest.get<{
result: { id: string; name: string; scopes?: string[] }[];
- result_info?: { count?: number };
}>(`${IntegrationUrls.CLOUDFLARE_API_URL}/client/v4/accounts/${accountId}/tokens/permission_groups`, {
headers: getCloudflareAuthHeaders(apiToken)
});
@@ -182,14 +177,11 @@ const $listCloudflareR2BucketsForJurisdiction = async ({
...(data.result?.buckets ?? []).map((bucket) => ({
name: bucket.name,
// the payload omits the jurisdiction for `default`, so fall back to the one we asked for
- jurisdiction: (bucket.jurisdiction as CloudflareR2Jurisdiction) || jurisdiction,
- location: bucket.location,
- storageClass: bucket.storage_class,
- creationDate: bucket.creation_date
+ jurisdiction: (bucket.jurisdiction as CloudflareR2Jurisdiction) || jurisdiction
}))
);
- cursor = data.result_info?.cursor || undefined;
+ cursor = data.result_info?.cursor;
if (!cursor) break;
}
diff --git a/backend/src/services/app-connection/cloudflare/cloudflare-connection-types.ts b/backend/src/services/app-connection/cloudflare/cloudflare-connection-types.ts
index d039eeaebc..96f9c5017c 100644
--- a/backend/src/services/app-connection/cloudflare/cloudflare-connection-types.ts
+++ b/backend/src/services/app-connection/cloudflare/cloudflare-connection-types.ts
@@ -46,13 +46,10 @@ export type TCloudflarePermissionGroup = {
scopes: string[];
};
+/** Name and jurisdiction together identify a bucket, and are all a token policy needs to grant it. */
export type TCloudflareR2Bucket = {
name: string;
jurisdiction: CloudflareR2Jurisdiction;
- // the physical region the bucket's data lives in, e.g. "weur" — informational only
- location?: string;
- storageClass?: string;
- creationDate?: string;
};
/** Raw shape returned by Cloudflare's `GET /accounts/:id/r2/buckets` list endpoint. */
@@ -60,10 +57,7 @@ export type TCloudflareR2BucketsApiResponse = {
result: {
buckets?: {
name: string;
- creation_date?: string;
jurisdiction?: string;
- location?: string;
- storage_class?: string;
}[];
} | null;
result_info?: { cursor?: string };