fix(auth): auto-assign bootstrap admin to Administrators group (closes #351) - #533
fix(auth): auto-assign bootstrap admin to Administrators group (closes #351)#533cristim wants to merge 0 commit into
Conversation
|
Warning Review limit reached
More reviews will be available in 59 minutes and 40 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes a gap in admin user bootstrap: admin rows created via the migration helper did not receive the default Administrators group. The change adds ChangesAdmin Group Assignment in Bootstrap
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
… + test Issue #351 acceptance criterion 2 asked for a migration-level idempotent backfill. PR #533 backfilled only in Go (assignAdminGroupAndWarn), which fires only when RunMigrations gets a non-empty admin email. A DB restored from a backup, or migrated without ADMIN_EMAIL set, never re-applied the backfill to pre-existing drifted admin rows. Migration 000024's backfill is one-shot at its version and does not re-run on an already-migrated DB. - Add migration 000053_backfill_admin_group_ids: the same idempotent backfill as 000024 (DISTINCT unnest dedupe, EXISTS guard, only touches empty group_ids so operator customisation is preserved), applied at migrate time regardless of how the deployment invokes migrations. Down is a documented no-op (additive backfill has no safe reverse). - Add integration test TestMigration_BackfillAdminGroupIDs covering the restore / no-admin-email path: it runs migrations with NO admin email so the Go backfill cannot fire, proving the SQL migration repairs a drifted admin row, and asserts idempotency on re-apply. Verified to fail when 000053 is neutered. The #351 group-assignment invariant already runs in default CI: ci.yml's integration-tests job runs `go test -tags=integration ./...` against a postgres service and is required by the ci-success gate, so TestEnsureAdminUser_GroupAssignment is exercised on every PR. Refs #546
… admin group (closes #545, #546) (#579) * test(database): #440 route admin group backfill log to stderr + cover it The #440 stdout-leak fix routed the per-user admin messages to the stdlib logger (stderr) but left the group_ids backfill line in assignAdminGroupAndWarn on fmt.Printf, which writes to stdout. The existing unit regression test could not catch it because it uses an unreachable pool, so the backfill branch never runs. - migrate.go: switch the "Backfilled ..." line from fmt.Printf to log.Printf so every admin-activity message in the file stays on the stderr-bound logger. - Add integration regression test TestAssignAdminGroup_BackfillLogsToStderr_NotStdout that seeds a drifted admin against a real container, runs the real ensureAdminUser path, and asserts the backfill message lands on stderr and never on stdout. Verified to fail when the line is reverted to fmt.Printf. Refs #545 * test(database): #351 add SQL-level admin group_ids backfill migration + test Issue #351 acceptance criterion 2 asked for a migration-level idempotent backfill. PR #533 backfilled only in Go (assignAdminGroupAndWarn), which fires only when RunMigrations gets a non-empty admin email. A DB restored from a backup, or migrated without ADMIN_EMAIL set, never re-applied the backfill to pre-existing drifted admin rows. Migration 000024's backfill is one-shot at its version and does not re-run on an already-migrated DB. - Add migration 000053_backfill_admin_group_ids: the same idempotent backfill as 000024 (DISTINCT unnest dedupe, EXISTS guard, only touches empty group_ids so operator customisation is preserved), applied at migrate time regardless of how the deployment invokes migrations. Down is a documented no-op (additive backfill has no safe reverse). - Add integration test TestMigration_BackfillAdminGroupIDs covering the restore / no-admin-email path: it runs migrations with NO admin email so the Go backfill cannot fire, proving the SQL migration repairs a drifted admin row, and asserts idempotency on re-apply. Verified to fail when 000053 is neutered. The #351 group-assignment invariant already runs in default CI: ci.yml's integration-tests job runs `go test -tags=integration ./...` against a postgres service and is required by the ci-success gate, so TestEnsureAdminUser_GroupAssignment is exercised on every PR. Refs #546 * test(database): renumber backfill_admin_group_ids migration 000053 -> 000056 PR #614 merged 000053_executions_account_fk_restrict on the base branch while this PR was open. Renumber the backfill migration to 000056 (next free slot after 000055_add_paused_status) to clear the collision, and update the test comment references to track the new number. The migration files are renamed via `git mv` to preserve history. The SQL contents are unchanged. * test(database): consolidate stdout/log capture helpers into helpers_test.go Address CodeRabbit nitpick on PR #579: drop the duplicate captureStdoutIntegration / captureLogOutputIntegration helpers from migrate_security_integration_test.go and centralise the integration-tag copies in helpers_test.go (same package, same build tag). The duplication with migrate_security_test.go's captureStdout / captureLogOutput is forced by a package boundary (that file lives in `package migrations`, while integration tests live in `package migrations_test`), so the helpers cannot be shared across files; the new copies in helpers_test.go reuse the same names and carry a comment pointing at the unit-test originals.
|
@coderabbitai full review |
Rate Limit Exceeded
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
0e92300 to
69b857a
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
group_idswith the Administrators group UUID on bothensureAdminUserINSERT paths (no-password and with-password) so a bootstrap admin has group-based permissions from the first boot.assignAdminGroupAndWarnhelper that runs an idempotent backfillUPDATEafter eachensureAdminUsercall, repairing any pre-existing admin rows whosegroup_idsdrifted to empty (e.g. from an out-of-band manual DB seed).WARNafter the backfill if any admin rows still have emptygroup_ids(signals the Administrators group row is missing from the DB), giving operators visibility in container logs.The
defaultAdminGroupIDconstant is duplicated as a package-private literal instead of imported frominternal/authto preserve the correct dependency direction (auth depends on DB, not the reverse).Integration test (
ensure_admin_user_test.go, build tagintegration) covers five scenarios: fresh insert no-password, fresh insert with-password, post-migration drift repair, idempotency under repeated boots, and operator-customisation preservation.Test plan
go test -tags integration ./internal/database/postgres/migrations/... -run TestEnsureAdminUser_GroupAssignmentpasses (requires a running postgres)go build ./...passesgo vet ./...passesCloses #351
Summary by CodeRabbit
Release Notes
Tests
Bug Fixes