Add AUTH_DISABLED opt-out for sharedauth's new pending mode
Docker / Docker Build & Push (push) Successful in 5m39s
Lint / Lint (push) Successful in 51s
Tests / Go backend (push) Successful in 1m12s
Tests / Dashboard checks (push) Successful in 1m11s

sharedauth.NewWithStore now treats an empty AUTHGUARD_URL as "pending"
(still gated, failing closed) rather than permanently disabled, so a
ProjectConfigurator-registered CollabTable no longer needs
AUTHGUARD_URL set at all. Add AUTH_DISABLED (default false) to opt
into the old fully-open behavior explicitly via sharedauth.Disabled(),
and update both READMEs/.env.example to document the three resulting
states.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-14 14:12:34 +02:00
1 parent a018f3da4c
commit f723afa369
7 files changed
+84 -38

No files matched your search

+11 -4
View File
@@ -32,16 +32,22 @@ shared/ Design system and backend helpers shared with sibling proje
CollabTable's browser dashboard authenticates through AuthGuard, a centralized identity service shared across projects (`AUTHGUARD_URL`): create a username, email, and password on first launch, then sign in with the username or email. AuthGuard hashes passwords and issues the `auth_session` cookie the browser holds; CollabTable itself stores no account credentials, only a small local flag recording that its one-time setup screen has run. Unlike the single-admin-tool projects in this workspace, CollabTable is a genuinely multi-user app that already supported full admin user management (list/create/edit/delete accounts, assign roles) before this integration — that maps directly onto AuthGuard's own `/api/admin/users` endpoints, which CollabTable proxies to rather than re-implementing the same authorization rules locally.
`AUTHGUARD_URL` is optional: leaving it unset does not fall back to any local account store — it disables authentication entirely, treating every request as authenticated with nothing gated. Only run without it for local development or a deployment you are certain does not need access control. Because AuthGuard doesn't know "this is CollabTable's initial account" and can't answer "have any accounts been registered yet" (it's a shared identity store other projects and other CollabTable instances may already use), the one-time setup screen is instead gated by a small local flag in Postgres, independent of AuthGuard's own state.
AuthGuard integration has three states:
- `AUTHGUARD_URL` set — used immediately.
- `AUTHGUARD_URL` unset, `AUTH_DISABLED` unset/false (the default) — "pending": auth stays fully enabled/gated, waiting for ProjectConfigurator to push a live URL (see below), and fails closed on auth calls until one arrives.
- `AUTH_DISABLED=true` — authentication is fully off (no login screen, nothing gated, every request treated as authenticated) — only use this for local development or a deployment you are certain does not need access control.
`AUTHGUARD_URL` and `CARRIERNODE_URL` are also only the bootstrap fallback: once CollabTable is registered in ProjectConfigurator's Projects workspace, ProjectConfigurator pushes both values here automatically (`PUT /api/core-services/internal`, `X-Internal-Auth`-gated with `INTERNAL_SERVICE_SECRET`) and keeps them current with no restart — see `Core/ProjectConfigurator/README.md`'s "Pushing core service info to other projects". CarrierNode isn't used by any feature here yet, but the client is wired and ready.
Because AuthGuard doesn't know "this is CollabTable's initial account" and can't answer "have any accounts been registered yet" (it's a shared identity store other projects and other CollabTable instances may already use), the one-time setup screen is instead gated by a small local flag in Postgres, independent of AuthGuard's own state.
`AUTHGUARD_URL` and `CARRIERNODE_URL` are also only the bootstrap fallback: once CollabTable is registered in ProjectConfigurator's Projects workspace, ProjectConfigurator pushes both values here automatically (`PUT /api/core-services/internal`, `X-Internal-Auth`-gated with `INTERNAL_SERVICE_SECRET`) and keeps them current with no restart — see `Core/ProjectConfigurator/README.md`'s "Pushing core service info to other projects". This means `AUTHGUARD_URL` no longer needs to be set at all for a registered deployment: it stays "pending" until the first push. A push never overrides `AUTH_DISABLED=true`; it only ever retargets an already-enabled AuthGuard connection. CarrierNode isn't used by any feature here yet, but the client is wired and ready.
The device-sync API token (generated from the dashboard's Settings page, used by the Android app's `Authorization: Bearer` header for `/api/lists`, `/api/fields`, `/api/items`, `/api/sync`, and notification polling) is unrelated to AuthGuard and unaffected by whether it's configured: it's a long-lived per-account credential for a user's own devices, not a browser session, and stays entirely local to CollabTable's own Postgres.
| Variable | Required | Default | Description |
|----------|----------|---------|--------------|
| `DATABASE_URL` | Yes | — | PostgreSQL connection string (bring your own instance) |
| `AUTHGUARD_URL` | No | unset (auth disabled) | Base URL of the AuthGuard identity service. Leaving it unset disables authentication entirely rather than falling back to local auth. Bootstrap fallback only — see below. |
| `AUTHGUARD_URL` | No | unset (pending) | Optional bootstrap/override base URL of the AuthGuard identity service. Leaving it unset does not disable authentication — it leaves the service "pending" until ProjectConfigurator pushes a URL, failing closed on auth calls until then. Use `AUTH_DISABLED` to actually turn auth off. |
| `AUTH_DISABLED` | No | `false` | Set `true` to disable authentication entirely (no login screen, nothing gated, every request treated as authenticated) — for local development or a standalone deployment with no AuthGuard integration at all. |
| `CARRIERNODE_URL` | No | unset | Base URL of a CarrierNode instance. Bootstrap fallback only — see below; not used by any feature here yet. |
| `INTERNAL_SERVICE_SECRET` | No | unset (push endpoint refuses every caller) | Shared secret, the same value CarrierNode/ProjectConfigurator were configured with, checked against `X-Internal-Auth` on `PUT /api/core-services/internal`. |
| `PORT` | No | `8080` | HTTP listen port |
@@ -84,7 +90,8 @@ Open **http://\<host\>:8080**, complete setup (this registers the first account
cd backend
DATABASE_URL="postgresql://user:password@localhost:5432/collabtable" go run .
# Add AUTHGUARD_URL="http://localhost:8081" to authenticate against a local
# AuthGuard instance instead of running with authentication disabled.
# AuthGuard instance, or AUTH_DISABLED=true to run with authentication
# disabled entirely.
```
### Frontend
+16 -6
View File
@@ -11,12 +11,20 @@ COOKIE_SECURE=false
# Authentication (AuthGuard)
#################################################################
# Base URL of the AuthGuard centralized identity service this app authenticates
# through instead of a local user table.
# through instead of a local user table. AuthGuard integration has three states:
# - AUTHGUARD_URL set: used immediately.
# - AUTHGUARD_URL unset, AUTH_DISABLED unset/false (the default): "pending"
# -- auth stays fully enabled/gated, waiting for ProjectConfigurator to
# push a live URL (see below), and fails closed on auth calls until one
# arrives.
# - AUTH_DISABLED=true: authentication is fully off (no login screen,
# everything open).
# AUTHGUARD_URL=https://auth.example.com
# Leaving AUTHGUARD_URL unset does NOT fall back to any local account store --
# it disables authentication entirely (no login screen, everything open).
# Only run without it for local development or a deployment you are certain
# does not need access control.
# AUTH_DISABLED=true
# Only set AUTH_DISABLED=true for local development or a deployment you are
# certain does not need access control. Leaving AUTHGUARD_URL unset does NOT
# do this -- it just leaves the service "pending" until ProjectConfigurator's
# push arrives.
# Base URL of a CarrierNode instance, for the generic per-project mount API
# (not used by any feature here yet).
@@ -29,7 +37,9 @@ COOKIE_SECURE=false
# automatically (PUT /api/core-services/internal) and keeps them current --
# see Core/ProjectConfigurator/README.md's "Pushing core service info to
# other projects". That push is itself authenticated with this secret, so it
# still needs to be set even though AUTHGUARD_URL/CARRIERNODE_URL don't.
# still needs to be set even though AUTHGUARD_URL/CARRIERNODE_URL don't. A
# push never overrides AUTH_DISABLED=true; it only ever retargets an
# already-enabled AuthGuard connection.
# INTERNAL_SERVICE_SECRET=
#################################################################
+11 -6
View File
@@ -79,8 +79,10 @@ notification events.
Browser authentication proxies to AuthGuard (`AUTHGUARD_URL`), which sets and reads its own
`auth_session` HTTP-only cookie; CollabTable itself mints no session token. Any number of
accounts can exist, with `user`/`admin`/`superadmin` roles managed via `/api/auth/users`.
`AUTHGUARD_URL` is optional: leaving it unset disables authentication entirely (no login
screen, nothing gated) rather than falling back to any local account store -- only use that for
AuthGuard integration has three states: `AUTHGUARD_URL` set (used immediately); unset with
`AUTH_DISABLED` unset/false (the default -- "pending": auth stays fully enabled/gated, waiting
for ProjectConfigurator's push, failing closed on auth calls until then); or `AUTH_DISABLED=true`
(authentication fully off -- no login screen, nothing gated). Only set `AUTH_DISABLED=true` for
local development or a deployment you are certain does not need access control. API tokens are
unrelated to AuthGuard (see below), hashed at rest, and shown only when generated.
@@ -112,10 +114,13 @@ unrelated to AuthGuard (see below), hashed at rest, and shown only when generate
- `APP_VERSION` — optional version displayed in the dashboard, default `dev`
- `COOKIE_SECURE` — set to `true` when served over HTTPS
- `DATABASE_URL` — PostgreSQL connection string, required
- `AUTHGUARD_URL` — base URL of the AuthGuard identity service CollabTable authenticates
against, default unset (auth disabled). Leaving it unset does not fall back to any local
account store -- it disables authentication entirely, treating every request as
authenticated with nothing gated.
- `AUTHGUARD_URL` — optional bootstrap/override base URL of the AuthGuard identity service
CollabTable authenticates against, default unset (pending). Leaving it unset does not disable
authentication -- it leaves the service "pending" until ProjectConfigurator pushes a URL,
failing closed on auth calls until then. Use `AUTH_DISABLED` to actually turn auth off.
- `AUTH_DISABLED` — set `true` to disable authentication entirely (no login screen, nothing
gated, every request treated as authenticated), default `false`. For local development or a
standalone deployment with no AuthGuard integration at all.
- `DB_INIT_RETRY_INTERVAL_MS` — startup retry delay, default `5000`
- `DB_INIT_RETRY_MAX_ATTEMPTS` — maximum startup attempts, `0` retries forever
- `SYNC_MAX_FUTURE_SKEW_MS` — allowed client timestamp skew, default `0`
+16 -7
View File
@@ -102,13 +102,22 @@ func (s collabTableAuthStore) UnclaimSetup(ctx context.Context) error {
}
// newAuthService builds CollabTable's sharedauth.Service. authGuardURL is
// AUTHGUARD_URL; empty means auth-disabled mode (see the package doc comment
// above and sharedauth's own "Auth-disabled mode" section). "collabtable" is
// CollabTable's projectKey, letting an AuthGuard administrator restrict which
// accounts may log into CollabTable specifically -- handled entirely
// server-side by AuthGuard once passed here.
func newAuthService(database *DB, authGuardURL string, secureCookies bool) *sharedauth.Service {
return sharedauth.NewWithStore(collabTableAuthStore{db: database}, legacySessionCookieName, secureCookies, authGuardURL, "collabtable")
// AUTHGUARD_URL, an optional bootstrap/override value: empty now means
// "pending" (see the package doc comment above and sharedauth's own
// "Auth-disabled mode" section) rather than disabled. authDisabled is
// AUTH_DISABLED, the explicit opt-out for local development or a standalone
// deployment that wants no AuthGuard integration at all -- it passes
// sharedauth.Disabled(), matching CollabTable's old unset-AUTHGUARD_URL
// behavior. "collabtable" is CollabTable's projectKey, letting an AuthGuard
// administrator restrict which accounts may log into CollabTable
// specifically -- handled entirely server-side by AuthGuard once passed
// here.
func newAuthService(database *DB, authGuardURL string, secureCookies bool, authDisabled bool) *sharedauth.Service {
var opts []sharedauth.ServiceOption
if authDisabled {
opts = append(opts, sharedauth.Disabled())
}
return sharedauth.NewWithStore(collabTableAuthStore{db: database}, legacySessionCookieName, secureCookies, authGuardURL, "collabtable", opts...)
}
// --- Device-sync API bearer token (unrelated to AuthGuard) ------------------
+12 -4
View File
@@ -42,10 +42,18 @@ func TestCollabTableAuthStoreSetLoginRequiredIsNoOp(t *testing.T) {
func TestNewAuthServiceBuildsAService(t *testing.T) {
// newAuthService must not panic given a nil *DB and no AuthGuard URL
// (auth-disabled mode) -- the store adapter's IsSetupClaimed/
// TryClaimSetup/UnclaimSetup only get called once a real request comes in
// and AuthGuard is enabled, so construction alone must be safe.
if service := newAuthService(nil, "", false); service == nil {
// ("pending" mode) -- the store adapter's IsSetupClaimed/TryClaimSetup/
// UnclaimSetup only get called once a real request comes in and AuthGuard
// is enabled, so construction alone must be safe.
if service := newAuthService(nil, "", false, false); service == nil {
t.Fatal("newAuthService() returned nil")
}
}
func TestNewAuthServiceBuildsADisabledService(t *testing.T) {
// authDisabled=true must also not panic given a nil *DB and no AuthGuard
// URL -- this is the explicit auth-disabled mode (sharedauth.Disabled()).
if service := newAuthService(nil, "", false, true); service == nil {
t.Fatal("newAuthService() returned nil")
}
}
+1 -1
View File
@@ -6,6 +6,6 @@ import (
)
func TestRegisterRoutes(t *testing.T) {
server := &Server{auth: newAuthService(nil, "", false)}
server := &Server{auth: newAuthService(nil, "", false, false)}
server.registerRoutes(http.NewServeMux(), webFS)
}
+17 -10
View File
@@ -57,18 +57,25 @@ func main() {
go database.pruneExpiredSessions(ctx)
go database.cleanupNotifications(ctx)
// AuthGuard is optional (see auth.go's top-of-file doc comment and
// sharedauth's own "Auth-disabled mode" section): an unset AUTHGUARD_URL
// means every request is treated as already authenticated, with nothing
// gated -- an explicit choice for local development or a standalone
// deployment, not a degraded fallback.
// AuthGuard integration has three states now (see auth.go's top-of-file
// doc comment and sharedauth's own "Auth-disabled mode" section): an
// AUTHGUARD_URL set is used immediately; unset with AUTH_DISABLED
// unset/false is "pending" (fully gated, failing closed until
// ProjectConfigurator's push arrives); AUTH_DISABLED=true is an explicit
// opt-out where every request is treated as already authenticated, with
// nothing gated -- for local development or a standalone deployment, not
// a degraded fallback.
authGuardURL := strings.TrimSpace(os.Getenv("AUTHGUARD_URL"))
if authGuardURL != "" {
authDisabled := strings.EqualFold(os.Getenv("AUTH_DISABLED"), "true")
switch {
case authDisabled:
fmt.Println("auth: DISABLED (AUTH_DISABLED=true) -- every request is treated as authenticated")
case authGuardURL != "":
fmt.Printf("auth: AuthGuard at %s\n", authGuardURL)
} else {
fmt.Println("auth: DISABLED (AUTHGUARD_URL not set) -- every request is treated as authenticated")
default:
fmt.Println("auth: PENDING (AUTHGUARD_URL not set) -- waiting for ProjectConfigurator to push an AuthGuard URL; auth calls fail closed until then")
}
auth := newAuthService(database, authGuardURL, strings.EqualFold(os.Getenv("COOKIE_SECURE"), "true"))
auth := newAuthService(database, authGuardURL, strings.EqualFold(os.Getenv("COOKIE_SECURE"), "true"), authDisabled)
// coreConfig holds the AuthGuard/CarrierNode URLs ProjectConfigurator pushes once this project
// is registered there (PUT /api/core-services/internal, see registerRoutes) -- AUTHGUARD_URL and
@@ -76,7 +83,7 @@ func main() {
// See Core/ProjectConfigurator/README.md's "Pushing core service info to other projects".
// auth.SetAuthGuardBaseURL retargets the live AuthGuard client sharedauth.Service holds
// internally on every push, so AuthGuard moving to a new URL takes effect without a restart -- it
// is a no-op when this service was constructed in auth-disabled mode (AUTHGUARD_URL unset above).
// is a no-op when this service was constructed in auth-disabled mode (AUTH_DISABLED=true above).
internalServiceSecret := strings.TrimSpace(os.Getenv("INTERNAL_SERVICE_SECRET"))
carrierNodeURL := strings.TrimSpace(os.Getenv("CARRIERNODE_URL"))
coreConfig := coreconfig.NewStore(coreconfig.Info{AuthGuardURL: authGuardURL, CarrierNodeURL: carrierNodeURL})