diff --git a/Docker-AIO/.env.prod.example b/Docker-AIO/.env.prod.example index 7eedfd4..ab8569e 100644 --- a/Docker-AIO/.env.prod.example +++ b/Docker-AIO/.env.prod.example @@ -40,6 +40,13 @@ DOCWELL_SIGNUP_ENABLED=true # Comma-separated email domains allowed to sign up (blank = any). DOCWELL_SIGNUP_DOMAINS= +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + # Largest attachment in MB (1-100). DOCWELL_MAX_UPLOAD_MB=50 # Days to keep audit log entries. Blank = 365, 0 = forever. diff --git a/Docker-AIO/.env.prod.s3.example b/Docker-AIO/.env.prod.s3.example index e20ce5e..1e2bf7f 100644 --- a/Docker-AIO/.env.prod.s3.example +++ b/Docker-AIO/.env.prod.s3.example @@ -40,6 +40,13 @@ DOCWELL_SIGNUP_ENABLED=true # Comma-separated email domains allowed to sign up (blank = any). DOCWELL_SIGNUP_DOMAINS= +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + # Largest attachment in MB (1-100). DOCWELL_MAX_UPLOAD_MB=50 # Days to keep audit log entries. Blank = 365, 0 = forever. diff --git a/Docker-AIO/.env.prod.seaweedfs.example b/Docker-AIO/.env.prod.seaweedfs.example index 5d5c9da..0b8ded5 100644 --- a/Docker-AIO/.env.prod.seaweedfs.example +++ b/Docker-AIO/.env.prod.seaweedfs.example @@ -40,6 +40,13 @@ DOCWELL_SIGNUP_ENABLED=true # Comma-separated email domains allowed to sign up (blank = any). DOCWELL_SIGNUP_DOMAINS= +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + # Largest attachment in MB (1-100). DOCWELL_MAX_UPLOAD_MB=50 # Days to keep audit log entries. Blank = 365, 0 = forever. diff --git a/Docker-AIO/.env.prod.seaweedfs.split.example b/Docker-AIO/.env.prod.seaweedfs.split.example index 2fb3e35..e40352c 100644 --- a/Docker-AIO/.env.prod.seaweedfs.split.example +++ b/Docker-AIO/.env.prod.seaweedfs.split.example @@ -40,6 +40,13 @@ DOCWELL_SIGNUP_ENABLED=true # Comma-separated email domains allowed to sign up (blank = any). DOCWELL_SIGNUP_DOMAINS= +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + # Largest attachment in MB (1-100). DOCWELL_MAX_UPLOAD_MB=50 # Days to keep audit log entries. Blank = 365, 0 = forever. diff --git a/Docker-AIO/docker-compose.prod.s3.yml b/Docker-AIO/docker-compose.prod.s3.yml index ea3586e..ff2b8f5 100644 --- a/Docker-AIO/docker-compose.prod.s3.yml +++ b/Docker-AIO/docker-compose.prod.s3.yml @@ -59,6 +59,10 @@ services: DOCWELL_DRAWIO_URL: "${DOCWELL_DRAWIO_URL:-}" # Defaults until a superadmin saves sign-up rules in the admin panel. DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" diff --git a/Docker-AIO/docker-compose.prod.seaweedfs.split.yml b/Docker-AIO/docker-compose.prod.seaweedfs.split.yml index 274fcd8..0f95bbf 100644 --- a/Docker-AIO/docker-compose.prod.seaweedfs.split.yml +++ b/Docker-AIO/docker-compose.prod.seaweedfs.split.yml @@ -231,6 +231,10 @@ services: DOCWELL_DRAWIO_URL: "${DOCWELL_DRAWIO_URL:-}" # Defaults until a superadmin saves sign-up rules in the admin panel. DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" diff --git a/Docker-AIO/docker-compose.prod.seaweedfs.yml b/Docker-AIO/docker-compose.prod.seaweedfs.yml index 8b478cd..bfd612d 100644 --- a/Docker-AIO/docker-compose.prod.seaweedfs.yml +++ b/Docker-AIO/docker-compose.prod.seaweedfs.yml @@ -107,6 +107,10 @@ services: DOCWELL_DRAWIO_URL: "${DOCWELL_DRAWIO_URL:-}" # Defaults until a superadmin saves sign-up rules in the admin panel. DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" diff --git a/Docker-AIO/docker-compose.prod.yml b/Docker-AIO/docker-compose.prod.yml index 4ac095f..afb8862 100644 --- a/Docker-AIO/docker-compose.prod.yml +++ b/Docker-AIO/docker-compose.prod.yml @@ -46,6 +46,10 @@ services: DOCWELL_DRAWIO_URL: "${DOCWELL_DRAWIO_URL:-}" # Defaults until a superadmin saves sign-up rules in the admin panel. DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" diff --git a/Docker-AIO/docker-compose.yml b/Docker-AIO/docker-compose.yml index b426c6c..7196058 100644 --- a/Docker-AIO/docker-compose.yml +++ b/Docker-AIO/docker-compose.yml @@ -18,6 +18,10 @@ services: # Links in auth emails point here. DOCWELL_WEB_URL: ${DOCWELL_WEB_URL:-http://localhost:3000} DOCWELL_SIGNUP_ENABLED: ${DOCWELL_SIGNUP_ENABLED:-true} + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: ${DOCWELL_ADMIN_EMAIL:-} + DOCWELL_ADMIN_PASSWORD: ${DOCWELL_ADMIN_PASSWORD:-} + DOCWELL_ADMIN_NAME: ${DOCWELL_ADMIN_NAME:-} DOCWELL_SIGNUP_DOMAINS: ${DOCWELL_SIGNUP_DOMAINS:-} DOCWELL_MAX_UPLOAD_MB: ${DOCWELL_MAX_UPLOAD_MB:-50} DOCWELL_SMTP_HOST: ${DOCWELL_SMTP_HOST:-} diff --git a/Docker/.env.example b/Docker/.env.example index 92d4cb1..a8c5233 100644 --- a/Docker/.env.example +++ b/Docker/.env.example @@ -26,6 +26,13 @@ DOCWELL_SIGNUP_ENABLED=true # Comma-separated email domains allowed to sign up (empty = any). DOCWELL_SIGNUP_DOMAINS= +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + # Email (verification, password reset, sign-in codes), sent by PocketBase. # Empty host = email off. For local testing run `docker compose --profile dev up` # with DOCWELL_SMTP_HOST=mailpit and DOCWELL_SMTP_PORT=1025, then open diff --git a/Docker/.env.prod.example b/Docker/.env.prod.example index 542ed4d..dd06481 100644 --- a/Docker/.env.prod.example +++ b/Docker/.env.prod.example @@ -52,6 +52,13 @@ DOCWELL_SIGNUP_ENABLED=true # Comma-separated email domains allowed to sign up (blank = any). DOCWELL_SIGNUP_DOMAINS= +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + # Largest attachment in MB (1-100). DOCWELL_MAX_UPLOAD_MB=50 # Days to keep audit log entries. Blank = 365, 0 = forever. diff --git a/Docker/.env.prod.s3.example b/Docker/.env.prod.s3.example index 9d92bda..35d7c67 100644 --- a/Docker/.env.prod.s3.example +++ b/Docker/.env.prod.s3.example @@ -52,6 +52,13 @@ DOCWELL_SIGNUP_ENABLED=true # Comma-separated email domains allowed to sign up (blank = any). DOCWELL_SIGNUP_DOMAINS= +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + # Largest attachment in MB (1-100). DOCWELL_MAX_UPLOAD_MB=50 # Days to keep audit log entries. Blank = 365, 0 = forever. diff --git a/Docker/.env.prod.seaweedfs.example b/Docker/.env.prod.seaweedfs.example index 7cca2df..9c393f2 100644 --- a/Docker/.env.prod.seaweedfs.example +++ b/Docker/.env.prod.seaweedfs.example @@ -52,6 +52,13 @@ DOCWELL_SIGNUP_ENABLED=true # Comma-separated email domains allowed to sign up (blank = any). DOCWELL_SIGNUP_DOMAINS= +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + # Largest attachment in MB (1-100). DOCWELL_MAX_UPLOAD_MB=50 # Days to keep audit log entries. Blank = 365, 0 = forever. diff --git a/Docker/.env.prod.seaweedfs.split.example b/Docker/.env.prod.seaweedfs.split.example index 18ea114..1f7f80b 100644 --- a/Docker/.env.prod.seaweedfs.split.example +++ b/Docker/.env.prod.seaweedfs.split.example @@ -52,6 +52,13 @@ DOCWELL_SIGNUP_ENABLED=true # Comma-separated email domains allowed to sign up (blank = any). DOCWELL_SIGNUP_DOMAINS= +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + # Largest attachment in MB (1-100). DOCWELL_MAX_UPLOAD_MB=50 # Days to keep audit log entries. Blank = 365, 0 = forever. diff --git a/Docker/docker-compose.prod.s3.yml b/Docker/docker-compose.prod.s3.yml index 0c351ee..8a5ec04 100644 --- a/Docker/docker-compose.prod.s3.yml +++ b/Docker/docker-compose.prod.s3.yml @@ -95,6 +95,10 @@ services: DOCWELL_CORS_ORIGINS: "${DOCWELL_CORS_ORIGINS:-${DOCWELL_WEB_URL:-http://localhost:3000}}" # Defaults until a superadmin saves sign-up rules in the admin panel. DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" diff --git a/Docker/docker-compose.prod.seaweedfs.split.yml b/Docker/docker-compose.prod.seaweedfs.split.yml index 6ef0852..49505df 100644 --- a/Docker/docker-compose.prod.seaweedfs.split.yml +++ b/Docker/docker-compose.prod.seaweedfs.split.yml @@ -263,6 +263,10 @@ services: DOCWELL_CORS_ORIGINS: "${DOCWELL_CORS_ORIGINS:-${DOCWELL_WEB_URL:-http://localhost:3000}}" # Defaults until a superadmin saves sign-up rules in the admin panel. DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" diff --git a/Docker/docker-compose.prod.seaweedfs.yml b/Docker/docker-compose.prod.seaweedfs.yml index 6197029..fd209c0 100644 --- a/Docker/docker-compose.prod.seaweedfs.yml +++ b/Docker/docker-compose.prod.seaweedfs.yml @@ -139,6 +139,10 @@ services: DOCWELL_CORS_ORIGINS: "${DOCWELL_CORS_ORIGINS:-${DOCWELL_WEB_URL:-http://localhost:3000}}" # Defaults until a superadmin saves sign-up rules in the admin panel. DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" diff --git a/Docker/docker-compose.prod.yml b/Docker/docker-compose.prod.yml index a7319f6..6df4c6b 100644 --- a/Docker/docker-compose.prod.yml +++ b/Docker/docker-compose.prod.yml @@ -82,6 +82,10 @@ services: DOCWELL_CORS_ORIGINS: "${DOCWELL_CORS_ORIGINS:-${DOCWELL_WEB_URL:-http://localhost:3000}}" # Defaults until a superadmin saves sign-up rules in the admin panel. DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" diff --git a/Docker/docker-compose.yml b/Docker/docker-compose.yml index 687cb18..bce9c21 100644 --- a/Docker/docker-compose.yml +++ b/Docker/docker-compose.yml @@ -40,6 +40,10 @@ services: DOCWELL_CORS_ORIGINS: ${DOCWELL_WEB_URL:-http://localhost:3000} # Defaults until a superadmin saves signup rules in the admin panel. DOCWELL_SIGNUP_ENABLED: ${DOCWELL_SIGNUP_ENABLED:-true} + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: ${DOCWELL_ADMIN_EMAIL:-} + DOCWELL_ADMIN_PASSWORD: ${DOCWELL_ADMIN_PASSWORD:-} + DOCWELL_ADMIN_NAME: ${DOCWELL_ADMIN_NAME:-} DOCWELL_SIGNUP_DOMAINS: ${DOCWELL_SIGNUP_DOMAINS:-} DOCWELL_MAX_UPLOAD_MB: ${DOCWELL_MAX_UPLOAD_MB:-50} # Written into PocketBase on every start. PocketBase sends the auth diff --git a/Docs-Site/guide/access.md b/Docs-Site/guide/access.md index c971f8a..b1a0787 100644 --- a/Docs-Site/guide/access.md +++ b/Docs-Site/guide/access.md @@ -4,7 +4,7 @@ | Role | Can | | --- | --- | -| **superadmin** | Everything on the server: every organization, user and workspace, and the instance settings. The first account is one. | +| **superadmin** | Everything on the server: every organization, user and workspace, and the instance settings. The first account is one (the first to sign up, or the one `DOCWELL_ADMIN_EMAIL` creates). | | **admin** | Their own organization: its people (never superadmins) and all of its workspaces. | | **user** | The workspaces they were added to. | diff --git a/Docs-Site/guide/configuration.md b/Docs-Site/guide/configuration.md index f4d0e2a..57aa9cf 100644 --- a/Docs-Site/guide/configuration.md +++ b/Docs-Site/guide/configuration.md @@ -27,6 +27,8 @@ Docwell's collections in it when it starts. Change the image with `DB_IMAGE`. | `DOCWELL_CORS_ORIGINS` | `http://localhost:5173,http://localhost:3000` | Comma-separated origins allowed to call the API from a browser: the web app's address. | | `DOCWELL_SIGNUP_ENABLED` | `true` | Self-service sign-up, until a superadmin saves *Authentication* in the admin panel. | | `DOCWELL_SIGNUP_DOMAINS` | | Comma-separated email domains allowed to sign up (empty: any), with the same rule. | +| `DOCWELL_ADMIN_EMAIL`, `DOCWELL_ADMIN_PASSWORD` | | Creates the first account as superadmin when the server starts and there are no accounts yet. Set both or neither; the password needs 8 characters or more. Once any account exists the server ignores them, so a restart never resets the password or the role. Empty: the first person to sign up becomes the superadmin. | +| `DOCWELL_ADMIN_NAME` | `Admin` | The display name of that account. | | `DOCWELL_MAX_UPLOAD_MB` | `50` | Largest attachment, 1 to 100. | | `DOCWELL_DATA_DIR` | `./data` (`/data` in the image) | The search index. It is rebuilt from the database when missing, so a volume is optional but makes restarts faster. | | `DOCWELL_SHUTDOWN_TIMEOUT` | `15s` | How long to wait for requests and open pages to finish saving on shutdown. | diff --git a/Docs-Site/guide/quick-start.md b/Docs-Site/guide/quick-start.md index 92f01ae..489027d 100644 --- a/Docs-Site/guide/quick-start.md +++ b/Docs-Site/guide/quick-start.md @@ -48,7 +48,8 @@ To build the images from your checkout instead of pulling released ones, add `-- ## First steps 1. **Create the first account.** The first person to sign up becomes the **superadmin** and can open the admin - panel. Do this right away on a server others can reach. + panel. Do this right away on a server others can reach, or set `DOCWELL_ADMIN_EMAIL` and + `DOCWELL_ADMIN_PASSWORD` in `.env` before the first start so the server creates it for you. 2. **Set up email** in *Admin panel → Email*, then send a test email. Without email, people cannot verify their address or reset a forgotten password, and invites have to be passed on by hand (Docwell shows the link). 3. **Decide who may join** in *Admin panel → Authentication*: turn self-service sign-up off and invite people diff --git a/Server/cmd/docwell-server/main.go b/Server/cmd/docwell-server/main.go index c4834ea..d9670d3 100644 --- a/Server/cmd/docwell-server/main.go +++ b/Server/cmd/docwell-server/main.go @@ -86,6 +86,19 @@ func run(log *slog.Logger) error { OAuthRedirects: []string{cfg.WebURL + "/oauth/callback", "docwell://oauth/callback"}, }) settingsSvc.SetOAuthCallback(cfg.WebURL + "/oauth/callback") + if cfg.AdminEmail != "" { + adminCtx, cancelAdmin := context.WithTimeout(context.Background(), time.Minute) + created, err := authSvc.EnsureSuperadmin(adminCtx, cfg.AdminEmail, cfg.AdminPassword, cfg.AdminName) + cancelAdmin() + switch { + case err != nil: + return fmt.Errorf("create superadmin from DOCWELL_ADMIN_EMAIL: %w", err) + case created: + log.Info("created superadmin from DOCWELL_ADMIN_EMAIL", "email", cfg.AdminEmail) + default: + log.Info("accounts already exist; DOCWELL_ADMIN_EMAIL left unused") + } + } auditLog := audit.New(db, log) defer auditLog.Close() hooks := webhooks.New(db, log, webhooks.Options{AllowLocal: cfg.WebhooksAllowLocal}) diff --git a/Server/internal/auth/auth.go b/Server/internal/auth/auth.go index 63d9813..8ac9017 100644 --- a/Server/internal/auth/auth.go +++ b/Server/internal/auth/auth.go @@ -331,6 +331,43 @@ func (s *Service) Signup(ctx context.Context, in SignupInput) (Session, error) { return s.Login(ctx, in.Email, in.Password, "") } +// EnsureSuperadmin creates the instance's first account as superadmin when the +// instance has no accounts yet (DOCWELL_ADMIN_EMAIL, DOCWELL_ADMIN_PASSWORD). +// Once anyone exists it changes nothing, so restarts never reset a password +// or a role changed in the admin panel. created reports whether it made one. +func (s *Service) EnsureSuperadmin(ctx context.Context, email, password, name string) (created bool, err error) { + email = strings.TrimSpace(email) + name = strings.TrimSpace(name) + if name == "" { + name = "Admin" + } + if len(password) < 8 { + return false, &ValidationError{Fields: map[string]string{"password": "Password must be at least 8 characters."}} + } + existing, err := pocketbase.List[UserRecord](ctx, s.pb, "users", pocketbase.ListOptions{PerPage: 1}) + if err != nil { + return false, err + } + if existing.TotalItems > 0 { + return false, nil + } + _, err = pocketbase.Create[UserRecord](ctx, s.pb, "users", map[string]any{ + "email": email, + "password": password, + "passwordConfirm": password, + "name": name, + "status": "active", + "role": access.RoleSuperadmin, + "emailVisibility": false, + // The operator chose this address; there is no one to confirm it. + "verified": true, + }) + if err != nil { + return false, mapError(err) + } + return true, nil +} + func (s *Service) signupRules(ctx context.Context) (bool, []string, error) { if s.opts.Rules != nil { return s.opts.Rules(ctx) diff --git a/Server/internal/auth/auth_test.go b/Server/internal/auth/auth_test.go index bd85694..f1c3821 100644 --- a/Server/internal/auth/auth_test.go +++ b/Server/internal/auth/auth_test.go @@ -171,6 +171,45 @@ func TestFirstSignupBecomesSuperadminThenSignupIsClosed(t *testing.T) { } } +func TestEnsureSuperadminOnlyOnEmptyInstance(t *testing.T) { + f, pb := newFakePB(t) + s := NewService(pb, Options{SignupEnabled: false}) + + var verr *ValidationError + if _, err := s.EnsureSuperadmin(ctx, "root@docwell.test", "short", ""); !errors.As(err, &verr) { + t.Errorf("short password err = %v", err) + } + + created, err := s.EnsureSuperadmin(ctx, " root@docwell.test ", "password123", "") + if err != nil || !created { + t.Fatalf("first run = %v, %v", created, err) + } + if rec := f.users["root@docwell.test"]; rec["role"] != "superadmin" || rec["name"] != "Admin" { + t.Errorf("created = %+v", rec) + } + sess, err := s.Login(ctx, "root@docwell.test", "password123", "") + if err != nil || sess.User.Role != "superadmin" { + t.Errorf("login = %+v, %v", sess.User, err) + } + + // A restart with another password changes nothing. + created, err = s.EnsureSuperadmin(ctx, "root@docwell.test", "different123", "Root") + if err != nil || created || f.passwords["root@docwell.test"] != "password123" { + t.Errorf("second run = %v, %v, password %q", created, err, f.passwords["root@docwell.test"]) + } + // Nor does a different address once someone exists. + if created, err := s.EnsureSuperadmin(ctx, "other@docwell.test", "password123", ""); err != nil || created { + t.Errorf("other address = %v, %v", created, err) + } + if _, ok := f.users["other@docwell.test"]; ok { + t.Error("created a second superadmin") + } + // And the next signup is an ordinary one (closed here). + if _, err := s.Signup(ctx, SignupInput{Email: "bob@docwell.test", Password: "password123", Name: "Bob"}); !errors.Is(err, ErrSignupDisabled) { + t.Errorf("signup after bootstrap err = %v", err) + } +} + func TestSignupDomainsAndValidation(t *testing.T) { _, pb := newFakePB(t) s := NewService(pb, Options{SignupEnabled: true, SignupDomains: []string{"docwell.test"}}) diff --git a/Server/internal/config/config.go b/Server/internal/config/config.go index 2cef306..36846f3 100644 --- a/Server/internal/config/config.go +++ b/Server/internal/config/config.go @@ -26,7 +26,13 @@ type Config struct { // SignupDomains limits signup to these email domains when not empty. SignupDomains []string - PocketBaseURL string + // AdminEmail and AdminPassword create the first account as superadmin when + // the instance has none (both set or neither). AdminName is its name. + AdminEmail string + AdminPassword string + AdminName string + + PocketBaseURL string PocketBaseEmail string PocketBasePassword string @@ -95,6 +101,9 @@ func fromLookup(lookup func(string) (string, bool)) (Config, error) { PocketBasePassword: get("DOCWELL_PB_PASSWORD", ""), SignupEnabled: get("DOCWELL_SIGNUP_ENABLED", "true") == "true", SignupDomains: splitList(get("DOCWELL_SIGNUP_DOMAINS", "")), + AdminEmail: strings.TrimSpace(get("DOCWELL_ADMIN_EMAIL", "")), + AdminPassword: get("DOCWELL_ADMIN_PASSWORD", ""), + AdminName: get("DOCWELL_ADMIN_NAME", ""), DataDir: get("DOCWELL_DATA_DIR", "./data"), ShutdownTimeout: 15 * time.Second, WebhooksAllowLocal: get("DOCWELL_WEBHOOKS_ALLOW_LOCAL", "false") == "true", @@ -154,6 +163,13 @@ func fromLookup(lookup func(string) (string, bool)) (Config, error) { cfg.MaxUploadMB = n } + if (cfg.AdminEmail == "") != (cfg.AdminPassword == "") { + return Config{}, errors.New("set both DOCWELL_ADMIN_EMAIL and DOCWELL_ADMIN_PASSWORD, or neither") + } + if cfg.AdminPassword != "" && len(cfg.AdminPassword) < 8 { + return Config{}, errors.New("DOCWELL_ADMIN_PASSWORD must be at least 8 characters") + } + if cfg.PocketBaseEmail == "" || cfg.PocketBasePassword == "" { return Config{}, errors.New("DOCWELL_PB_EMAIL and DOCWELL_PB_PASSWORD are required") } diff --git a/Server/internal/config/config_test.go b/Server/internal/config/config_test.go index d9715a8..f357fa5 100644 --- a/Server/internal/config/config_test.go +++ b/Server/internal/config/config_test.go @@ -63,6 +63,31 @@ func TestOverridesAndTrimming(t *testing.T) { } } +func TestAdminAccount(t *testing.T) { + base := func(extra map[string]string) map[string]string { + env := map[string]string{"DOCWELL_PB_EMAIL": "a@b.c", "DOCWELL_PB_PASSWORD": "x"} + for k, v := range extra { + env[k] = v + } + return env + } + cfg, err := fromLookup(lookup(base(map[string]string{ + "DOCWELL_ADMIN_EMAIL": " root@docwell.test ", "DOCWELL_ADMIN_PASSWORD": "password123", "DOCWELL_ADMIN_NAME": "Root", + }))) + if err != nil || cfg.AdminEmail != "root@docwell.test" || cfg.AdminPassword != "password123" || cfg.AdminName != "Root" { + t.Errorf("admin = %+v, %v", cfg, err) + } + for name, extra := range map[string]map[string]string{ + "email only": {"DOCWELL_ADMIN_EMAIL": "root@docwell.test"}, + "password only": {"DOCWELL_ADMIN_PASSWORD": "password123"}, + "short password": {"DOCWELL_ADMIN_EMAIL": "root@docwell.test", "DOCWELL_ADMIN_PASSWORD": "short"}, + } { + if _, err := fromLookup(lookup(base(extra))); err == nil { + t.Errorf("%s: expected an error", name) + } + } +} + func TestMissingCredentials(t *testing.T) { if _, err := fromLookup(lookup(nil)); err == nil { t.Fatal("expected error without PocketBase credentials")