Skip to content

feat(auth): bootstrap the first user as admin, default the rest to editor - #124

Merged
ssavutu merged 1 commit into
mainfrom
feat/first-login-admin
Jul 31, 2026
Merged

feat(auth): bootstrap the first user as admin, default the rest to editor#124
ssavutu merged 1 commit into
mainfrom
feat/first-login-admin

Conversation

@ssavutu

@ssavutu ssavutu commented Jul 31, 2026

Copy link
Copy Markdown
Member

What

New CMS users are no longer created as admins. The first user to log in against an empty cms_users table is bootstrapped as an admin so a fresh install has someone who can manage roles; everyone after that is created as an editor and has to be promoted from the users screen.

CMS_AUTO_PROMOTE_ALL_ADMINS is removed entirely — it also re-promoted existing users to admin on every login, which made a demotion impossible to keep while the flag was on.

How

  • FindOrCreateUser no longer reads the env var, and the promote-on-login branch for existing users is gone.
  • New insertUser helper does SELECT COUNT(*) FROM cms_users FOR UPDATE and the INSERT inside one transaction. Count 0 → admin, otherwise editor. The transaction is what keeps two simultaneous first logins from both landing as admin.
  • Flag dropped from .env.example, deploy/cms.env.example, docker-compose.yml, deploy/compose.cms.yml, and the deploy/README.md variable list. README now documents the bootstrap behavior instead.

The cms_users.role column default was already 'editor', so there's no schema change.

Deploy note

Existing admins keep their role — this only governs account creation. Any accounts that were auto-promoted while the flag was on will need to be demoted by hand.

Remove CMS_AUTO_PROMOTE_ALL_ADMINS from the production env file when this ships; it's now ignored either way.

Testing

go build ./... and go test ./... pass. The bootstrap path itself is not covered by a test — it needs a live DB for the transaction and locking read, which the current suite doesn't stand up.

🤖 Generated with Claude Code

…itor

New CMS users were promoted to admin whenever CMS_AUTO_PROMOTE_ALL_ADMINS was
set, and existing users were re-promoted on every login. Drop the flag and give
new accounts the editor role instead.

The first user to log in against an empty cms_users table is still bootstrapped
as an admin so a fresh install has someone who can manage roles. The count and
the insert share a transaction with a locking read so two simultaneous first
logins can't both come out as admin.

Existing admins keep their role; this only governs account creation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ssavutu
ssavutu merged commit 8946af4 into main Jul 31, 2026
6 checks passed
@ssavutu
ssavutu deleted the feat/first-login-admin branch July 31, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant