Skip to content

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

address reviews

Andreybef22b597714
diff --git a/backend/src/ee/services/pam-session-recording/aws-s3/aws-s3-provider-factory.ts b/backend/src/ee/services/pam-session-recording/aws-s3/aws-s3-provider-factory.ts
index 2e19ff72ba..1b037fb389 100644
--- a/backend/src/ee/services/pam-session-recording/aws-s3/aws-s3-provider-factory.ts
+++ b/backend/src/ee/services/pam-session-recording/aws-s3/aws-s3-provider-factory.ts
@@ -1,3 +1,5 @@
+import type { Agent } from "node:https";
+
import {
DeleteObjectCommand,
GetObjectCommand,
@@ -32,13 +34,13 @@ export const PAM_RECORDING_CONNECTION_APPS = [AppConnection.AWS, AppConnection.S
export const resolveS3RecordingAccess = async (
appConnection: TAppConnection,
region: string | undefined
-): Promise<Pick<TPamRecordingResolvedConfig, "region" | "endpoint" | "httpsAgent" | "awsCredentials">> => {
+): Promise<Pick<TPamRecordingResolvedConfig, "region" | "endpoint" | "getHttpsAgent" | "awsCredentials">> => {
if (appConnection.app === AppConnection.S3Compatible) {
const s3Config = await getS3CompatibleConnectionConfig(appConnection);
return {
region: s3Config.region,
endpoint: s3Config.endpoint,
- httpsAgent: s3Config.httpsAgent,
+ getHttpsAgent: s3Config.getHttpsAgent,
awsCredentials: s3Config.credentials
};
}
@@ -57,14 +59,14 @@ export const resolveS3RecordingAccess = async (
return { region, awsCredentials: awsConfig.credentials };
};
-const buildClient = (config: TPamRecordingResolvedConfig) => {
+const buildClient = (config: TPamRecordingResolvedConfig, httpsAgent?: Agent) => {
if (!config.region || !config.awsCredentials) {
throw new BadRequestError({ message: "S3 storage backend requires region and credentials" });
}
return createS3Client({
region: config.region,
endpoint: config.endpoint,
- httpsAgent: config.httpsAgent,
+ httpsAgent,
credentials: config.awsCredentials
});
};
@@ -74,7 +76,7 @@ export const AwsS3RecordingStorageProvider: TPamRecordingStorageProvider = () =>
if (!config.bucket) {
throw new BadRequestError({ message: "Bucket is required for S3 storage backend" });
}
- const client = buildClient(config);
+ const client = buildClient(config, await config.getHttpsAgent?.());
try {
await client.send(new HeadBucketCommand({ Bucket: config.bucket }));
} catch (err) {
@@ -158,7 +160,7 @@ export const AwsS3RecordingStorageProvider: TPamRecordingStorageProvider = () =>
deleteSession: async ({ config, projectId, sessionId }) => {
if (!config.bucket) throw new BadRequestError({ message: "Bucket is required" });
- const client = buildClient(config);
+ const client = buildClient(config, await config.getHttpsAgent?.());
const prefix = `${normalizeKeyPrefix(config.keyPrefix)}${projectId}/${sessionId}/`;
diff --git a/backend/src/ee/services/pam-session-recording/pam-recording-storage-types.ts b/backend/src/ee/services/pam-session-recording/pam-recording-storage-types.ts
index b89e963fc7..487c598cb1 100644
--- a/backend/src/ee/services/pam-session-recording/pam-recording-storage-types.ts
+++ b/backend/src/ee/services/pam-session-recording/pam-recording-storage-types.ts
@@ -13,7 +13,7 @@ export type TPamRecordingResolvedConfig = {
bucket?: string;
region?: string;
endpoint?: string;
- httpsAgent?: Agent;
+ getHttpsAgent?: () => Promise<Agent | undefined>;
keyPrefix?: string | null;
awsCredentials?: {
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 8ce27fc06e..0544965ca1 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -3201,7 +3201,9 @@ export const AppConnections = {
endpoint:
"The S3 API endpoint of the storage provider, without a bucket name: 'https://s3.<region>.amazonaws.com' (AWS S3), 'https://<account-id>.r2.cloudflarestorage.com' (Cloudflare R2), 'https://storage.googleapis.com' (Google Cloud Storage), 'https://<namespace>.compat.objectstorage.<region>.oraclecloud.com' (OCI Object Storage), or a hostname allowed in the Server Console.",
accessKeyId: "The Access Key ID used to authenticate with the storage provider.",
- secretAccessKey: "The Secret Access Key used to authenticate with the storage provider."
+ secretAccessKey: "The Secret Access Key used to authenticate with the storage provider.",
+ region:
+ "The region to sign requests for when the endpoint is a hostname allowed in the Server Console. Defaults to 'us-east-1'. The built-in providers take the region from the endpoint."
}
}
};
diff --git a/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-fns.ts b/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-fns.ts
index 667eff77af..3a6456c51b 100644
--- a/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-fns.ts
+++ b/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-fns.ts
@@ -25,13 +25,19 @@ export const getS3CompatibleConnectionListItem = () => {
};
};
+const buildCustomHostAgent = async (origin: string, host: string) =>
+ (await buildSsrfSafeAgent(origin).catch((error: NodeJS.ErrnoException) => {
+ if (error.code !== "ENOTFOUND" && error.code !== "EAI_AGAIN") throw error;
+ throw new BadRequestError({ message: `Could not resolve ${host}. Verify the hostname and try again.` });
+ })) as Agent | undefined;
+
export const getS3CompatibleConnectionConfig = async ({
credentials
}: {
credentials: TS3CompatibleConnectionConfig["credentials"];
}) => {
const { allowedStorageHostnames } = await getServerCfg();
- const parsed = parseS3CompatibleEndpoint(credentials.endpoint, allowedStorageHostnames ?? []);
+ const parsed = parseS3CompatibleEndpoint(credentials.endpoint, allowedStorageHostnames ?? [], credentials.region);
if (!parsed) {
throw new BadRequestError({ message: S3_COMPATIBLE_ENDPOINT_ERROR });
}
@@ -41,30 +47,24 @@ export const getS3CompatibleConnectionConfig = async ({
? new URL(parsed.origin).host
: S3_COMPATIBLE_PROVIDER_MAP[parsed.provider].name;
- const httpsAgent =
- parsed.provider === S3CompatibleProvider.Custom
- ? ((await buildSsrfSafeAgent(parsed.origin).catch((error: NodeJS.ErrnoException) => {
- if (error.code !== "ENOTFOUND" && error.code !== "EAI_AGAIN") throw error;
- throw new BadRequestError({
- message: `Could not resolve ${providerName}. Verify the hostname and try again.`
- });
- })) as Agent | undefined)
- : undefined;
-
return {
providerName,
region: parsed.region,
endpoint: parsed.provider === S3CompatibleProvider.AwsS3 ? undefined : parsed.origin,
- httpsAgent,
+ getHttpsAgent:
+ parsed.provider === S3CompatibleProvider.Custom
+ ? () => buildCustomHostAgent(parsed.origin, providerName)
+ : undefined,
credentials: { accessKeyId: credentials.accessKeyId, secretAccessKey: credentials.secretAccessKey }
};
};
export const validateS3CompatibleConnectionCredentials = async (config: TS3CompatibleConnectionConfig) => {
- const { providerName, ...clientConfig } = await getS3CompatibleConnectionConfig(config);
+ const { providerName, getHttpsAgent, ...clientConfig } = await getS3CompatibleConnectionConfig(config);
+ const httpsAgent = await getHttpsAgent?.();
try {
- await createS3Client(clientConfig).send(new ListBucketsCommand({}));
+ await createS3Client({ ...clientConfig, httpsAgent }).send(new ListBucketsCommand({}));
} catch (error) {
// keys scoped to a bucket can't list buckets, but an AccessDenied still means the key authenticated
if (error instanceof S3ServiceException && error.name === "AccessDenied") return config.credentials;
diff --git a/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-schemas.ts b/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-schemas.ts
index 04d2689421..24b63a70e4 100644
--- a/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-schemas.ts
+++ b/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-schemas.ts
@@ -19,8 +19,9 @@ const OCI_HOSTNAME = new RE2(
/^[a-z0-9-]+\.compat\.objectstorage\.([a-z0-9-]+)\.(?:oraclecloud\.com|oci\.customer-oci\.com)$/
);
const STORAGE_HOSTNAME = new RE2(/^[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:[0-9]{1,5})?$/);
-// S3-compatible servers on custom hostnames, such as MinIO, accept this region by default
-const CUSTOM_HOSTNAME_SIGNING_REGION = "us-east-1";
+const SIGNING_REGION = new RE2(/^[a-zA-Z0-9_-]+$/);
+// MinIO and most other S3-compatible servers accept this region unless configured otherwise
+const DEFAULT_CUSTOM_HOSTNAME_REGION = "us-east-1";
const isStorageHostname = (hostname: string) => {
try {
@@ -82,7 +83,11 @@ const parseEndpointUrl = (endpoint: string) => {
}
};
-export const parseS3CompatibleEndpoint = (endpoint: string, allowedStorageHostnames: string[]) => {
+export const parseS3CompatibleEndpoint = (
+ endpoint: string,
+ allowedStorageHostnames: string[],
+ customHostRegion?: string
+) => {
const url = parseEndpointUrl(endpoint);
if (!url) return null;
@@ -94,7 +99,11 @@ export const parseS3CompatibleEndpoint = (endpoint: string, allowedStorageHostna
}
if (allowedStorageHostnames.includes(url.host)) {
- return { provider: S3CompatibleProvider.Custom, region: CUSTOM_HOSTNAME_SIGNING_REGION, origin: url.origin };
+ return {
+ provider: S3CompatibleProvider.Custom,
+ region: customHostRegion ?? DEFAULT_CUSTOM_HOSTNAME_REGION,
+ origin: url.origin
+ };
}
return null;
};
@@ -124,7 +133,17 @@ export const S3CompatibleConnectionAccessKeyCredentialsSchema = z.object({
.trim()
.min(1, "Secret Access Key required")
.max(256, "Secret Access Key cannot exceed 256 characters")
- .describe(AppConnections.CREDENTIALS.S3_COMPATIBLE.secretAccessKey)
+ .describe(AppConnections.CREDENTIALS.S3_COMPATIBLE.secretAccessKey),
+ region: z
+ .string()
+ .trim()
+ .max(64, "Region cannot exceed 64 characters")
+ .refine(
+ (region) => SIGNING_REGION.test(region),
+ "Region can only contain letters, numbers, hyphens and underscores"
+ )
+ .optional()
+ .describe(AppConnections.CREDENTIALS.S3_COMPATIBLE.region)
});
const BaseS3CompatibleConnectionSchema = BaseAppConnectionSchema.extend({
@@ -139,7 +158,11 @@ export const S3CompatibleConnectionSchema = BaseS3CompatibleConnectionSchema.ext
export const SanitizedS3CompatibleConnectionSchema = z.discriminatedUnion("method", [
BaseS3CompatibleConnectionSchema.extend({
method: z.literal(S3CompatibleConnectionMethod.AccessKey),
- credentials: S3CompatibleConnectionAccessKeyCredentialsSchema.pick({ endpoint: true, accessKeyId: true })
+ credentials: S3CompatibleConnectionAccessKeyCredentialsSchema.pick({
+ endpoint: true,
+ accessKeyId: true,
+ region: true
+ })
}).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.S3Compatible]} (Access Key)` }))
]);
diff --git a/docs/documentation/platform/admin-panel/server-admin.mdx b/docs/documentation/platform/admin-panel/server-admin.mdx
index 5b68876fb4..994d50d0b3 100644
--- a/docs/documentation/platform/admin-panel/server-admin.mdx
+++ b/docs/documentation/platform/admin-panel/server-admin.mdx
@@ -67,7 +67,7 @@ Select **Save** to apply either change.
If you store [PAM session recordings](/documentation/platform/pam/sessions/external-storage) on your own S3-compatible server, such as MinIO, add the server's hostname under **Hostnames** and select **Save**. Include the port if it isn't 443, such as `minio.example.com:9000`, and make sure the server accepts HTTPS connections. If the hostname resolves to a private IP address, also set [`ALLOW_INTERNAL_IP_CONNECTIONS`](/self-hosting/configuration/envars#param-allow-internal-ip-connections) to `true`.
-An S3-Compatible Storage connection can then use the server as its endpoint, and browsers can play back recordings stored there.
+An S3-Compatible Storage connection can then use the server as its endpoint, and browsers can play back recordings stored there. If the server expects a signing region other than `us-east-1`, as Garage does, enter it under **Region** on the connection.
## Authentication
diff --git a/frontend/src/hooks/api/appConnections/types/s3-compatible-connection.ts b/frontend/src/hooks/api/appConnections/types/s3-compatible-connection.ts
index adb6c9c482..96b5f5839b 100644
--- a/frontend/src/hooks/api/appConnections/types/s3-compatible-connection.ts
+++ b/frontend/src/hooks/api/appConnections/types/s3-compatible-connection.ts
@@ -11,5 +11,6 @@ export type TS3CompatibleConnection = TRootAppConnection & { app: AppConnection.
endpoint: string;
accessKeyId: string;
secretAccessKey: string;
+ region?: string;
};
};
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/S3CompatibleConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/S3CompatibleConnectionForm.tsx
index e6be69a866..db3f10f2aa 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/S3CompatibleConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/S3CompatibleConnectionForm.tsx
@@ -59,7 +59,17 @@ const buildFormSchema = (allowedStorageHostnames: string[]) =>
"Enter the S3 API endpoint of a supported provider, without the bucket name"
),
accessKeyId: z.string().trim().min(1, "Access Key ID required"),
- secretAccessKey: z.string().trim().min(1, "Secret Access Key required")
+ secretAccessKey: z.string().trim().min(1, "Secret Access Key required"),
+ region: z
+ .string()
+ .trim()
+ .max(64, "Region cannot exceed 64 characters")
+ .regex(
+ /^[a-zA-Z0-9_-]*$/,
+ "Region can only contain letters, numbers, hyphens and underscores"
+ )
+ .optional()
+ .transform((region) => region || undefined)
})
})
]);
@@ -98,7 +108,12 @@ export const S3CompatibleConnectionForm = ({ appConnection, onSubmit }: Props) =
}
});
- const { handleSubmit, control } = form;
+ const { handleSubmit, control, watch } = form;
+ const endpointHost = getS3CompatibleProviderName(
+ watch("credentials.endpoint") ?? "",
+ allowedStorageHostnames
+ );
+ const isCustomHost = Boolean(endpointHost && allowedStorageHostnames.includes(endpointHost));
return (
<FormProvider {...form}>
@@ -161,6 +176,31 @@ export const S3CompatibleConnectionForm = ({ appConnection, onSubmit }: Props) =
</Field>
)}
/>
+ {isCustomHost && (
+ <Controller
+ name="credentials.region"
+ control={control}
+ shouldUnregister
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <Field className="mb-4">
+ <FieldLabel htmlFor="region">
+ Region <span className="text-muted">(optional)</span>
+ </FieldLabel>
+ <Input
+ id="region"
+ value={value ?? ""}
+ onChange={(e) => onChange(e.target.value)}
+ placeholder="us-east-1"
+ isError={Boolean(error?.message)}
+ />
+ <FieldDescription>
+ Leave blank unless your server expects a region other than us-east-1.
+ </FieldDescription>
+ <FieldError errors={[error]} />
+ </Field>
+ )}
+ />
+ )}
<Controller
name="credentials.accessKeyId"
control={control}