Skip to content

Commit ff421d8

Browse files
committed
improvement(auth): replace the three signup toggles with REGISTRATION_MODE
1 parent 6ffd995 commit ff421d8

45 files changed

Lines changed: 788 additions & 117 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/docs/content/docs/platform/self-hosting/authentication.mdx‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,31 @@ Google and Microsoft share their client credentials with integrations. Register
6161

6262
## Control registration and sign-in [#controlling-who-can-sign-up]
6363

64+
`REGISTRATION_MODE` decides who can create an account and whether email/password and email OTP work at all:
65+
66+
| `REGISTRATION_MODE` | New accounts | Email/password and email OTP sign-in |
67+
| --- | --- | --- |
68+
| `open` (default) | Any enabled method | On |
69+
| `no-email-signup` | Social login only | On |
70+
| `closed` | None | On |
71+
| `no-email` | Social login only | **Off, including for existing accounts** |
72+
| `closed-no-email` | None | **Off, including for existing accounts** |
73+
74+
In the `closed` modes, existing accounts can still sign in, including to accept workspace invitations. No mode affects accounts created by SSO on first sign-in or by SCIM provisioning. An unrecognized value closes self-serve registration (sign-in keeps working) and logs an error until you correct it.
75+
76+
`REGISTRATION_MODE` replaces three variables. They still work and log a deprecation warning; set alongside `REGISTRATION_MODE`, the more restrictive setting wins:
77+
78+
| Deprecated variable | Equivalent |
79+
| --- | --- |
80+
| `DISABLE_REGISTRATION=true` | `closed` |
81+
| `DISABLE_EMAIL_SIGNUP=true` | `no-email-signup` |
82+
| `EMAIL_PASSWORD_SIGNUP_ENABLED=false` (or `NEXT_PUBLIC_EMAIL_PASSWORD_SIGNUP_ENABLED=false`) | `no-email` |
83+
| `DISABLE_REGISTRATION=true` with `EMAIL_PASSWORD_SIGNUP_ENABLED=false` | `closed-no-email` |
84+
85+
The other sign-in controls:
86+
6487
| Variable | Effect |
6588
| --- | --- |
66-
| `DISABLE_REGISTRATION=true` | Blocks new email/password, email OTP, and social accounts. Existing accounts can sign in, including to accept workspace invitations. SSO registration is unaffected. |
67-
| `DISABLE_EMAIL_SIGNUP=true` | Blocks new email/password and email OTP registrations. Existing accounts can still sign in through those methods. |
68-
| `EMAIL_PASSWORD_SIGNUP_ENABLED=false` | Disables email/password and email OTP sign-in and signup, including for existing accounts. |
6989
| `ALLOWED_LOGIN_DOMAINS` | Comma-separated email domain allowlist, such as `acme.com,acme.co.uk`. Applies to email/password and email OTP sign-in as well as email signup. |
7090
| `ALLOWED_LOGIN_EMAILS` | Comma-separated address allowlist. An address or its domain may satisfy the allowlists. |
7191
| `BLOCKED_SIGNUP_DOMAINS` | Comma-separated blocked domains. Blocks signup, sign-in, and executions for addresses in those domains, including subdomains. |
@@ -74,14 +94,14 @@ Google and Microsoft share their client credentials with integrations. Register
7494
| `BLOCKED_EMAIL_MX_HOSTS` | MX-host substrings to reject when MX validation is enabled. |
7595

7696
<Callout type="warn">
77-
Email allowlists do not filter first-time Google, GitHub, or Microsoft sign-in. To restrict social access, disable login providers you have not vetted or restrict membership through your identity provider and use SSO. MX validation applies only to email/password signup, not sign-in or email OTP. Registration-disabled and blocked-domain/address controls also cover social accounts.
97+
Email allowlists do not filter first-time Google, GitHub, or Microsoft sign-in. To restrict social access, disable login providers you have not vetted or restrict membership through your identity provider and use SSO. MX validation applies only to email/password signup, not sign-in or email OTP. The `closed` registration modes and the blocked-domain/address controls also cover social accounts.
7898
</Callout>
7999

80100
For example, an installation using SSO while allowing existing company email accounts to sign in can set:
81101

82102
```bash
83103
ALLOWED_LOGIN_DOMAINS=acme.com
84-
DISABLE_EMAIL_SIGNUP=true
104+
REGISTRATION_MODE=no-email-signup
85105
SSO_ENABLED=true
86106
```
87107

‎apps/docs/content/docs/platform/self-hosting/environment-variables.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ See [AWS credentials](/integrations/aws-credentials#self-hosted-deployments) for
174174

175175
## Access control
176176

177-
Who may sign up and sign in — the allowlists, blocklists, `DISABLE_REGISTRATION`, `DISABLE_INVITATIONS`, `DISABLE_PUBLIC_API`, and `DISABLE_AUTH` — is documented in [Authentication](/platform/self-hosting/authentication).
177+
Who may sign up and sign in — the allowlists, blocklists, `REGISTRATION_MODE`, `DISABLE_INVITATIONS`, `DISABLE_PUBLIC_API`, and `DISABLE_AUTH` — is documented in [Authentication](/platform/self-hosting/authentication).
178178

179179
## Code execution
180180

‎apps/docs/content/docs/platform/self-hosting/security.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Review access, secrets, networking, and code execution before exposing a self-ho
1515
- TLS terminating at the ingress; HTTP redirected or disabled
1616
- `NEXT_PUBLIC_APP_URL` and `BETTER_AUTH_URL` set to the real public origin
1717
- `AUTH_TRUSTED_PROXIES` set if behind a load balancer
18-
- Signup restricted (`DISABLE_REGISTRATION` or `ALLOWED_LOGIN_DOMAINS`)
18+
- Signup restricted (`REGISTRATION_MODE=closed` or `ALLOWED_LOGIN_DOMAINS`)
1919
- `DISABLE_AUTH` **not** set
2020
- NetworkPolicy enabled and `ingressFrom` scoped to the ingress controller
2121
- Namespace labelled `pod-security.kubernetes.io/enforce=restricted`, with the GPU device-plugin exception reviewed if GPU Ollama is enabled

‎apps/docs/scripts/fixtures/content-baseline.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172154,7 +172154,7 @@
172154172154
{
172155172155
"lang": "bash",
172156172156
"meta": null,
172157-
"sha256": "dd9ca81a343c3f8aee7c8023f036f8da04077ebdf67e4352c4c35c9702bea09a",
172157+
"sha256": "341d45806fe1148043272665cf561585b5a3f452082214381a9894da046eca8c",
172158172158
"bytes": 102,
172159172159
"line": 78
172160172160
},

‎apps/sim/.env.example‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ BETTER_AUTH_URL=http://localhost:3000
1212
# Authentication Bypass (Optional - for self-hosted deployments behind private networks)
1313
# DISABLE_AUTH=true # Uncomment to bypass authentication entirely. Creates an anonymous session for all requests.
1414

15+
# Registration (Optional)
16+
# REGISTRATION_MODE=open # open (default) | no-email-signup | closed | no-email | closed-no-email. `closed*` stops self-serve signup by any method; `no-email*` also turns off email/password and OTP sign-in for existing accounts. Replaces DISABLE_REGISTRATION, DISABLE_EMAIL_SIGNUP, and EMAIL_PASSWORD_SIGNUP_ENABLED.
17+
1518
# Private-network egress allowlist (Optional - self-hosted only; ignored on Sim Cloud)
1619
# EGRESS_ALLOWED_HOSTS=host.docker.internal,*.svc.cluster.local # Uncomment to let outbound requests reach these hosts on a private network. Widens the SSRF boundary; only use on a trusted private network.
1720
# EGRESS_ALLOWED_IP_RANGES=10.0.0.0/8 # Same, by CIDR. Cloud metadata endpoints stay blocked regardless, and neither setting is honored for URLs harvested from content or for a proxy.

‎apps/sim/app/(auth)/layout.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Metadata } from 'next'
2-
import { isRegistrationDisabled } from '@/lib/core/config/env-flags'
2+
import { isSelfServeRegistrationClosed } from '@/lib/core/config/env-flags'
33
import { AttributionCapture } from '@/app/_shell/consent/attribution-capture'
44
import { AuthShell } from '@/app/(auth)/components'
55

@@ -9,7 +9,7 @@ export const metadata: Metadata = {
99

1010
export default function AuthLayout({ children }: { children: React.ReactNode }) {
1111
return (
12-
<AuthShell registrationDisabled={isRegistrationDisabled}>
12+
<AuthShell registrationDisabled={isSelfServeRegistrationClosed}>
1313
{children}
1414
<AttributionCapture />
1515
</AuthShell>

‎apps/sim/app/(auth)/login/login-form.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { useRouter, useSearchParams } from 'next/navigation'
99
import { requestJson } from '@/lib/api/client/request'
1010
import { forgetPasswordContract } from '@/lib/api/contracts'
1111
import { client } from '@/lib/auth/client'
12-
import { getEnv, isFalsy } from '@/lib/core/config/env'
1312
import { isSsoEnabled } from '@/lib/core/config/env-flags'
1413
import { validateCallbackUrl } from '@/lib/core/security/input-validation'
1514
import { getBaseUrl } from '@/lib/core/utils/urls'
@@ -79,10 +78,13 @@ export default function LoginPage({
7978
githubAvailable,
8079
googleAvailable,
8180
microsoftAvailable,
81+
emailPasswordEnabled,
8282
}: {
8383
githubAvailable: boolean
8484
googleAvailable: boolean
8585
microsoftAvailable: boolean
86+
/** Whether `REGISTRATION_MODE` leaves email/password and email OTP sign-in on. */
87+
emailPasswordEnabled: boolean
8688
}) {
8789
const router = useRouter()
8890
const searchParams = useSearchParams()
@@ -346,7 +348,7 @@ export default function LoginPage({
346348
}
347349

348350
const ssoEnabled = isSsoEnabled
349-
const emailEnabled = !isFalsy(getEnv('NEXT_PUBLIC_EMAIL_PASSWORD_SIGNUP_ENABLED'))
351+
const emailEnabled = emailPasswordEnabled
350352
const hasSocial = githubAvailable || googleAvailable || microsoftAvailable
351353
const hasOnlySSO = ssoEnabled && !emailEnabled && !hasSocial
352354
const showTopSSO = hasOnlySSO

‎apps/sim/app/(auth)/login/page.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Suspense } from 'react'
22
import type { Metadata } from 'next'
3+
import { isEmailPasswordAuthEnabled } from '@/lib/core/config/env-flags'
34
import { getOAuthProviderStatus } from '@/app/(auth)/components/oauth-provider-checker'
45
import LoginLoading from '@/app/(auth)/login/loading'
56
import LoginForm from '@/app/(auth)/login/login-form'
@@ -19,6 +20,7 @@ export default async function LoginPage() {
1920
githubAvailable={githubAvailable}
2021
googleAvailable={googleAvailable}
2122
microsoftAvailable={microsoftAvailable}
23+
emailPasswordEnabled={isEmailPasswordAuthEnabled}
2224
/>
2325
</Suspense>
2426
)

‎apps/sim/app/(auth)/oauth/sign-in/route.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function redirectParts(response: Response): { destination: URL; callback: URL }
2121

2222
describe('OAuth login bridge', () => {
2323
beforeEach(() => {
24-
setEnvFlags({ isAuthDisabled: false, isRegistrationDisabled: false })
24+
setEnvFlags({ isAuthDisabled: false, isSelfServeRegistrationClosed: false })
2525
setEnv({ NEXT_PUBLIC_APP_URL: 'https://sim.test' })
2626
})
2727

‎apps/sim/app/(auth)/oauth/sign-in/route.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type NextRequest, NextResponse } from 'next/server'
2-
import { isAuthDisabled, isRegistrationDisabled } from '@/lib/core/config/env-flags'
2+
import { isAuthDisabled, isSelfServeRegistrationClosed } from '@/lib/core/config/env-flags'
33
import { getBaseUrl } from '@/lib/core/utils/urls'
44
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
55
import { buildAuthCrossLink } from '@/app/(auth)/auth-redirect'
@@ -33,9 +33,9 @@ function consumeInteractivePrompt(params: URLSearchParams): boolean {
3333
* client hooks to keep in step.
3434
*
3535
* Signup rather than login by default, for the same reason the CLI handoff
36-
* chooses it: this is reached from a terminal, often on a fresh install. Under
37-
* DISABLE_REGISTRATION nobody can create an account, so login is the only hop
38-
* that can succeed.
36+
* chooses it: this is reached from a terminal, often on a fresh install. When
37+
* `REGISTRATION_MODE` closes self-serve registration nobody can create an
38+
* account, so login is the only hop that can succeed.
3939
*/
4040
export const GET = withRouteHandler(async (request: NextRequest) => {
4141
/** Avoid sending a newly signed-in user to a disabled provider's JSON 404. */
@@ -49,7 +49,7 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
4949

5050
const authorizeUrl = `/api/auth/oauth2/authorize?${params.toString()}`
5151
const destination = buildAuthCrossLink(
52-
isRegistrationDisabled || requiresLogin ? '/login' : '/signup',
52+
isSelfServeRegistrationClosed || requiresLogin ? '/login' : '/signup',
5353
{
5454
callbackUrl: authorizeUrl,
5555
isInviteFlow: false,

0 commit comments

Comments
 (0)