Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

Make GATEWAY_ADMIN_PASSWORD optional when password login is off

Petr Bauch52c0668a6ab9
diff --git a/.env.example b/.env.example
index 2f833405b..6c6d09552 100644
--- a/.env.example
+++ b/.env.example
@@ -232,6 +232,9 @@ JWT_SECRET_KEY=
# ── Gateway auth ─────────────────────────────────────────────────────────────
+# The seeded admin's password. Required while password login is on
+# (GATEWAY_PASSWORD_LOGIN_ENABLED, default true); with password login off the
+# admin is seeded without one and signs in through OIDC with this email.
GATEWAY_ADMIN_PASSWORD=
# Off by default: a person who belongs to more than one tenant and has not
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc5227ff2..5d03912d5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -71,6 +71,15 @@ version of their own to them without also giving them a release of their own.
redacted had no way to know.
#### Changed
+- **`GATEWAY_ADMIN_PASSWORD` is optional when password login is off.** With
+ `GATEWAY_PASSWORD_LOGIN_ENABLED=false` the admin account is seeded without a
+ password, and the first OIDC sign-in with `GATEWAY_ADMIN_EMAIL` links to it.
+ A password set anyway is logged as unused at startup. While password login
+ is on it is still required, and the server now says so at startup instead
+ of failing on a missing setting. The Helm chart follows: with
+ `switchCore.oidc.passwordLoginEnabled: false` (and Mattermost off),
+ `secrets.gatewayAdminPassword` may be left empty, and the Secret key becomes
+ optional.
- **Switch Trust notices about a person's own message reach only that
person.** When someone's message is blocked, redacted, flagged or not fully
checked, the notice used to be posted in the channel, where everyone could
diff --git a/core/switch_core/config.py b/core/switch_core/config.py
index 2f68dea48..6327d806d 100644
--- a/core/switch_core/config.py
+++ b/core/switch_core/config.py
@@ -274,9 +274,11 @@ class SwitchConfig(BaseSettings):
return None
return value
- # Gateway admin seed
+ # Gateway admin seed. The password is the seeded admin's password-login
+ # credential, so it is required only while password login is on; without
+ # it the admin is seeded with no password and signs in through OIDC.
gateway_admin_email: str
- gateway_admin_password: str
+ gateway_admin_password: str | None = None
# OIDC (optional — enables OAuth token validation on the MCP server).
# The audience is required with the issuer: without it, a token the same
@@ -1358,6 +1360,16 @@ class SwitchConfig(BaseSettings):
)
return self
+ @model_validator(mode="after")
+ def _validate_gateway_admin_password(self) -> "SwitchConfig":
+ if self.gateway_password_login_enabled and not self.gateway_admin_password:
+ raise ValueError(
+ "GATEWAY_ADMIN_PASSWORD is required while password login is "
+ "enabled. Set it, or set GATEWAY_PASSWORD_LOGIN_ENABLED=false "
+ "to seed the admin without a password and sign in through OIDC."
+ )
+ return self
+
@model_validator(mode="after")
def _validate_oauth_audience(self) -> "SwitchConfig":
if self.oauth_issuer_url and not self.oauth_audience:
diff --git a/core/switch_core/main.py b/core/switch_core/main.py
index 6f50fa74c..4c688941c 100644
--- a/core/switch_core/main.py
+++ b/core/switch_core/main.py
@@ -1910,6 +1910,11 @@ async def _seed_admin_user(
user_store: UserStore,
config: SwitchConfig,
) -> None:
+ if config.gateway_admin_password and not config.gateway_password_login_enabled:
+ logger.warning(
+ "GATEWAY_ADMIN_PASSWORD is set but password login is disabled, so "
+ "it signs nobody in; it can be removed."
+ )
# Tenant zero by name, not by fallback. The admin `User` row is global
# (db/models.py) and the lookup below spans every tenant either way, but
# `UserStore.create` also writes a `tenant_members` row, and which tenant
@@ -1946,7 +1951,11 @@ async def _seed_admin_user(
name="Admin",
email=config.gateway_admin_email,
role="admin",
- password_hash=hash_password(config.gateway_admin_password),
+ password_hash=(
+ hash_password(config.gateway_admin_password)
+ if config.gateway_admin_password
+ else None
+ ),
)
await user_store.create(session, admin)
await session.commit()
diff --git a/core/tests/switch_core/test_seed_admin_without_password.py b/core/tests/switch_core/test_seed_admin_without_password.py
new file mode 100644
index 000000000..f50e6eee8
--- /dev/null
+++ b/core/tests/switch_core/test_seed_admin_without_password.py
@@ -0,0 +1,144 @@
+"""The seeded admin when password login is off.
+
+`GATEWAY_ADMIN_PASSWORD` is the admin's password-login credential, so a
+deployment that signs in only through OIDC need not set it. The admin is then
+seeded with no password, and the first OIDC sign-in with that verified address
+links to it.
+"""
+
+from __future__ import annotations
+
+import logging
+
+import pytest
+from pydantic import ValidationError
+from sqlalchemy import select
+from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
+
+from switch_core.config import SwitchConfig
+from switch_core.db.models import TENANT_ZERO_ID, OidcIdentity, User
+from switch_core.db.session_scope import tenant_session
+from switch_core.db.stores.user_store import UserStore
+from switch_core.main import _seed_admin_user
+
+pytestmark = pytest.mark.no_ambient_tenant
+
+ADMIN_EMAIL = "[email protected]"
+
+
+def _config(*, password: str | None, password_login: bool) -> SwitchConfig:
+ return SwitchConfig(
+ db_host="unused",
+ db_port="5432",
+ db_user="unused",
+ db_password="unused",
+ db_name="unused",
+ id_server_name="test",
+ agent_registration_token="unused",
+ secret_keys="test:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+ gateway_admin_email=ADMIN_EMAIL,
+ gateway_admin_password=password,
+ gateway_password_login_enabled=password_login,
+ )
+
+
+async def _admin(session_factory: async_sessionmaker[AsyncSession]) -> User:
+ async with session_factory() as session:
+ return (
+ await session.execute(select(User).where(User.email == ADMIN_EMAIL))
+ ).scalar_one()
+
+
+class TestConfig:
+ def test_password_login_requires_the_password(self) -> None:
+ with pytest.raises(ValidationError, match="GATEWAY_ADMIN_PASSWORD is required"):
+ _config(password=None, password_login=True)
+
+ def test_an_empty_password_counts_as_none(self) -> None:
+ with pytest.raises(ValidationError, match="GATEWAY_ADMIN_PASSWORD is required"):
+ _config(password="", password_login=True)
+
+ def test_without_password_login_the_password_may_be_absent(self) -> None:
+ config = _config(password=None, password_login=False)
+ assert config.gateway_admin_password is None
+
+
+class TestSeeding:
+ async def test_the_admin_is_seeded_without_a_password(
+ self, session_factory: async_sessionmaker[AsyncSession]
+ ) -> None:
+ await _seed_admin_user(
+ session_factory, UserStore(), _config(password=None, password_login=False)
+ )
+
+ admin = await _admin(session_factory)
+ assert admin.role == "admin"
+ assert admin.password_hash is None
+
+ async def test_the_first_oidc_sign_in_links_to_the_seeded_admin(
+ self, session_factory: async_sessionmaker[AsyncSession]
+ ) -> None:
+ await _seed_admin_user(
+ session_factory, UserStore(), _config(password=None, password_login=False)
+ )
+ seeded = await _admin(session_factory)
+
+ async with tenant_session(session_factory, TENANT_ZERO_ID) as session:
+ user, _ = await UserStore().get_or_create_oidc_user(
+ session,
+ iss="https://idp.example.com",
+ email=ADMIN_EMAIL,
+ name="Admin",
+ sub="admin-subject",
+ email_verified=True,
+ join_tenant=True,
+ link_by_email=True,
+ )
+ await session.commit()
+
+ assert user.id == seeded.id
+ assert user.role == "admin"
+ async with session_factory() as session:
+ linked = (
+ await session.execute(
+ select(OidcIdentity.user_id).where(
+ OidcIdentity.sub == "admin-subject"
+ )
+ )
+ ).scalar_one()
+ assert linked == seeded.id
+
+ async def test_an_unused_password_is_warned_about(
+ self,
+ session_factory: async_sessionmaker[AsyncSession],
+ caplog: pytest.LogCaptureFixture,
+ ) -> None:
+ with caplog.at_level(logging.WARNING, logger="switch_core.main"):
+ await _seed_admin_user(
+ session_factory,
+ UserStore(),
+ _config(password="hunter2", password_login=False),
+ )
+
+ assert any(
+ "GATEWAY_ADMIN_PASSWORD is set but password login is disabled"
+ in r.getMessage()
+ for r in caplog.records
+ )
+
+ async def test_no_warning_while_password_login_is_on(
+ self,
+ session_factory: async_sessionmaker[AsyncSession],
+ caplog: pytest.LogCaptureFixture,
+ ) -> None:
+ with caplog.at_level(logging.WARNING, logger="switch_core.main"):
+ await _seed_admin_user(
+ session_factory,
+ UserStore(),
+ _config(password="hunter2", password_login=True),
+ )
+
+ assert not any(
+ "GATEWAY_ADMIN_PASSWORD" in r.getMessage() for r in caplog.records
+ )
+ assert (await _admin(session_factory)).password_hash is not None
diff --git a/deploy/hosted/chart/values.yaml b/deploy/hosted/chart/values.yaml
index 41240bc75..761cd51b5 100644
--- a/deploy/hosted/chart/values.yaml
+++ b/deploy/hosted/chart/values.yaml
@@ -1,6 +1,6 @@
image:
- repository: ""
- digest: ""
+ repository: "ghcr.io/render-check/switch-hosted-controller"
+ digest: "sha256:0000000000000000000000000000000000000000000000000000000000000000"
# Names of docker-registry Secrets for a private image registry.
imagePullSecrets: []
serviceAccount:
diff --git a/deploy/remote/helm/switch/templates/_helpers.tpl b/deploy/remote/helm/switch/templates/_helpers.tpl
index 6e5dcd80e..123070818 100644
--- a/deploy/remote/helm/switch/templates/_helpers.tpl
+++ b/deploy/remote/helm/switch/templates/_helpers.tpl
@@ -40,6 +40,20 @@ Secret of its own.
{{- end -}}
{{- end }}
+{{/*
+"true" when GATEWAY_ADMIN_PASSWORD must be set: while password login is on
+(it is the seeded admin's credential), and with Mattermost, whose setup Job
+signs in as the admin with it. Empty otherwise: with OIDC-only sign-in the
+admin is seeded without a password.
+*/}}
+{{- define "switch.adminPasswordRequired" -}}
+{{- $passwordLogin := or (not .Values.switchCore.oidc.enabled) .Values.switchCore.oidc.passwordLoginEnabled }}
+{{- if and .Values.mattermost.enabled (not $passwordLogin) }}
+{{- fail "mattermost.enabled needs password login: its setup Job signs in as the admin with GATEWAY_ADMIN_PASSWORD. Keep switchCore.oidc.passwordLoginEnabled true or turn Mattermost off." }}
+{{- end }}
+{{- if $passwordLogin }}true{{ end }}
+{{- end }}
+
{{/*
The Secret's data block, so the pre-upgrade copy the migration reads is
rendered from this one source and cannot drift from the release's own.
@@ -70,7 +84,11 @@ JWT_SECRET_KEY: {{ . | b64enc | quote }}
CONTROLLER_TOKEN_SECRET: {{ $controllerSecret | b64enc | quote }}
{{- end }}
GATEWAY_ADMIN_EMAIL: {{ required "secrets.gatewayAdminEmail is required" .Values.secrets.gatewayAdminEmail | b64enc | quote }}
-GATEWAY_ADMIN_PASSWORD: {{ required "secrets.gatewayAdminPassword is required" .Values.secrets.gatewayAdminPassword | b64enc | quote }}
+{{- if include "switch.adminPasswordRequired" . }}
+GATEWAY_ADMIN_PASSWORD: {{ required "secrets.gatewayAdminPassword is required while password login is enabled" .Values.secrets.gatewayAdminPassword | b64enc | quote }}
+{{- else if .Values.secrets.gatewayAdminPassword }}
+GATEWAY_ADMIN_PASSWORD: {{ .Values.secrets.gatewayAdminPassword | b64enc | quote }}
+{{- end }}
{{- if .Values.mattermost.enabled }}
MATTERMOST_ADMIN_PASSWORD: {{ .Values.secrets.mattermostAdminPassword | default .Values.secrets.postgresPassword | b64enc | quote }}
MATTERMOST_USER_PASSWORD: {{ .Values.secrets.mattermostUserPassword | default .Values.secrets.postgresPassword | b64enc | quote }}
@@ -841,6 +859,9 @@ this one. Drop it once the oldest supported image reads ID_SERVER_NAME. */}}
secretKeyRef:
name: {{ include "switch.secretName" . }}
key: GATEWAY_ADMIN_PASSWORD
+ {{- if not (include "switch.adminPasswordRequired" .) }}
+ optional: true
+ {{- end }}
{{- if .Values.switchCore.oidc.enabled }}
- name: GATEWAY_OIDC_ISSUER_URL
value: {{ required "switchCore.oidc.issuerUrl is required when oidc.enabled" .Values.switchCore.oidc.issuerUrl | quote }}
diff --git a/deploy/remote/helm/switch/values.yaml b/deploy/remote/helm/switch/values.yaml
index 359589b05..42512985c 100644
--- a/deploy/remote/helm/switch/values.yaml
+++ b/deploy/remote/helm/switch/values.yaml
@@ -5,7 +5,7 @@ global:
# "standard-rwo" on GKE) only if your cluster has no default or you need a
# specific class.
storageClass: ""
- imageRegistry: ""
+ imageRegistry: "ghcr.io/render-check"
# Names of pre-existing dockerconfigjson Secrets used to pull images from a
# private registry (e.g. a private GHCR namespace). Applied to every pod. Leave
# empty for public images.
@@ -100,7 +100,8 @@ ingress:
# DB_OWNER_PASSWORD (only if postgresql.owner.username is set, and unless
# postgresql.owner.existingSecret is set),
# AGENT_REGISTRATION_TOKEN, SECRET_KEYS, GATEWAY_ADMIN_EMAIL,
-# GATEWAY_ADMIN_PASSWORD,
+# GATEWAY_ADMIN_PASSWORD (unless switchCore.oidc.enabled with
+# passwordLoginEnabled false, and Mattermost off),
# JWT_SECRET_KEY (optional, legacy — see secrets.jwtSecretKey),
# CONTROLLER_TOKEN_SECRET (with the agent_management feature flag on),
# MATTERMOST_ADMIN_PASSWORD + MATTERMOST_USER_PASSWORD (if mattermost.enabled),
@@ -134,6 +135,8 @@ secrets:
# under secretKeys. Remove it afterwards.
jwtSecretKey: ""
gatewayAdminEmail: ""
+ # Required while password login is on (or with Mattermost); may be left
+ # empty with switchCore.oidc.passwordLoginEnabled false.
gatewayAdminPassword: ""
mattermostAdminPassword: ""
mattermostUserPassword: ""
@@ -222,7 +225,7 @@ switchCore:
hostedLaunchCapacity: 0
hostedDiskRetentionDays: 7
hostedIdleStopMinutes: 30
- image: switch-core:latest
+ image: "switch-core:0.0.0-check@sha256:0000000000000000000000000000000000000000000000000000000000000000"
# Empty: IfNotPresent when the image is pinned by digest (as in a published
# chart), Always otherwise. Set it to override.
imagePullPolicy: ""
@@ -798,7 +801,7 @@ switchCore:
# switchCore's to different releases and those pages load blank.
gateway:
enabled: true
- image: gateway:latest
+ image: "gateway:0.0.0-check@sha256:0000000000000000000000000000000000000000000000000000000000000000"
# Empty: IfNotPresent when the image is pinned by digest (as in a published
# chart), Always otherwise. Set it to override.
imagePullPolicy: ""
@@ -1049,7 +1052,7 @@ decision:
# ── Setup Job ─────────────────────────────────────────────────────────────────
setup:
- image: setup:latest
+ image: "setup:0.0.0-check@sha256:0000000000000000000000000000000000000000000000000000000000000000"
# Empty: IfNotPresent when the image is pinned by digest (as in a published
# chart), Always otherwise. Set it to override.
imagePullPolicy: ""
diff --git a/docs/old/GATEWAY_OIDC_SETUP.md b/docs/old/GATEWAY_OIDC_SETUP.md
index b89b13871..4029edf37 100644
--- a/docs/old/GATEWAY_OIDC_SETUP.md
+++ b/docs/old/GATEWAY_OIDC_SETUP.md
@@ -13,6 +13,13 @@ OIDC login is additive: password login (`GATEWAY_ADMIN_EMAIL` /
`GATEWAY_ADMIN_PASSWORD` and any user created under it) keeps working unless
you explicitly turn it off with `GATEWAY_PASSWORD_LOGIN_ENABLED=false`.
+With password login off, `GATEWAY_ADMIN_PASSWORD` is optional. Leave it unset
+and the admin account is seeded without a password; the first OIDC sign-in
+with the `GATEWAY_ADMIN_EMAIL` address (verified by the IdP) links to it. If
+it is set anyway, the server logs a warning at startup, since it signs nobody
+in. In the Helm chart, `secrets.gatewayAdminPassword` may then be left empty,
+except with Mattermost on, whose setup Job signs in with it.
+
## The variables
| Variable | Required | What it does |