Skip to content

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

allow custom hostnames on dedicated instances

Andrey3ef6d384da21
diff --git a/backend/src/db/migrations/20261008120000_super-admin-allowed-storage-hostnames.ts b/backend/src/db/migrations/20261008120000_super-admin-allowed-storage-hostnames.ts
new file mode 100644
index 0000000000..77e80ce141
--- /dev/null
+++ b/backend/src/db/migrations/20261008120000_super-admin-allowed-storage-hostnames.ts
@@ -0,0 +1,19 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas/models";
+
+export async function up(knex: Knex): Promise<void> {
+ if (!(await knex.schema.hasColumn(TableName.SuperAdmin, "allowedStorageHostnames"))) {
+ await knex.schema.alterTable(TableName.SuperAdmin, (t) => {
+ t.specificType("allowedStorageHostnames", "text[]");
+ });
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ if (await knex.schema.hasColumn(TableName.SuperAdmin, "allowedStorageHostnames")) {
+ await knex.schema.alterTable(TableName.SuperAdmin, (t) => {
+ t.dropColumn("allowedStorageHostnames");
+ });
+ }
+}
diff --git a/backend/src/db/schemas/super-admin.ts b/backend/src/db/schemas/super-admin.ts
index cc2f04c339..e126376e0e 100644
--- a/backend/src/db/schemas/super-admin.ts
+++ b/backend/src/db/schemas/super-admin.ts
@@ -35,7 +35,8 @@ export const SuperAdminSchema = z.object({
encryptedGitHubAppConnectionPrivateKey: zodBuffer.nullable().optional(),
encryptedEnvOverrides: zodBuffer.nullable().optional(),
fipsEnabled: z.boolean().default(false),
- onboardingCompleted: z.boolean().default(false)
+ onboardingCompleted: z.boolean().default(false),
+ allowedStorageHostnames: z.string().array().nullable().optional()
});
export type TSuperAdmin = z.infer<typeof SuperAdminSchema>;
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 3ea6ced0e0..e7c09117b5 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
@@ -34,7 +34,7 @@ export const resolveS3RecordingAccess = async (
region: string | undefined
): Promise<Pick<TPamRecordingResolvedConfig, "region" | "endpoint" | "awsCredentials">> => {
if (appConnection.app === AppConnection.S3Compatible) {
- const s3Config = getS3CompatibleConnectionConfig(appConnection);
+ const s3Config = await getS3CompatibleConnectionConfig(appConnection);
return { region: s3Config.region, endpoint: s3Config.endpoint, awsCredentials: s3Config.credentials };
}
diff --git a/backend/src/ee/services/pam/CLAUDE.md b/backend/src/ee/services/pam/CLAUDE.md
index c9cf57332e..b51a8f6f82 100644
--- a/backend/src/ee/services/pam/CLAUDE.md
+++ b/backend/src/ee/services/pam/CLAUDE.md
@@ -178,7 +178,8 @@ template's `settings` column, not `policies`. Both are edited on the template de
**External recording storage** is the `aws-s3` backend whether the connection is AWS or S3-Compatible Storage
(`resolveS3RecordingAccess`). Don't add a backend per provider: the value is in each chunk's AAD and in the
-backend list gateways read.
+backend list gateways read. Hosts beyond the built-in providers come from the server admin's
+`allowedStorageHostnames`, which `serve-ui.ts` also adds to the CSP `connect-src`, since browsers fetch chunks directly.
**Break-glass** lets a requester self-approve their own pending request, and needs **both** gates open:
the account's template carries `allow-break-glass`, *and* the folder's approval policy names the actor in
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 818d390a4c..2332276190 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -3124,7 +3124,7 @@ export const AppConnections = {
},
S3_COMPATIBLE: {
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), or 'https://<namespace>.compat.objectstorage.<region>.oraclecloud.com' (OCI Object Storage).",
+ "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."
}
diff --git a/backend/src/server/plugins/serve-ui.ts b/backend/src/server/plugins/serve-ui.ts
index 8fc0134f39..3194d8b694 100644
--- a/backend/src/server/plugins/serve-ui.ts
+++ b/backend/src/server/plugins/serve-ui.ts
@@ -5,6 +5,23 @@ import staticServe from "@fastify/static";
import RE2 from "re2";
import { getConfig, IS_PACKAGED } from "@app/lib/config/env";
+import { logger } from "@app/lib/logger";
+import { getServerCfg } from "@app/services/super-admin/super-admin-service";
+
+const CONNECT_SRC_DIRECTIVE = new RE2("(connect-src\\s+[^;]+)(;)");
+
+// browsers download session recordings straight from storage hosts a server admin allowed
+const withAllowedStorageHostnames = async (indexHtml: string) => {
+ try {
+ const { allowedStorageHostnames } = await getServerCfg();
+ if (!allowedStorageHostnames?.length) return indexHtml;
+ const hosts = allowedStorageHostnames.map((hostname) => `https://${hostname}`).join(" ");
+ return indexHtml.replace(CONNECT_SRC_DIRECTIVE, `$1 ${hosts}$2`);
+ } catch (err) {
+ logger.warn(err, "serve-ui: could not load allowed storage hostnames");
+ return indexHtml;
+ }
+};
// to enabled this u need to set standalone mode to true
export const registerServeUI = async (
@@ -138,7 +155,7 @@ export const registerServeUI = async (
schema: {
hide: true
},
- handler: (request, reply) => {
+ handler: async (request, reply) => {
if (request.url.startsWith("/api")) {
reply.callNotFound();
return;
@@ -149,7 +166,7 @@ export const registerServeUI = async (
.header("Cache-Control", "no-cache, no-store, must-revalidate")
.header("Pragma", "no-cache")
.header("Expires", "0")
- .send(indexHtml);
+ .send(await withAllowedStorageHostnames(indexHtml));
}
});
}
diff --git a/backend/src/server/routes/v1/admin-router.ts b/backend/src/server/routes/v1/admin-router.ts
index a437b82f3b..88d4376d68 100644
--- a/backend/src/server/routes/v1/admin-router.ts
+++ b/backend/src/server/routes/v1/admin-router.ts
@@ -22,6 +22,7 @@ import { GenericResourceNameSchema } from "@app/server/lib/schemas";
import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
import { verifySuperAdmin } from "@app/server/plugins/auth/superAdmin";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
+import { StorageHostnameSchema } from "@app/services/app-connection/s3-compatible";
import { AuthMode } from "@app/services/auth/auth-type";
import { RootKeyEncryptionStrategy } from "@app/services/kms/kms-types";
import { isSuperAdmin } from "@app/services/super-admin/super-admin-fns";
@@ -44,6 +45,7 @@ const SanitizedSuperAdminSchema = z.object({
enabledLoginMethods: z.string().array().nullable().optional(),
authConsentContent: z.string().nullable().optional(),
pageFrameContent: z.string().nullable().optional(),
+ allowedStorageHostnames: z.string().array().nullable().optional(),
// Populated on self-hosted instances when a newer release than the running version exists
latestAvailableVersion: z.string().nullable().optional(),
// Super admin-only fields (omitted for non-super-admin callers)
@@ -112,6 +114,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
passwordPolicy: PASSWORD_POLICY,
authConsentContent: config.authConsentContent,
pageFrameContent: config.pageFrameContent,
+ allowedStorageHostnames: config.allowedStorageHostnames,
isPublicSecretSharingDisabled: serverEnvs.DISABLE_PUBLIC_SECRET_SHARING,
isClickhouseAuditLogEnabled,
latestAvailableVersion
@@ -182,6 +185,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
message: "Page frame content contains unsafe HTML."
})
.optional(),
+ allowedStorageHostnames: StorageHostnameSchema.array().max(50).optional(),
envOverrides: z.record(z.enum(Array.from(overridableKeys) as [string, ...string[]]), z.string()).optional()
}),
response: {
diff --git a/backend/src/services/app-connection/s3-compatible/index.ts b/backend/src/services/app-connection/s3-compatible/index.ts
index 4fd0399064..48fa62e513 100644
--- a/backend/src/services/app-connection/s3-compatible/index.ts
+++ b/backend/src/services/app-connection/s3-compatible/index.ts
@@ -8,6 +8,7 @@ export {
CreateS3CompatibleConnectionSchema,
S3CompatibleConnectionListItemSchema,
SanitizedS3CompatibleConnectionSchema,
+ StorageHostnameSchema,
UpdateS3CompatibleConnectionSchema,
ValidateS3CompatibleConnectionCredentialsSchema
} from "./s3-compatible-connection-schemas";
diff --git a/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-enums.ts b/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-enums.ts
index 1beb68e11b..24524995a3 100644
--- a/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-enums.ts
+++ b/backend/src/services/app-connection/s3-compatible/s3-compatible-connection-enums.ts
@@ -6,5 +6,6 @@ export enum S3CompatibleProvider {
AwsS3 = "aws-s3",
CloudflareR2 = "cloudflare-r2",
GoogleCloudStorage = "google-cloud-storage",
- OciObjectStorage = "oci-object-storage"
+ OciObjectStorage = "oci-object-storage",
+ Custom = "custom"
}
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 84afb7e209..189faa07f0 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
@@ -3,10 +3,15 @@ import { ListBucketsCommand, S3ServiceException } from "@aws-sdk/client-s3";
import { createS3Client } from "@app/lib/aws/s3";
import { BadRequestError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
+import { getServerCfg } from "@app/services/super-admin/super-admin-service";
import { AppConnection } from "../app-connection-enums";
import { S3CompatibleConnectionMethod, S3CompatibleProvider } from "./s3-compatible-connection-enums";
-import { parseS3CompatibleEndpoint, S3_COMPATIBLE_PROVIDER_MAP } from "./s3-compatible-connection-schemas";
+import {
+ parseS3CompatibleEndpoint,
+ S3_COMPATIBLE_ENDPOINT_ERROR,
+ S3_COMPATIBLE_PROVIDER_MAP
+} from "./s3-compatible-connection-schemas";
import { TS3CompatibleConnectionConfig } from "./s3-compatible-connection-types";
export const getS3CompatibleConnectionListItem = () => {
@@ -17,20 +22,22 @@ export const getS3CompatibleConnectionListItem = () => {
};
};
-export const getS3CompatibleConnectionConfig = ({
+export const getS3CompatibleConnectionConfig = async ({
credentials
}: {
credentials: TS3CompatibleConnectionConfig["credentials"];
}) => {
- const parsed = parseS3CompatibleEndpoint(credentials.endpoint);
+ const { allowedStorageHostnames } = await getServerCfg();
+ const parsed = parseS3CompatibleEndpoint(credentials.endpoint, allowedStorageHostnames ?? []);
if (!parsed) {
- throw new BadRequestError({
- message: "The S3-Compatible Storage connection's endpoint is not supported. Update the connection's endpoint."
- });
+ throw new BadRequestError({ message: S3_COMPATIBLE_ENDPOINT_ERROR });
}
return {
- provider: parsed.provider,
+ providerName:
+ parsed.provider === S3CompatibleProvider.Custom
+ ? new URL(parsed.origin).host
+ : S3_COMPATIBLE_PROVIDER_MAP[parsed.provider].name,
region: parsed.region,
endpoint: parsed.provider === S3CompatibleProvider.AwsS3 ? undefined : parsed.origin,
credentials: { accessKeyId: credentials.accessKeyId, secretAccessKey: credentials.secretAccessKey }
@@ -38,8 +45,7 @@ export const getS3CompatibleConnectionConfig = ({
};
export const validateS3CompatibleConnectionCredentials = async (config: TS3CompatibleConnectionConfig) => {
- const { provider, ...clientConfig } = getS3CompatibleConnectionConfig(config);
- const providerName = S3_COMPATIBLE_PROVIDER_MAP[provider].name;
+ const { providerName, ...clientConfig } = await getS3CompatibleConnectionConfig(config);
try {
await createS3Client(clientConfig).send(new ListBucketsCommand({}));
@@ -49,7 +55,7 @@ export const validateS3CompatibleConnectionCredentials = async (config: TS3Compa
logger.warn(
{ err: error },
- `S3-Compatible Storage credential check failed [orgId=${config.orgId}] [provider=${provider}]`
+ `S3-Compatible Storage credential check failed [orgId=${config.orgId}] [provider=${providerName}]`
);
if (error instanceof S3ServiceException) {
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 a1d8a2212f..626ac1c4a2 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
@@ -18,9 +18,27 @@ const R2_HOSTNAME = new RE2(/^[a-f0-9]{32}(\.[a-z]+)?\.r2\.cloudflarestorage\.co
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 isStorageHostname = (hostname: string) => {
+ try {
+ return STORAGE_HOSTNAME.test(hostname) && new URL(`https://${hostname}`).host === hostname;
+ } catch {
+ return false;
+ }
+};
+
+export const StorageHostnameSchema = z
+ .string()
+ .trim()
+ .toLowerCase()
+ .max(253, "Hostname cannot exceed 253 characters")
+ .refine(isStorageHostname, "Enter a hostname, with a port if it isn't 443, such as minio.example.com:9000");
export const S3_COMPATIBLE_PROVIDER_MAP: Record<
- S3CompatibleProvider,
+ Exclude<S3CompatibleProvider, S3CompatibleProvider.Custom>,
{
name: string;
endpointExample: string;
@@ -52,38 +70,39 @@ export const S3_COMPATIBLE_PROVIDER_MAP: Record<
}
};
-export const parseS3CompatibleEndpoint = (endpoint: string) => {
- let url: URL;
+const parseEndpointUrl = (endpoint: string) => {
try {
- url = new URL(endpoint);
+ const url = new URL(endpoint);
+ if (url.protocol !== "https:" || url.username || url.password || url.pathname !== "/" || url.search || url.hash) {
+ return null;
+ }
+ return url;
} catch {
return null;
}
+};
- if (
- url.protocol !== "https:" ||
- url.port ||
- url.username ||
- url.password ||
- url.pathname !== "/" ||
- url.search ||
- url.hash
- ) {
- return null;
+export const parseS3CompatibleEndpoint = (endpoint: string, allowedStorageHostnames: string[]) => {
+ const url = parseEndpointUrl(endpoint);
+ if (!url) return null;
+
+ if (allowedStorageHostnames.includes(url.host)) {
+ return { provider: S3CompatibleProvider.Custom, region: CUSTOM_HOSTNAME_SIGNING_REGION, origin: url.origin };
}
+ if (url.port) return null;
- for (const provider of Object.values(S3CompatibleProvider)) {
+ for (const provider of Object.keys(S3_COMPATIBLE_PROVIDER_MAP) as (keyof typeof S3_COMPATIBLE_PROVIDER_MAP)[]) {
const region = S3_COMPATIBLE_PROVIDER_MAP[provider].getSigningRegion(url.hostname);
if (region) return { provider, region, origin: url.origin };
}
return null;
};
-const S3_COMPATIBLE_ENDPOINT_ERROR = `Endpoint must be the S3 API endpoint of a supported provider, without a bucket name: ${Object.values(
+export const S3_COMPATIBLE_ENDPOINT_ERROR = `Endpoint must be the S3 API endpoint of a supported provider, without a bucket name: ${Object.values(
S3_COMPATIBLE_PROVIDER_MAP
)
.map(({ name, endpointExample }) => `${endpointExample} (${name})`)
- .join(", ")}`;
+ .join(", ")}, or a hostname allowed in the Server Console`;
export const S3CompatibleConnectionAccessKeyCredentialsSchema = z.object({
endpoint: z
@@ -91,7 +110,7 @@ export const S3CompatibleConnectionAccessKeyCredentialsSchema = z.object({
.trim()
.min(1, "Endpoint required")
.max(256, "Endpoint cannot exceed 256 characters")
- .refine((endpoint) => Boolean(parseS3CompatibleEndpoint(endpoint)), S3_COMPATIBLE_ENDPOINT_ERROR)
+ .refine((endpoint) => Boolean(parseEndpointUrl(endpoint)), "Endpoint must be an HTTPS URL without a bucket name")
.describe(AppConnections.CREDENTIALS.S3_COMPATIBLE.endpoint),
accessKeyId: z
.string()
diff --git a/docs/documentation/platform/admin-panel/server-admin.mdx b/docs/documentation/platform/admin-panel/server-admin.mdx
index e5c36ddd56..194606c73c 100644
--- a/docs/documentation/platform/admin-panel/server-admin.mdx
+++ b/docs/documentation/platform/admin-panel/server-admin.mdx
@@ -20,7 +20,7 @@ The console opens on **General**. The sidebar holds the rest of the instance set
## General
-Instance-wide settings for signups, the default organization, LDAP email trust, and the notices users see.
+Instance-wide settings for signups, the default organization, LDAP email trust, the notices users see, and allowed storage hostnames.
![General settings](/images/platform/admin-panels/admin-panel-general.png)
![Notice settings](/images/platform/admin-panels/admin-panel-general-1.png)
@@ -63,6 +63,12 @@ Users see **Auth consent content** on the login page. Use it for anything they s
Select **Save** to apply either change.
+### Allowed storage hostnames
+
+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.
+
+An S3-Compatible Storage connection can then use the server as its endpoint, and browsers can play back recordings stored there.
+
## Authentication
Use **Login Methods** to choose the login methods available on the instance. Turn a method off here and no organization can use it.
diff --git a/docs/documentation/platform/pam/sessions/external-storage.mdx b/docs/documentation/platform/pam/sessions/external-storage.mdx
index 082de66583..1d7ab0a143 100644
--- a/docs/documentation/platform/pam/sessions/external-storage.mdx
+++ b/docs/documentation/platform/pam/sessions/external-storage.mdx
@@ -15,6 +15,8 @@ By default, [session recordings](/documentation/platform/pam/sessions/session-re
| Google Cloud Storage | `https://storage.googleapis.com` | An HMAC key for a service account with **Storage Object User** on the bucket |
| OCI Object Storage | `https://<namespace>.compat.objectstorage.<region>.oraclecloud.com` | A customer secret key for a user who can `inspect buckets` and `manage objects` |
+If you self-host Infisical, you can also store recordings on your own S3-compatible server, such as MinIO, after a server admin adds its hostname under [Allowed storage hostnames](/documentation/platform/admin-panel/server-admin#allowed-storage-hostnames).
+
## Prerequisites
Before configuring external storage, you need an [AWS Connection](/integrations/app-connections/aws) or an S3-Compatible Storage connection in your organization. This provides the credentials Infisical uses to write to your bucket.
diff --git a/frontend/src/helpers/appConnections.ts b/frontend/src/helpers/appConnections.ts
index 909d0e502a..fbeaa6f4ae 100644
--- a/frontend/src/helpers/appConnections.ts
+++ b/frontend/src/helpers/appConnections.ts
@@ -667,12 +667,25 @@ const S3_COMPATIBLE_PROVIDERS = [
}
];
-export const getS3CompatibleProviderName = (endpoint: string) => {
+const STORAGE_HOSTNAME_REGEX = /^[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:[0-9]{1,5})?$/;
+
+export const isStorageHostname = (hostname: string) => {
+ if (!STORAGE_HOSTNAME_REGEX.test(hostname)) return false;
+ try {
+ return new URL(`https://${hostname}`).host === hostname;
+ } catch {
+ return false;
+ }
+};
+
+export const getS3CompatibleProviderName = (
+ endpoint: string,
+ allowedStorageHostnames: string[] = []
+) => {
try {
const url = new URL(endpoint);
if (
url.protocol !== "https:" ||
- url.port ||
url.username ||
url.pathname !== "/" ||
url.search ||
@@ -680,6 +693,8 @@ export const getS3CompatibleProviderName = (endpoint: string) => {
) {
return null;
}
+ if (allowedStorageHostnames.includes(url.host)) return url.host;
+ if (url.port) return null;
return (
S3_COMPATIBLE_PROVIDERS.find(({ hostname }) => hostname.test(url.hostname))?.name ?? null
);
diff --git a/frontend/src/hooks/api/admin/types.ts b/frontend/src/hooks/api/admin/types.ts
index 11797a9517..d67367efd5 100644
--- a/frontend/src/hooks/api/admin/types.ts
+++ b/frontend/src/hooks/api/admin/types.ts
@@ -82,6 +82,7 @@ export type TServerConfig = {
passwordPolicy: TPasswordPolicy;
authConsentContent?: string;
pageFrameContent?: string;
+ allowedStorageHostnames?: string[] | null;
invalidatingCache: boolean;
envOverrides?: Record<string, string>;
isPublicSecretSharingDisabled?: boolean;
diff --git a/frontend/src/pages/admin/GeneralPage/components/GeneralPageForm.tsx b/frontend/src/pages/admin/GeneralPage/components/GeneralPageForm.tsx
index 6465a18b51..7f4f6c0b03 100644
--- a/frontend/src/pages/admin/GeneralPage/components/GeneralPageForm.tsx
+++ b/frontend/src/pages/admin/GeneralPage/components/GeneralPageForm.tsx
@@ -1,4 +1,4 @@
-import { type ReactNode, useEffect } from "react";
+import { type ReactNode, useEffect, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { AtSign } from "lucide-react";
@@ -27,10 +27,12 @@ import {
SelectItem,
SelectTrigger,
SelectValue,
+ TagsInput,
TextArea,
Toggle
} from "@app/components/v3";
import { useServerConfig } from "@app/context";
+import { isStorageHostname } from "@app/helpers/appConnections";
import { allowedEmailDomainsSchema } from "@app/helpers/email";
import { useGetOrganizations, useUpdateServerConfig } from "@app/hooks/api";
@@ -55,11 +57,17 @@ const signUpFormSchema = formSchema.pick({
const defaultOrganizationFormSchema = formSchema.pick({ defaultAuthOrgId: true });
const trustLdapEmailsFormSchema = formSchema.pick({ trustLdapEmails: true });
const noticesFormSchema = formSchema.pick({ authConsentContent: true, pageFrameContent: true });
+const storageHostnamesFormSchema = z.object({
+ allowedStorageHostnames: z.string().array().max(50, "Add at most 50 hostnames")
+});
+
+const NO_STORAGE_HOSTNAMES: string[] = [];
type TSignUpForm = z.infer<typeof signUpFormSchema>;
type TDefaultOrganizationForm = z.infer<typeof defaultOrganizationFormSchema>;
type TTrustLdapEmailsForm = z.infer<typeof trustLdapEmailsFormSchema>;
type TNoticesForm = z.infer<typeof noticesFormSchema>;
+type TStorageHostnamesForm = z.infer<typeof storageHostnamesFormSchema>;
type GeneralSettingsCardProps = {
title: string;
@@ -431,6 +439,80 @@ const NoticesSettingsCard = ({
);
};
+type StorageHostnamesSettingsCardProps = {
+ allowedStorageHostnames: string[];
+};
+
+const StorageHostnamesSettingsCard = ({
+ allowedStorageHostnames
+}: StorageHostnamesSettingsCardProps) => {
+ const [hostnameError, setHostnameError] = useState<string | null>(null);
+ const { mutateAsync: updateServerConfig } = useUpdateServerConfig();
+ const {
+ control,
+ handleSubmit,
+ reset,
+ formState: { isSubmitting, isDirty }
+ } = useForm<TStorageHostnamesForm>({
+ resolver: zodResolver(storageHostnamesFormSchema),
+ defaultValues: { allowedStorageHostnames }
+ });
+
+ useEffect(() => {
+ reset({ allowedStorageHostnames });
+ }, [allowedStorageHostnames, reset]);
+
+ const onFormSubmit = async (formData: TStorageHostnamesForm) => {
+ await updateServerConfig(formData);
+ reset(formData);
+ createNotification({
+ text: "Allowed storage hostnames updated.",
+ type: "success"
+ });
+ };
+
+ return (
+ <form onSubmit={handleSubmit(onFormSubmit)}>
+ <GeneralSettingsCard
+ title="Allowed Storage Hostnames"
+ description="Let S3-Compatible Storage connections and session playback use your own storage servers, such as MinIO."
+ isSubmitting={isSubmitting}
+ isDirty={isDirty}
+ >
+ <Controller
+ control={control}
+ name="allowedStorageHostnames"
+ render={({ field, fieldState: { error } }) => (
+ <Field className="max-w-lg" data-invalid={Boolean(hostnameError || error)}>
+ <FieldLabel htmlFor="allowed-storage-hostnames">Hostnames</FieldLabel>
+ <TagsInput
+ id="allowed-storage-hostnames"
+ value={field.value}
+ onValueChange={field.onChange}
+ validateTag={(tag, existing) => {
+ if (!isStorageHostname(tag)) {
+ return "Enter a lowercase hostname, with a port if it isn't 443, such as minio.example.com:9000";
+ }
+ return existing.includes(tag) ? `${tag} is already allowed` : null;
+ }}
+ onValidationError={setHostnameError}
+ isError={Boolean(hostnameError || error)}
+ aria-describedby="allowed-storage-hostnames-feedback"
+ placeholder="minio.example.com"
+ />
+ <FieldFeedback
+ id="allowed-storage-hostnames-feedback"
+ description="Include the port if it isn't 443."
+ error={hostnameError ?? error?.message}
+ />
+ </Field>
+ )}
+ />
+ </GeneralSettingsCard>
+ </form>
+ );
+};
+
export const GeneralPageForm = () => {
const { config } = useServerConfig();
@@ -446,6 +528,9 @@ export const GeneralPageForm = () => {
authConsentContent={config.authConsentContent ?? ""}
pageFrameContent={config.pageFrameContent ?? ""}
/>
+ <StorageHostnamesSettingsCard
+ allowedStorageHostnames={config.allowedStorageHostnames ?? NO_STORAGE_HOSTNAMES}
+ />
</div>
);
};
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 956d4de331..e6be69a866 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/S3CompatibleConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/S3CompatibleConnectionForm.tsx
@@ -1,3 +1,4 @@
+import { useMemo } from "react";
import { Controller, FormProvider, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { Info } from "lucide-react";
@@ -19,6 +20,7 @@ import {
TooltipContent,
TooltipTrigger
} from "@app/components/v3";
+import { useServerConfig } from "@app/context";
import {
APP_CONNECTION_MAP,
getAppConnectionMethodDetails,
@@ -43,28 +45,45 @@ const rootSchema = genericAppConnectionFieldsSchema.extend({
app: z.literal(AppConnection.S3Compatible)
});
-const formSchema = z.discriminatedUnion("method", [
- rootSchema.extend({
- method: z.literal(S3CompatibleConnectionMethod.AccessKey),
- credentials: z.object({
- endpoint: z
- .string()
- .trim()
- .min(1, "Endpoint required")
- .refine(
- (endpoint) => Boolean(getS3CompatibleProviderName(endpoint)),
- "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")
+const buildFormSchema = (allowedStorageHostnames: string[]) =>
+ z.discriminatedUnion("method", [
+ rootSchema.extend({
+ method: z.literal(S3CompatibleConnectionMethod.AccessKey),
+ credentials: z.object({
+ endpoint: z
+ .string()
+ .trim()
+ .min(1, "Endpoint required")
+ .refine(
+ (endpoint) => Boolean(getS3CompatibleProviderName(endpoint, allowedStorageHostnames)),
+ "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")
+ })
})
- })
-]);
+ ]);
-type FormData = z.infer<typeof formSchema>;
+type FormData = z.infer<ReturnType<typeof buildFormSchema>>;
export const S3CompatibleConnectionForm = ({ appConnection, onSubmit }: Props) => {
const isUpdate = Boolean(appConnection);
+ const { config } = useServerConfig();
+ const allowedStorageHostnames = useMemo(
+ () => config.allowedStorageHostnames ?? [],
+ [config.allowedStorageHostnames]
+ );
+ const formSchema = useMemo(
+ () => buildFormSchema(allowedStorageHostnames),
+ [allowedStorageHostnames]
+ );
+ const supportedEndpoints = new Intl.ListFormat("en").format([
+ "AWS S3",
+ "Cloudflare R2",
+ "Google Cloud Storage",
+ "OCI Object Storage",
+ ...allowedStorageHostnames
+ ]);
const form = useForm<FormData>({
resolver: zodResolver(formSchema),
@@ -136,8 +155,7 @@ export const S3CompatibleConnectionForm = ({ appConnection, onSubmit }: Props) =
isError={Boolean(error?.message)}
/>
<FieldDescription>
- The S3 API endpoint, without the bucket name. Supports AWS S3, Cloudflare R2, Google
- Cloud Storage and OCI Object Storage.
+ The S3 API endpoint, without the bucket name. Supports {supportedEndpoints}.
</FieldDescription>
<FieldError errors={[error]} />
</Field>