Skip to content

Commit 8018027

Browse files
authored
feat: add self-hosted enterprise restrictions (remote-servers-only, enforce-sso) (Dokploy#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
1 parent 6675aa6 commit 8018027

25 files changed

Lines changed: 16995 additions & 40 deletions

File tree

‎apps/dokploy/__test__/traefik/server/update-server-config.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ const baseSettings: WebServerSettings = {
6565
cleanupCacheApplications: false,
6666
cleanupCacheOnCompose: false,
6767
cleanupCacheOnPreviews: false,
68+
remoteServersOnly: false,
69+
enforceSSO: false,
6870
createdAt: null,
6971
updatedAt: new Date(),
7072
};

‎apps/dokploy/components/dashboard/project/add-application.tsx‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ interface Props {
7171
export const AddApplication = ({ environmentId, projectName }: Props) => {
7272
const utils = api.useUtils();
7373
const { data: isCloud } = api.settings.isCloud.useQuery();
74+
const { data: webServerSettings } =
75+
api.settings.getWebServerSettings.useQuery();
76+
const showLocalOption = !isCloud && !webServerSettings?.remoteServersOnly;
7477
const [visible, setVisible] = useState(false);
7578
const slug = slugify(projectName);
7679
const { data: servers } = api.server.withSSHKey.useQuery();
@@ -171,7 +174,8 @@ export const AddApplication = ({ environmentId, projectName }: Props) => {
171174
<Tooltip>
172175
<TooltipTrigger asChild>
173176
<FormLabel className="break-all w-fit flex flex-row gap-1 items-center">
174-
Select a Server {!isCloud ? "(Optional)" : ""}
177+
Select a Server{" "}
178+
{showLocalOption ? "(Optional)" : ""}
175179
<HelpCircle className="size-4 text-muted-foreground" />
176180
</FormLabel>
177181
</TooltipTrigger>
@@ -191,17 +195,19 @@ export const AddApplication = ({ environmentId, projectName }: Props) => {
191195
<Select
192196
onValueChange={field.onChange}
193197
defaultValue={
194-
field.value || (!isCloud ? "dokploy" : undefined)
198+
field.value || (showLocalOption ? "dokploy" : undefined)
195199
}
196200
>
197201
<SelectTrigger>
198202
<SelectValue
199-
placeholder={!isCloud ? "Dokploy" : "Select a Server"}
203+
placeholder={
204+
showLocalOption ? "Dokploy" : "Select a Server"
205+
}
200206
/>
201207
</SelectTrigger>
202208
<SelectContent>
203209
<SelectGroup>
204-
{!isCloud && (
210+
{showLocalOption && (
205211
<SelectItem value="dokploy">
206212
<span className="flex items-center gap-2 justify-between w-full">
207213
<span>Dokploy</span>
@@ -225,7 +231,8 @@ export const AddApplication = ({ environmentId, projectName }: Props) => {
225231
</SelectItem>
226232
))}
227233
<SelectLabel>
228-
Servers ({servers?.length + (!isCloud ? 1 : 0)})
234+
Servers (
235+
{servers?.length + (showLocalOption ? 1 : 0)})
229236
</SelectLabel>
230237
</SelectGroup>
231238
</SelectContent>

‎apps/dokploy/components/dashboard/project/add-compose.tsx‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export const AddCompose = ({ environmentId, projectName }: Props) => {
7474
const [visible, setVisible] = useState(false);
7575
const slug = slugify(projectName);
7676
const { data: isCloud } = api.settings.isCloud.useQuery();
77+
const { data: webServerSettings } =
78+
api.settings.getWebServerSettings.useQuery();
79+
const showLocalOption = !isCloud && !webServerSettings?.remoteServersOnly;
7780
const { data: servers } = api.server.withSSHKey.useQuery();
7881
const { mutateAsync, isPending, error, isError } =
7982
api.compose.create.useMutation();
@@ -182,7 +185,8 @@ export const AddCompose = ({ environmentId, projectName }: Props) => {
182185
<Tooltip>
183186
<TooltipTrigger asChild>
184187
<FormLabel className="break-all w-fit flex flex-row gap-1 items-center">
185-
Select a Server {!isCloud ? "(Optional)" : ""}
188+
Select a Server{" "}
189+
{showLocalOption ? "(Optional)" : ""}
186190
<HelpCircle className="size-4 text-muted-foreground" />
187191
</FormLabel>
188192
</TooltipTrigger>
@@ -202,17 +206,19 @@ export const AddCompose = ({ environmentId, projectName }: Props) => {
202206
<Select
203207
onValueChange={field.onChange}
204208
defaultValue={
205-
field.value || (!isCloud ? "dokploy" : undefined)
209+
field.value || (showLocalOption ? "dokploy" : undefined)
206210
}
207211
>
208212
<SelectTrigger>
209213
<SelectValue
210-
placeholder={!isCloud ? "Dokploy" : "Select a Server"}
214+
placeholder={
215+
showLocalOption ? "Dokploy" : "Select a Server"
216+
}
211217
/>
212218
</SelectTrigger>
213219
<SelectContent>
214220
<SelectGroup>
215-
{!isCloud && (
221+
{showLocalOption && (
216222
<SelectItem value="dokploy">
217223
<span className="flex items-center gap-2 justify-between w-full">
218224
<span>Dokploy</span>
@@ -236,7 +242,8 @@ export const AddCompose = ({ environmentId, projectName }: Props) => {
236242
</SelectItem>
237243
))}
238244
<SelectLabel>
239-
Servers ({servers?.length + (!isCloud ? 1 : 0)})
245+
Servers (
246+
{servers?.length + (showLocalOption ? 1 : 0)})
240247
</SelectLabel>
241248
</SelectGroup>
242249
</SelectContent>

‎apps/dokploy/components/dashboard/project/add-database.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ export const AddDatabase = ({ environmentId, projectName }: Props) => {
219219
const [visible, setVisible] = useState(false);
220220
const slug = slugify(projectName);
221221
const { data: isCloud } = api.settings.isCloud.useQuery();
222+
const { data: webServerSettings } =
223+
api.settings.getWebServerSettings.useQuery();
224+
const showLocalOption = !isCloud && !webServerSettings?.remoteServersOnly;
222225
const { data: servers } = api.server.withSSHKey.useQuery();
223226
const libsqlMutation = api.libsql.create.useMutation();
224227
const mariadbMutation = api.mariadb.create.useMutation();
@@ -470,19 +473,20 @@ export const AddDatabase = ({ environmentId, projectName }: Props) => {
470473
<Select
471474
onValueChange={field.onChange}
472475
defaultValue={
473-
field.value || (!isCloud ? "dokploy" : undefined)
476+
field.value ||
477+
(showLocalOption ? "dokploy" : undefined)
474478
}
475479
>
476480
<SelectTrigger>
477481
<SelectValue
478482
placeholder={
479-
!isCloud ? "Dokploy" : "Select a Server"
483+
showLocalOption ? "Dokploy" : "Select a Server"
480484
}
481485
/>
482486
</SelectTrigger>
483487
<SelectContent>
484488
<SelectGroup>
485-
{!isCloud && (
489+
{showLocalOption && (
486490
<SelectItem value="dokploy">
487491
<span className="flex items-center gap-2 justify-between w-full">
488492
<span>Dokploy</span>
@@ -501,7 +505,8 @@ export const AddDatabase = ({ environmentId, projectName }: Props) => {
501505
</SelectItem>
502506
))}
503507
<SelectLabel>
504-
Servers ({servers?.length + (!isCloud ? 1 : 0)})
508+
Servers (
509+
{servers?.length + (showLocalOption ? 1 : 0)})
505510
</SelectLabel>
506511
</SelectGroup>
507512
</SelectContent>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { HelpCircle } from "lucide-react";
2+
import { toast } from "sonner";
3+
import { Label } from "@/components/ui/label";
4+
import { Switch } from "@/components/ui/switch";
5+
import {
6+
Tooltip,
7+
TooltipContent,
8+
TooltipProvider,
9+
TooltipTrigger,
10+
} from "@/components/ui/tooltip";
11+
import { api } from "@/utils/api";
12+
13+
export const ToggleEnforceSSO = () => {
14+
const { data, refetch } = api.settings.getWebServerSettings.useQuery();
15+
const { mutateAsync } = api.settings.updateEnforceSSO.useMutation();
16+
17+
const handleToggle = async (checked: boolean) => {
18+
try {
19+
await mutateAsync({ enforceSSO: checked });
20+
await refetch();
21+
toast.success("Enforce SSO updated");
22+
} catch {
23+
toast.error("Error updating Enforce SSO");
24+
}
25+
};
26+
27+
return (
28+
<div className="flex items-center gap-4">
29+
<Switch checked={!!data?.enforceSSO} onCheckedChange={handleToggle} />
30+
<TooltipProvider delayDuration={0}>
31+
<Tooltip>
32+
<TooltipTrigger asChild>
33+
<Label className="text-primary flex items-center gap-1.5 cursor-pointer">
34+
Enforce SSO
35+
<HelpCircle className="size-4 text-muted-foreground" />
36+
</Label>
37+
</TooltipTrigger>
38+
<TooltipContent side="top" className="max-w-sm">
39+
<p>
40+
When enabled, the email/password login form is hidden and users
41+
must sign in exclusively through SSO.
42+
</p>
43+
</TooltipContent>
44+
</Tooltip>
45+
</TooltipProvider>
46+
</div>
47+
);
48+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { HelpCircle } from "lucide-react";
2+
import { toast } from "sonner";
3+
import { Label } from "@/components/ui/label";
4+
import { Switch } from "@/components/ui/switch";
5+
import {
6+
Tooltip,
7+
TooltipContent,
8+
TooltipProvider,
9+
TooltipTrigger,
10+
} from "@/components/ui/tooltip";
11+
import { api } from "@/utils/api";
12+
13+
export const ToggleRemoteServersOnly = () => {
14+
const { data, refetch } = api.settings.getWebServerSettings.useQuery();
15+
16+
const { mutateAsync } = api.settings.updateRemoteServersOnly.useMutation();
17+
18+
const handleToggle = async (checked: boolean) => {
19+
try {
20+
await mutateAsync({ remoteServersOnly: checked });
21+
await refetch();
22+
toast.success("Remote Servers Only updated");
23+
} catch {
24+
toast.error("Error updating Remote Servers Only");
25+
}
26+
};
27+
28+
return (
29+
<div className="flex items-center gap-4">
30+
<Switch
31+
checked={!!data?.remoteServersOnly}
32+
onCheckedChange={handleToggle}
33+
/>
34+
<TooltipProvider delayDuration={0}>
35+
<Tooltip>
36+
<TooltipTrigger asChild>
37+
<Label className="text-primary flex items-center gap-1.5 cursor-pointer">
38+
Remote Servers Only
39+
<HelpCircle className="size-4 text-muted-foreground" />
40+
</Label>
41+
</TooltipTrigger>
42+
<TooltipContent side="top" className="max-w-sm">
43+
<p>
44+
When enabled, all services (applications, databases, compose) must
45+
be deployed to a remote server. Deploying directly to the Dokploy
46+
host VM is not allowed.
47+
</p>
48+
</TooltipContent>
49+
</Tooltip>
50+
</TooltipProvider>
51+
</div>
52+
);
53+
};

‎apps/dokploy/components/proprietary/sso/sign-in-with-sso.tsx‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ type SSOEmailForm = z.infer<typeof ssoEmailSchema>;
2929

3030
interface SignInWithSSOProps {
3131
/** Content shown when SSO is collapsed (e.g. email/password form) */
32-
children: React.ReactNode;
32+
children?: React.ReactNode;
33+
/** When true, SSO is the only option — no fallback to email/password */
34+
enforce?: boolean;
3335
}
3436

35-
export function SignInWithSSO({ children }: SignInWithSSOProps) {
37+
export function SignInWithSSO({
38+
children,
39+
enforce = false,
40+
}: SignInWithSSOProps) {
3641
const [expanded, setExpanded] = useState(false);
3742

3843
const form = useForm<SSOEmailForm>({
@@ -72,7 +77,7 @@ export function SignInWithSSO({ children }: SignInWithSSOProps) {
7277
<LogIn className="mr-2 size-4" />
7378
Sign in with SSO
7479
</Button>
75-
{children}
80+
{!enforce && children}
7681
</div>
7782
);
7883
}
@@ -113,13 +118,15 @@ export function SignInWithSSO({ children }: SignInWithSSOProps) {
113118
</FormItem>
114119
)}
115120
/>
116-
<button
117-
type="button"
118-
onClick={() => setExpanded(false)}
119-
className="text-xs text-muted-foreground hover:underline"
120-
>
121-
Use email and password instead
122-
</button>
121+
{!enforce && (
122+
<button
123+
type="button"
124+
onClick={() => setExpanded(false)}
125+
className="text-xs text-muted-foreground hover:underline"
126+
>
127+
Use email and password instead
128+
</button>
129+
)}
123130
</form>
124131
</Form>
125132
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "webServerSettings" ADD COLUMN "remoteServersOnly" boolean DEFAULT false NOT NULL;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "webServerSettings" ADD COLUMN "enforceSSO" boolean DEFAULT false NOT NULL;

0 commit comments

Comments
 (0)