Skip to content

Commit d4bfeb6

Browse files
wip
1 parent 1387c46 commit d4bfeb6

41 files changed

Lines changed: 812 additions & 799 deletions

Some content is hidden

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

.env.development

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ CTAGS_COMMAND=ctags
1313
# @see: https://authjs.dev/getting-started/deployment#auth_secret
1414
AUTH_SECRET="00000000000000000000000000000000000000000000"
1515
AUTH_URL="http://localhost:3000"
16-
# AUTH_CREDENTIALS_LOGIN_ENABLED=true
1716

1817
DATA_CACHE_DIR=${PWD}/.sourcebot # Path to the sourcebot cache dir (ex. ~/sourcebot/.sourcebot)
1918
SOURCEBOT_PUBLIC_KEY_PATH=${PWD}/public.pem

docs/docs/configuration/auth/providers.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ If there's an authentication provider you'd like us to support, please [reach ou
1111

1212
### Email / Password
1313
---
14-
Email / password authentication is enabled by default. It can be **disabled** by setting `AUTH_CREDENTIALS_LOGIN_ENABLED` to `false`.
14+
Email / password authentication is enabled by default. You can toggle it from **Settings → Access** using the **Email login** setting.
15+
16+
The `AUTH_CREDENTIALS_LOGIN_ENABLED` environment variable is deprecated. It still works, but when it is set it overrides the UI setting and locks the toggle. Leave it unset to manage email login from the UI.
17+
18+
Email login can't be disabled when no other login method is configured (no SSO identity provider and no email-code login), since that would leave no way to sign in.
1519

1620
### Email codes
1721
---

docs/docs/configuration/config-file.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ The following are settings that can be provided in your config file to modify So
4949
| `maxRepoGarbageCollectionJobConcurrency` | number | 8 | 1 | Concurrent repo‑garbage‑collection jobs. |
5050
| `repoGarbageCollectionGracePeriodMs` | number | 10 seconds | 1 | Grace period to avoid deleting shards while loading. |
5151
| `repoIndexTimeoutMs` | number | 2 hours | 1 | Timeout for a single repo‑indexing run. |
52-
| `enablePublicAccess` **(deprecated)** | boolean | false || Use the `FORCE_ENABLE_ANONYMOUS_ACCESS` environment variable instead. |
5352
| `repoDrivenPermissionSyncIntervalMs` | number | 24 hours | 1 | Interval at which the repo permission syncer should run. |
5453
| `userDrivenPermissionSyncIntervalMs` | number | 24 hours | 1 | Interval at which the user permission syncer should run. |
5554
| `experiment_repoDrivenPermissionSyncIntervalMs` **(deprecated)** | number | 24 hours | 1 | Use `repoDrivenPermissionSyncIntervalMs` instead. |

docs/docs/configuration/environment-variables.mdx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ The following environment variables allow you to configure your Sourcebot deploy
1010

1111
| Variable | Default | Description |
1212
| :------- | :------ | :---------- |
13-
| `AUTH_CREDENTIALS_LOGIN_ENABLED` | `true` | <p>Enables/disables authentication with basic credentials. Username and passwords are stored encrypted at rest within the postgres database. Checkout the [auth docs](/docs/configuration/auth/authentication) for more info</p> |
1413
| `AUTH_EMAIL_CODE_LOGIN_ENABLED` | `false` | <p>Enables/disables authentication with a login code that's sent to a users email. `SMTP_CONNECTION_URL` and `EMAIL_FROM_ADDRESS` must also be set. Checkout the [auth docs](/docs/configuration/auth/authentication) for more info </p> |
1514
| `AUTH_SECRET` **(required)** | - | <p>Used to validate login session cookies. Genearte one with `openssl rand -base64 33`.</p> |
1615
| `AUTH_SESSION_MAX_AGE_SECONDS` | `2592000` (30 days) | <p>Relative time from now in seconds when to expire the session.</p> |
@@ -24,7 +23,6 @@ The following environment variables allow you to configure your Sourcebot deploy
2423
| `DATA_DIR` | `/data` | <p>The directory within the container to store all persistent data. Typically, this directory will be volume mapped such that data is persisted across container restarts (e.g., `docker run -v $(pwd):/data`)</p> |
2524
| `DATABASE_URL` **(required)** | - | <p>Connection string of your Postgres database, e.g. `postgresql://user:password@host:5432/sourcebot`.</p><p>If you'd like to use a non-default schema, you can provide it as a parameter in the database url.</p><p>You can also use `DATABASE_HOST`, `DATABASE_USERNAME`, `DATABASE_PASSWORD`, `DATABASE_NAME`, and `DATABASE_ARGS` to construct the database url.</p> |
2625
| `EMAIL_FROM_ADDRESS` | `-` | <p>The email address that transactional emails will be sent from. See [this doc](/docs/configuration/transactional-emails) for more info.</p> |
27-
| `FORCE_ENABLE_ANONYMOUS_ACCESS` | `false` | <p>When enabled, [anonymous access](/docs/configuration/auth/access-settings#anonymous-access) to the organization will always be enabled</p>
2826
| `REQUIRE_APPROVAL_NEW_MEMBERS` | - | <p>When set, controls whether new users require approval before accessing your deployment. If not set, the setting can be configured via the UI. See [member approval](/docs/configuration/auth/access-settings#member-approval) for more info.</p>
2927
| `REDIS_URL` **(required)** | - | <p>Connection string of your Redis instance, e.g. `redis://host:6379`.</p><p>To enable TLS, see [this doc](/docs/deployment/infrastructure/redis#tls).</p> |
3028
| `REDIS_REMOVE_ON_COMPLETE` | `0` | <p>Controls how many completed jobs are allowed to remain in Redis queues</p> |
@@ -54,10 +52,8 @@ The following environment variables allow you to configure your Sourcebot deploy
5452
| `AUTH_EE_GCP_IAP_AUDIENCE` | - | <p>The GCP IAP audience to use when verifying JWT tokens. Must be set to enable GCP IAP JIT provisioning</p> |
5553
| `PERMISSION_SYNC_ENABLED` | `false` | <p>Enables [permission syncing](/docs/features/permission-syncing).</p> |
5654
| `PERMISSION_SYNC_REPO_DRIVEN_ENABLED` | `true` | <p>Enables/disables [repo-driven permission syncing](/docs/features/permission-syncing#how-it-works). Only applies when `PERMISSION_SYNC_ENABLED` is `true`.</p> |
57-
| `EXPERIMENT_EE_PERMISSION_SYNC_ENABLED` **(deprecated)** | `false` | <p>Deprecated. Use `PERMISSION_SYNC_ENABLED` instead.</p> |
5855
| `AUTH_EE_ALLOW_EMAIL_ACCOUNT_LINKING` | `true` | <p>When enabled, different SSO accounts with the same email address will automatically be linked.</p> |
5956
| `DISABLE_API_KEY_CREATION_FOR_NON_OWNER_USERS` | `false` | <p>When enabled, only organization owners can create API keys. Non-owner members will receive a `403` error if they attempt to create one.</p> |
60-
| `EXPERIMENT_DISABLE_API_KEY_CREATION_FOR_NON_ADMIN_USERS` **(deprecated)** | `false` | <p>Deprecated. Use `DISABLE_API_KEY_CREATION_FOR_NON_OWNER_USERS` instead.</p> |
6157
| `DISABLE_API_KEY_USAGE_FOR_NON_OWNER_USERS` | `false` | <p>When enabled, only organization owners can create or use API keys. Non-owner members will receive a `403` error if they attempt to create or authenticate with an API key. If you only want to restrict creation (not usage), use `DISABLE_API_KEY_CREATION_FOR_NON_OWNER_USERS` instead.</p> |
6258

6359

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- AlterTable
2+
ALTER TABLE "Org" ADD COLUMN "isAnonymousAccessEnabled" BOOLEAN NOT NULL DEFAULT false,
3+
ADD COLUMN "isCredentialsLoginEnabled" BOOLEAN NOT NULL DEFAULT true,
4+
ADD COLUMN "isEmailCodeLoginEnabled" BOOLEAN NOT NULL DEFAULT false;
5+
6+
-- Backfill the new dedicated column from the legacy `metadata.anonymousAccessEnabled`
7+
-- value (see orgMetadataSchema in packages/web/src/types.ts) so existing deployments
8+
-- that had anonymous access enabled keep it after upgrading.
9+
UPDATE "Org"
10+
SET "isAnonymousAccessEnabled" = true
11+
WHERE "metadata"->>'anonymousAccessEnabled' = 'true';

packages/db/prisma/schema.prisma

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,32 @@ model Org {
274274
apiKeys ApiKey[]
275275
isOnboarded Boolean @default(false)
276276
imageUrl String?
277-
metadata Json? // For schema see orgMetadataSchema in packages/web/src/types.ts
277+
metadata Json?
278278
279+
/// @deprecated This property can be controlled by the environment
280+
/// variable `REQUIRE_APPROVAL_NEW_MEMBERS`. To ensure that we use
281+
/// the correct setting, use the helper function `isMemberApprovalRequired`
282+
/// in shared/src/utils.ts
279283
memberApprovalRequired Boolean @default(true)
280284
285+
/// @deprecated This property can be controlled by the environment
286+
/// variable `AUTH_CREDENTIALS_LOGIN_ENABLED`. To ensure that we use
287+
/// the correct setting, use the helper function `isCredentialsLoginEnabled`
288+
/// in shared/src/utils.ts
289+
isCredentialsLoginEnabled Boolean @default(true)
290+
291+
/// @deprecated This property can be controlled by the environment
292+
/// variable `AUTH_EMAIL_CODE_LOGIN_ENABLED`. To ensure that we use
293+
/// the correct setting, use the helper function `isEmailCodeLoginEnabled`
294+
/// in shared/src/utils.ts
295+
isEmailCodeLoginEnabled Boolean @default(false)
296+
297+
/// @deprecated This property can be overriden by the environment
298+
/// variable `FORCE_ENABLE_ANONYMOUS_ACCESS`, as well as the org's
299+
/// available entitlements. Use the helper function `isAnonymousAccessEnabled`
300+
/// in web/src/lib/entitlements.ts
301+
isAnonymousAccessEnabled Boolean @default(false)
302+
281303
/// List of pending invites to this organization
282304
invites Invite[]
283305

packages/shared/src/env.server.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,8 @@ const options = {
173173
ZOEKT_WEBSERVER_URL: z.string().url().default("http://localhost:6070"),
174174

175175
// Auth
176-
FORCE_ENABLE_ANONYMOUS_ACCESS: booleanSchema.default('false'),
177-
REQUIRE_APPROVAL_NEW_MEMBERS: booleanSchema.optional(),
178176
AUTH_SECRET: z.string(),
179177
AUTH_URL: z.string().url(),
180-
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.default('true'),
181-
AUTH_EMAIL_CODE_LOGIN_ENABLED: booleanSchema.default('false'),
182178

183179
/**
184180
* Relative time from now in seconds when to expire the session.
@@ -425,6 +421,39 @@ const options = {
425421
* ignored.
426422
*/
427423
SOURCEBOT_TELEMETRY_PII_COLLECTION_ENABLED: booleanSchema.default('false'),
424+
425+
//////////// Deprecated ////////////
426+
/**
427+
* @deprecated Configure this setting via the "Require approval
428+
* for new members" toggle in Settings → Security intsead.
429+
*/
430+
REQUIRE_APPROVAL_NEW_MEMBERS: booleanSchema.optional(),
431+
432+
/**
433+
* @deprecated Configure email + password login via the "Email & password login"
434+
* toggle in Settings → Security instead. When set, this env var overrides the UI
435+
* setting and locks the toggle; when unset, the DB-backed
436+
* `Org.isCredentialsLoginEnabled` setting is used.
437+
*/
438+
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.optional(),
439+
440+
/**
441+
* @deprecated Configure email code login via the UI in Settings → Security
442+
* instead. When set, this env var overrides the UI setting and locks the toggle;
443+
* when unset, the DB-backed `Org.isEmailCodeLoginEnabled` setting is used. Left
444+
* optional (rather than defaulting to 'false') so we can detect whether it was
445+
* explicitly set.
446+
*/
447+
AUTH_EMAIL_CODE_LOGIN_ENABLED: booleanSchema.optional(),
448+
449+
/**
450+
* @deprecated Configure anonymous access via the UI in Settings → Security
451+
* instead. When set, this env var overrides the UI setting and locks the toggle;
452+
* when unset, the DB-backed `Org.isAnonymousAccessEnabled` setting is used. Left
453+
* optional (rather than defaulting to 'false') so we can detect whether it was
454+
* explicitly set.
455+
*/
456+
FORCE_ENABLE_ANONYMOUS_ACCESS: booleanSchema.optional(),
428457
},
429458
runtimeEnv,
430459
emptyStringAsUndefined: true,

packages/shared/src/index.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export {
3131
getConfigSettings,
3232
getRepoPath,
3333
getRepoIdFromPath,
34+
isCredentialsLoginEnabled,
35+
isEmailCodeLoginEnabled,
36+
isMemberApprovalRequired,
3437
} from "./utils.js";
3538
export * from "./constants.js";
3639
export {

packages/shared/src/utils.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import stripJsonComments from 'strip-json-comments';
33
import { z } from "zod";
44
import { DEFAULT_CONFIG_SETTINGS } from "./constants.js";
55
import { ConfigSettings } from "./types.js";
6-
import { Repo } from "@sourcebot/db";
6+
import { Org, Repo } from "@sourcebot/db";
77
import path from "path";
88
import { env, isRemotePath, loadConfig } from "./env.server.js";
9+
import { isAnonymousAccessAvailable } from './entitlements.js';
910

1011
// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
1112
export const base64Decode = (base64: string): string => {
@@ -118,4 +119,28 @@ export const getRepoPath = (repo: Repo): { path: string, isReadOnly: boolean } =
118119
path: path.join(reposPath, repo.id.toString()),
119120
isReadOnly: false,
120121
}
122+
}
123+
124+
export const isCredentialsLoginEnabled = (org: Org): boolean => {
125+
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED !== undefined) {
126+
return env.AUTH_CREDENTIALS_LOGIN_ENABLED === 'true';
127+
}
128+
129+
return org.isCredentialsLoginEnabled;
130+
}
131+
132+
export const isEmailCodeLoginEnabled = (org: Org): boolean => {
133+
if (env.AUTH_EMAIL_CODE_LOGIN_ENABLED !== undefined) {
134+
return env.AUTH_EMAIL_CODE_LOGIN_ENABLED === 'true';
135+
}
136+
137+
return org.isEmailCodeLoginEnabled;
138+
}
139+
140+
export const isMemberApprovalRequired = (org: Org): boolean => {
141+
if (env.REQUIRE_APPROVAL_NEW_MEMBERS !== undefined) {
142+
return env.REQUIRE_APPROVAL_NEW_MEMBERS === 'true';
143+
}
144+
145+
return org.memberApprovalRequired;
121146
}

packages/web/src/__mocks__/prisma.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export const MOCK_ORG: Org = {
1919
imageUrl: null,
2020
metadata: null,
2121
memberApprovalRequired: false,
22+
isCredentialsLoginEnabled: true,
23+
isEmailCodeLoginEnabled: false,
24+
isAnonymousAccessEnabled: false,
2225
inviteLinkEnabled: false,
2326
inviteLinkId: null,
2427
}

0 commit comments

Comments
 (0)