From 801802733057931f6b356d1fb7ed593ebf64612c Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 30 May 2026 01:02:34 -0600 Subject: [PATCH] feat: add self-hosted enterprise restrictions (remote-servers-only, enforce-sso) (#4511) * feat: add self-hosted enterprise restrictions (remote-servers-only, enforce-sso) - Add `remoteServersOnly` field to webServerSettings: prevents creating services on the local Dokploy VM, forcing all deployments to remote servers. Validated in all 8 service routers (application, compose, postgres, mysql, mongo, redis, mariadb, libsql). - Add `enforceSSO` field to webServerSettings: hides the email/password login form and shows only the SSO button on the login page. - Both settings are enterprise-only (enterpriseProcedure) and self-hosted-only (blocked at the API level when IS_CLOUD=true). - UI toggles added to the SSO settings page under a new "Self-hosted Restrictions" card (hidden in cloud). Login page reads enforceSSO from getServerSideProps to avoid client-side flash. - Migrations: 0167_fresh_goliath.sql, 0168_long_justice.sql * fix: add missing final newlines to migration files * refactor: improve code formatting for better readability in multiple components - Adjusted formatting in `add-application.tsx`, `add-compose.tsx`, and `add-database.tsx` to enhance readability by adding line breaks and consistent indentation. - Updated `toggle-enforce-sso.tsx` to simplify the Switch component's props. - Reformatted imports in `index.tsx` and `sso.tsx` for consistency. - Cleaned up conditional statements in various router files for improved clarity. * fix: add enforceSSO to test mock --- .../server/update-server-config.test.ts | 2 + .../dashboard/project/add-application.tsx | 17 +- .../dashboard/project/add-compose.tsx | 17 +- .../dashboard/project/add-database.tsx | 13 +- .../servers/actions/toggle-enforce-sso.tsx | 48 + .../actions/toggle-remote-servers-only.tsx | 53 + .../proprietary/sso/sign-in-with-sso.tsx | 27 +- apps/dokploy/drizzle/0167_fresh_goliath.sql | 1 + apps/dokploy/drizzle/0168_long_justice.sql | 1 + apps/dokploy/drizzle/meta/0167_snapshot.json | 8325 ++++++++++++++++ apps/dokploy/drizzle/meta/0168_snapshot.json | 8332 +++++++++++++++++ apps/dokploy/drizzle/meta/_journal.json | 16 +- apps/dokploy/pages/dashboard/settings/sso.tsx | 46 +- apps/dokploy/pages/index.tsx | 17 +- .../dokploy/server/api/routers/application.ts | 7 +- apps/dokploy/server/api/routers/compose.ts | 12 +- apps/dokploy/server/api/routers/libsql.ts | 7 +- apps/dokploy/server/api/routers/mariadb.ts | 7 +- apps/dokploy/server/api/routers/mongo.ts | 7 +- apps/dokploy/server/api/routers/mysql.ts | 7 +- apps/dokploy/server/api/routers/postgres.ts | 7 +- .../server/api/routers/proprietary/sso.ts | 8 + apps/dokploy/server/api/routers/redis.ts | 7 +- apps/dokploy/server/api/routers/settings.ts | 45 + .../src/db/schema/web-server-settings.ts | 6 + 25 files changed, 16995 insertions(+), 40 deletions(-) create mode 100644 apps/dokploy/components/dashboard/settings/servers/actions/toggle-enforce-sso.tsx create mode 100644 apps/dokploy/components/dashboard/settings/servers/actions/toggle-remote-servers-only.tsx create mode 100644 apps/dokploy/drizzle/0167_fresh_goliath.sql create mode 100644 apps/dokploy/drizzle/0168_long_justice.sql create mode 100644 apps/dokploy/drizzle/meta/0167_snapshot.json create mode 100644 apps/dokploy/drizzle/meta/0168_snapshot.json diff --git a/apps/dokploy/__test__/traefik/server/update-server-config.test.ts b/apps/dokploy/__test__/traefik/server/update-server-config.test.ts index e07f34ade..eda4dace5 100644 --- a/apps/dokploy/__test__/traefik/server/update-server-config.test.ts +++ b/apps/dokploy/__test__/traefik/server/update-server-config.test.ts @@ -65,6 +65,8 @@ const baseSettings: WebServerSettings = { cleanupCacheApplications: false, cleanupCacheOnCompose: false, cleanupCacheOnPreviews: false, + remoteServersOnly: false, + enforceSSO: false, createdAt: null, updatedAt: new Date(), }; diff --git a/apps/dokploy/components/dashboard/project/add-application.tsx b/apps/dokploy/components/dashboard/project/add-application.tsx index 16fac353d..0c50cc41f 100644 --- a/apps/dokploy/components/dashboard/project/add-application.tsx +++ b/apps/dokploy/components/dashboard/project/add-application.tsx @@ -71,6 +71,9 @@ interface Props { export const AddApplication = ({ environmentId, projectName }: Props) => { const utils = api.useUtils(); const { data: isCloud } = api.settings.isCloud.useQuery(); + const { data: webServerSettings } = + api.settings.getWebServerSettings.useQuery(); + const showLocalOption = !isCloud && !webServerSettings?.remoteServersOnly; const [visible, setVisible] = useState(false); const slug = slugify(projectName); const { data: servers } = api.server.withSSHKey.useQuery(); @@ -171,7 +174,8 @@ export const AddApplication = ({ environmentId, projectName }: Props) => { - Select a Server {!isCloud ? "(Optional)" : ""} + Select a Server{" "} + {showLocalOption ? "(Optional)" : ""} @@ -191,17 +195,19 @@ export const AddApplication = ({ environmentId, projectName }: Props) => { - {!isCloud && ( + {showLocalOption && ( Dokploy @@ -236,7 +242,8 @@ export const AddCompose = ({ environmentId, projectName }: Props) => { ))} - Servers ({servers?.length + (!isCloud ? 1 : 0)}) + Servers ( + {servers?.length + (showLocalOption ? 1 : 0)}) diff --git a/apps/dokploy/components/dashboard/project/add-database.tsx b/apps/dokploy/components/dashboard/project/add-database.tsx index 966fe0013..a76de2775 100644 --- a/apps/dokploy/components/dashboard/project/add-database.tsx +++ b/apps/dokploy/components/dashboard/project/add-database.tsx @@ -219,6 +219,9 @@ export const AddDatabase = ({ environmentId, projectName }: Props) => { const [visible, setVisible] = useState(false); const slug = slugify(projectName); const { data: isCloud } = api.settings.isCloud.useQuery(); + const { data: webServerSettings } = + api.settings.getWebServerSettings.useQuery(); + const showLocalOption = !isCloud && !webServerSettings?.remoteServersOnly; const { data: servers } = api.server.withSSHKey.useQuery(); const libsqlMutation = api.libsql.create.useMutation(); const mariadbMutation = api.mariadb.create.useMutation(); @@ -470,19 +473,20 @@ export const AddDatabase = ({ environmentId, projectName }: Props) => {