Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/email-password-registration-toggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'hive': minor
---

Add the `AUTH_EMAIL_PASSWORD_REGISTRATION` environment variable for disabling sign up with email and password, e.g. for self-hosted instances where everyone should sign in through SSO.

Set `AUTH_EMAIL_PASSWORD_REGISTRATION=0` on both the `server` and the `app` service. The server then rejects new email and password sign ups, and the app no longer shows the sign up form (or the "Sign up" link, if no other sign up method is enabled). Users that already have an email and password account, such as organization admins, can still sign in. The default is `1`, which keeps the current behaviour.
2 changes: 2 additions & 0 deletions docker/docker-compose.community.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ services:
# Auth
AUTH_ORGANIZATION_OIDC: '1'
AUTH_REQUIRE_EMAIL_VERIFICATION: '0'
AUTH_EMAIL_PASSWORD_REGISTRATION: '${AUTH_EMAIL_PASSWORD_REGISTRATION:-1}'
GRAPHQL_PUBLIC_ORIGIN: http://localhost:8082
SUPERTOKENS_REFRESH_TOKEN_KEY: '${SUPERTOKENS_REFRESH_TOKEN_KEY}'
SUPERTOKENS_ACCESS_TOKEN_KEY: '${SUPERTOKENS_ACCESS_TOKEN_KEY}'
Expand Down Expand Up @@ -385,6 +386,7 @@ services:
GRAPHQL_PUBLIC_SUBSCRIPTION_ENDPOINT: http://localhost:8082/graphql
GRAPHQL_PUBLIC_ORIGIN: http://localhost:8082
AUTH_REQUIRE_EMAIL_VERIFICATION: '0'
AUTH_EMAIL_PASSWORD_REGISTRATION: '${AUTH_EMAIL_PASSWORD_REGISTRATION:-1}'
AUTH_ORGANIZATION_OIDC: '1'
LOG_LEVEL: '${LOG_LEVEL:-debug}'
SENTRY: '${SENTRY:-0}'
Expand Down
1 change: 1 addition & 0 deletions packages/services/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The GraphQL API for Hive Console.
| `AUTH_OKTA_CLIENT_ID` | No (**Yes** if `AUTH_OKTA` is set) | The Okta client ID. | `g6aff8102efda5e1d12e` |
| `AUTH_OKTA_CLIENT_SECRET` | No (**Yes** if `AUTH_OKTA` is set) | The Okta client secret. | `g12e552xx54xx2b127821dc4abc4491dxxxa6b187` |
| `AUTH_REQUIRE_EMAIL_VERIFICATION` | No | Whether verifying the email address is mandatory. | `1` (enabled) or `0` (disabled) |
| `AUTH_EMAIL_PASSWORD_REGISTRATION` | No | Whether new users can sign up with an email address and a password. Existing users can still sign in with their email address and password. Set the same value on the `app` service. (Default: `1`) | `1` (enabled) or `0` (disabled) |
| `SUPERADMIN_FOREIGN_ORGANIZATION_ACTIONS` | No | Comma-separated authorization actions superadmins are granted in organizations they are not a member of. | Default: `*:describe` |
| `SUPERADMIN_ORGANIZATION_ID` | No | Users provisioned (via SCIM) by this organization are treated as superadmins. | `0b6c2d8e-5f0a-4b1e-9c3d-7a8e6f4b2c1d` |
| `INTEGRATION_GITHUB` | No | Whether the GitHub integration is enabled | `1` (enabled) or `0` (disabled) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import fastify from 'fastify';
import { registerSupertokensAtHome } from '../src/supertokens-at-home';

const env = vi.hoisted(() => ({
requestBroker: null,
clientIPHeaderName: null,
auth: { emailPasswordRegistration: true },
}));
vi.mock('../src/environment', () => ({ env }));

// Only the email lookup is reached when signing up with an email address that is already taken,
// so the other dependencies are empty stand-ins.
async function createServer() {
const pool = {
maybeOneFirst: vi.fn().mockResolvedValue('existing-user-id'),
maybeOne: vi.fn().mockResolvedValue({
userId: 'existing-user-id',
email: 'admin@the-guild.dev',
passwordHash: 'hash',
timeJoined: 0,
}),
};
const server = fastify();
await registerSupertokensAtHome(
server,
{ pool } as any,
{} as any,
{} as any,
{} as any,
{ isFastifyRouteRateLimited: async () => false } as any,
{} as any,
() => {},
{ refreshTokenKey: 'refresh-token-key', accessTokenKey: 'key|public|private' },
null,
false,
{} as any,
);
onTestFinished(() => server.close());
return { server, pool };
}

function signUp(server: Awaited<ReturnType<typeof createServer>>['server']) {
return server.inject({
method: 'POST',
url: '/auth-api/signup',
payload: {
formFields: [
{ id: 'firstName', value: 'Admin' },
{ id: 'lastName', value: 'User' },
{ id: 'email', value: 'admin@the-guild.dev' },
{ id: 'password', value: 'Password123!' },
],
},
});
}

afterEach(() => {
env.auth.emailPasswordRegistration = true;
});

test('email and password sign up is rejected when registration is disabled', async () => {
env.auth.emailPasswordRegistration = false;
const { server, pool } = await createServer();

const response = await signUp(server);

expect(response.json()).toEqual({
status: 'SIGN_UP_NOT_ALLOWED',
reason: 'Signing up with email and password is disabled.',
});
// Rejected before looking up the email, so it does not reveal whether an account exists.
expect(pool.maybeOneFirst).not.toHaveBeenCalled();
expect(pool.maybeOne).not.toHaveBeenCalled();
});

test('email and password sign up is processed when registration is enabled', async () => {
const { server, pool } = await createServer();

const response = await signUp(server);

expect(response.json()).toEqual({
status: 'FIELD_ERROR',
formFields: [{ id: 'email', error: 'This email already exists. Please sign in instead.' }],
});
expect(pool.maybeOneFirst).toHaveBeenCalledTimes(1);
});
6 changes: 6 additions & 0 deletions packages/services/server/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ const EnvironmentModel = zod.object({
AUTH_REQUIRE_EMAIL_VERIFICATION: emptyString(
zod.union([zod.literal('1'), zod.literal('0')]).optional(),
),
// Whether new users can sign up with an email address and a password. Defaults to `1`.
// Existing email and password users can still sign in when this is disabled.
AUTH_EMAIL_PASSWORD_REGISTRATION: emptyString(
zod.union([zod.literal('1'), zod.literal('0')]).optional(),
),
// Comma-separated list of authorization actions (e.g. `*:describe,alert:modify`) superadmins are
// granted within organizations they are not a member of. Defaults to `*:describe`,
// the access superadmins had before this was configurable.
Expand Down Expand Up @@ -739,6 +744,7 @@ export const env = {
: null,
organizationOIDC: authOktaMultiTenant.AUTH_ORGANIZATION_OIDC === '1',
requireEmailVerification: base.AUTH_REQUIRE_EMAIL_VERIFICATION === '1',
emailPasswordRegistration: base.AUTH_EMAIL_PASSWORD_REGISTRATION !== '0',
superadminForeignOrganizationActions: (
base.SUPERADMIN_FOREIGN_ORGANIZATION_ACTIONS ?? '*:describe'
)
Expand Down
8 changes: 8 additions & 0 deletions packages/services/server/src/supertokens-at-home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ export async function registerSupertokensAtHome(
});
}

if (!env.auth.emailPasswordRegistration) {
req.log.debug('Email and password sign up is disabled.');
return rep.send({
status: 'SIGN_UP_NOT_ALLOWED',
reason: 'Signing up with email and password is disabled.',
});
}

const parsedBody = SignUpBodyModel.safeParse(req.body);

if (!parsedBody.success) {
Expand Down
35 changes: 18 additions & 17 deletions packages/web/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ The Hive application as seen on https://app.graphql-hive.com/.

The following environment variables configure the application.

| Name | Required | Description | Example Value |
| --------------------------------- | -------- | --------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| `APP_BASE_URL` | **Yes** | The base url of the app, | `https://app.graphql-hive.com` |
| `GRAPHQL_PUBLIC_ENDPOINT` | **Yes** | The public endpoint of the Hive GraphQL API. | `http://127.0.0.1:4000/graphql` |
| `GRAPHQL_PUBLIC_ORIGIN` | **Yes** | The http address origin of the Hive GraphQL server. | `http://127.0.0.1:4000/` |
| `AUTH_GITHUB` | No | Whether login via GitHub should be allowed | `1` (enabled) or `0` (disabled) |
| `AUTH_GOOGLE` | No | Whether login via Google should be allowed | `1` (enabled) or `0` (disabled) |
| `AUTH_ORGANIZATION_OIDC` | No | Whether linking a Hive organization to an Open ID Connect provider is allowed. (Default: `0`) | `1` (enabled) or `0` (disabled) |
| `AUTH_OKTA` | No | Whether login via Okta should be allowed | `1` (enabled) or `0` (disabled) |
| `AUTH_OKTA_HIDDEN` | No | Whether the Okta login button should be hidden. (Default: `0`) | `1` (enabled) or `0` (disabled) |
| `AUTH_REQUIRE_EMAIL_VERIFICATION` | No | Whether verifying the email address is mandatory. | `1` (enabled) or `0` (disabled) |
| `ENVIRONMENT` | No | The environment of your Hive app. (**Note:** This will be used for Sentry reporting.) | `staging` |
| `SENTRY_DSN` | No | The DSN for reporting errors to Sentry. | `https://dooobars@o557896.ingest.sentry.io/12121212` |
| `SENTRY_ENABLED` | No | Whether Sentry error reporting should be enabled. | `1` (enabled) or `0` (disabled) |
| `DOCS_URL` | No | The URL of the Hive Docs | `https://the-guild.dev/graphql/hive/docs` |
| `NODE_ENV` | No | The `NODE_ENV` value. | `production` |
| `GRAPHQL_PERSISTED_OPERATIONS` | No | Send persisted operation hashes instead of documents to the server. | `1` (enabled) or `0` (disabled) |
| Name | Required | Description | Example Value |
| ---------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| `APP_BASE_URL` | **Yes** | The base url of the app, | `https://app.graphql-hive.com` |
| `GRAPHQL_PUBLIC_ENDPOINT` | **Yes** | The public endpoint of the Hive GraphQL API. | `http://127.0.0.1:4000/graphql` |
| `GRAPHQL_PUBLIC_ORIGIN` | **Yes** | The http address origin of the Hive GraphQL server. | `http://127.0.0.1:4000/` |
| `AUTH_GITHUB` | No | Whether login via GitHub should be allowed | `1` (enabled) or `0` (disabled) |
| `AUTH_GOOGLE` | No | Whether login via Google should be allowed | `1` (enabled) or `0` (disabled) |
| `AUTH_ORGANIZATION_OIDC` | No | Whether linking a Hive organization to an Open ID Connect provider is allowed. (Default: `0`) | `1` (enabled) or `0` (disabled) |
| `AUTH_OKTA` | No | Whether login via Okta should be allowed | `1` (enabled) or `0` (disabled) |
| `AUTH_OKTA_HIDDEN` | No | Whether the Okta login button should be hidden. (Default: `0`) | `1` (enabled) or `0` (disabled) |
| `AUTH_REQUIRE_EMAIL_VERIFICATION` | No | Whether verifying the email address is mandatory. | `1` (enabled) or `0` (disabled) |
| `AUTH_EMAIL_PASSWORD_REGISTRATION` | No | Whether the sign up form for email and password is shown. Set the same value on the `server` service. (Default: `1`) | `1` (enabled) or `0` (disabled) |
| `ENVIRONMENT` | No | The environment of your Hive app. (**Note:** This will be used for Sentry reporting.) | `staging` |
| `SENTRY_DSN` | No | The DSN for reporting errors to Sentry. | `https://dooobars@o557896.ingest.sentry.io/12121212` |
| `SENTRY_ENABLED` | No | Whether Sentry error reporting should be enabled. | `1` (enabled) or `0` (disabled) |
| `DOCS_URL` | No | The URL of the Hive Docs | `https://the-guild.dev/graphql/hive/docs` |
| `NODE_ENV` | No | The `NODE_ENV` value. | `production` |
| `GRAPHQL_PERSISTED_OPERATIONS` | No | Send persisted operation hashes instead of documents to the server. | `1` (enabled) or `0` (disabled) |

## Hive Hosted Configuration

Expand Down
4 changes: 4 additions & 0 deletions packages/web/app/src/env/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const BaseSchema = zod.object({
AUTH_REQUIRE_EMAIL_VERIFICATION: emptyString(
zod.union([zod.literal('1'), zod.literal('0')]).optional(),
),
AUTH_EMAIL_PASSWORD_REGISTRATION: emptyString(
zod.union([zod.literal('1'), zod.literal('0')]).optional(),
),
GRAPHQL_PERSISTED_OPERATIONS: emptyString(
zod.union([zod.literal('1'), zod.literal('0')]).optional(),
),
Expand Down Expand Up @@ -185,6 +188,7 @@ function buildConfig() {
},
organizationOIDC: authOktaMultiTenant.AUTH_ORGANIZATION_OIDC === '1',
requireEmailVerification: base.AUTH_REQUIRE_EMAIL_VERIFICATION === '1',
emailPasswordRegistration: base.AUTH_EMAIL_PASSWORD_REGISTRATION !== '0',
},
sentry: sentry.SENTRY === '1' ? { dsn: sentry.SENTRY_DSN } : null,
stripePublicKey: base.STRIPE_PUBLIC_KEY ?? null,
Expand Down
1 change: 1 addition & 0 deletions packages/web/app/src/env/frontend-public-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const ALLOWED_ENVIRONMENT_VARIABLES = [
'STRIPE_PUBLIC_KEY',
'RELEASE',
'AUTH_REQUIRE_EMAIL_VERIFICATION',
'AUTH_EMAIL_PASSWORD_REGISTRATION',
'GRAPHQL_PERSISTED_OPERATIONS',
'ZENDESK_SUPPORT',
'INTEGRATION_SLACK',
Expand Down
2 changes: 2 additions & 0 deletions packages/web/app/src/env/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const BaseSchema = protectedObject({
AUTH_REQUIRE_EMAIL_VERIFICATION: emptyString(
zod.union([zod.literal('1'), zod.literal('0')]).optional(),
),
AUTH_EMAIL_PASSWORD_REGISTRATION: enabledOrDisabled,
GRAPHQL_PERSISTED_OPERATIONS: emptyString(
zod.union([zod.literal('1'), zod.literal('0')]).optional(),
),
Expand Down Expand Up @@ -146,6 +147,7 @@ function buildConfig() {
google: authGoogle.AUTH_GOOGLE === '1',
okta: authOkta.AUTH_OKTA === '1' ? { hidden: authOkta.AUTH_OKTA_HIDDEN === '1' } : null,
requireEmailVerification: base.AUTH_REQUIRE_EMAIL_VERIFICATION === '1',
emailPasswordRegistration: base.AUTH_EMAIL_PASSWORD_REGISTRATION !== '0',
oidc: authOktaMultiTenant.AUTH_ORGANIZATION_OIDC === '1',
},
integrations: {
Expand Down
8 changes: 8 additions & 0 deletions packages/web/app/src/lib/auth/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ export const enabledProviders: Provider[] = providers.filter(provider => !!env.a
export function isProviderEnabled(provider: Provider) {
return enabledProviders.includes(provider);
}

/**
* Whether a visitor can create an account, either with an email address and a password or through
* one of the enabled providers.
*/
export function isSignUpAvailable() {
return env.auth.emailPasswordRegistration || enabledProviders.length > 0;
}
1 change: 1 addition & 0 deletions packages/web/app/src/lib/testing/mocks/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const env: typeof import('@/env/frontend').env = {
google: false,
okta: null,
requireEmailVerification: false,
emailPasswordRegistration: true,
oidc: false,
},
integrations: {
Expand Down
Loading