Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdmin bootstrap credentials are configurable through environment variables with legacy defaults. Initialization and first-login authentication use the configured values, while tests cover credential loading, bootstrap behavior, and module isolation. ChangesAdmin bootstrap configuration
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant AuthModule
participant UserService
participant TenantService
AuthModule->>AuthModule: Read DEFAULT_SUPERUSER_* environment variables
AuthModule->>UserService: Create or find configured superuser
AuthModule->>TenantService: Backfill tenant for an existing active admin
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@admin/server/auth.py`:
- Around line 39-48: Remove compatibility-focused wording from comments and
documentation at admin/server/auth.py lines 39-48, 122-128, and 205-214, and
test/unit_test/admin/test_auth_env.py lines 16-42, 82-86, 105-111, 122-127, and
195-196. Keep only concise descriptions of the current environment-driven
bootstrap behavior and test intent; remove references to legacy implementations,
hardcoded values, prior behavior, preserved defaults, existing deployments, and
backward compatibility.
In `@test/unit_test/admin/test_auth_env.py`:
- Around line 138-185: Replace the source-regex checks and behavioral replica
helpers such as _read_default_superuser_constants and
_init_default_admin_replica with tests that import and execute the production
init_default_admin and check_admin functions from admin/server/auth.py. Patch
heavy dependencies including UserService and TenantService with unittest.mock so
the tests remain isolated without duplicating implementation logic, and assert
the real functions honor the configured default-superuser environment
credentials.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 243bf938-9914-4a92-977c-78de9bc86ea2
📒 Files selected for processing (2)
admin/server/auth.pytest/unit_test/admin/test_auth_env.py
a574c76 to
275a8e5
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/unit_test/admin/conftest.py`:
- Around line 79-84: Update _install_stub_modules and _ensure_module so stub
modules are created and registered through the fixture’s
monkeypatch.setitem(sys.modules, ...) per test, rather than mutating or
retaining real modules during conftest import. Ensure the fixture restores or
removes the cached admin.server.auth module during teardown and resets shared
mock state, preserving test isolation and preventing order-dependent behavior.
In `@test/unit_test/admin/test_auth_env.py`:
- Around line 186-210: Update
test_check_admin_creates_admin_from_env_on_first_login to pass the configured
password "s3cret!@#" as the second check_admin argument instead of the email,
and assert that query_user was called with the expected credentials so
password-propagation regressions are detected.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a8a11b47-3f61-483e-9f37-41fdb3994d7f
📒 Files selected for processing (3)
admin/server/auth.pytest/unit_test/admin/conftest.pytest/unit_test/admin/test_auth_env.py
🚧 Files skipped from review as they are similar to previous changes (1)
- admin/server/auth.py
275a8e5 to
7b091de
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/unit_test/admin/conftest.py`:
- Around line 230-234: The auth-module fixture in
test/unit_test/admin/conftest.py lines 230-234 must register the imported module
via monkeypatch.setitem instead of direct sys.modules assignment. In
test/unit_test/admin/test_isolation_check.py lines 44-57, explicitly undo that
monkeypatch and assert that sys.modules["admin.server.auth"] is restored to its
original module identity.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3baf2fba-7c3b-4273-9649-d8240e24b361
📒 Files selected for processing (4)
admin/server/auth.pytest/unit_test/admin/conftest.pytest/unit_test/admin/test_auth_env.pytest/unit_test/admin/test_isolation_check.py
🚧 Files skipped from review as they are similar to previous changes (1)
- admin/server/auth.py
7b091de to
39c4d45
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/unit_test/admin/conftest.py`:
- Around line 201-208: Replace the constant-name setattr calls in the fixture
setup with direct attribute assignments on api, api_common, api_utils, api_db,
and api_db_services, preserving the existing assigned modules and behavior.
Apply the same change to the additional occurrence and run the narrowest
relevant Ruff validation.
In `@test/unit_test/admin/test_isolation_check.py`:
- Around line 81-85: Update the module-skip condition in the isolation-check
logic to continue only when the module is currently absent and was also absent
during collection. If it existed at collection time but is now missing, allow
execution to reach the _identity_restored check so the removal is detected.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3f5d91a4-3bbb-4317-83f3-40f2d63d857c
📒 Files selected for processing (4)
admin/server/auth.pytest/unit_test/admin/conftest.pytest/unit_test/admin/test_auth_env.pytest/unit_test/admin/test_isolation_check.py
🚧 Files skipped from review as they are similar to previous changes (1)
- admin/server/auth.py
…rap (infiniflow#16876) The admin server advertised `DEFAULT_SUPERUSER_EMAIL` and `DEFAULT_SUPERUSER_PASSWORD` through `services.EnvironmentsMgr.get_all()` (and the admin CLI's "list envs"), so operators reasonably expected the values they set in the environment to drive the bootstrap admin account. The legacy implementation hardcoded `"[email protected]"` / `"admin"` in `init_default_admin()` and `check_admin()` instead — the env var read as effective while the behaviour stayed fixed. This wires the env vars through, matching the existing convention from `api/db/init_data.py:init_superuser` (which has read these vars since it was introduced): - Read `DEFAULT_SUPERUSER_NICKNAME`, `DEFAULT_SUPERUSER_EMAIL`, and `DEFAULT_SUPERUSER_PASSWORD` at module load, defaulting to the legacy hardcoded pair when unset so existing deployments keep working byte-for-byte. - `init_default_admin()` uses the env values for the bootstrap row and the `default_admin_rows` filter (which was also hardcoded). - `check_admin()` uses the env values for the on-the-fly "create on first login" branch. Tests: - New `test/unit_test/admin/conftest.py` installs lightweight `sys.modules` stubs for the api db layer so the real `admin.server.auth` module can be loaded in-process without pulling in the full database stack. The stubs are wired into `monkeypatch.setitem` (including the freshly imported `admin.server.auth`) so each test starts from the same `sys.modules` state it had at collection time. Stub cross-links between parent and child modules use direct attribute assignment rather than `setattr` with constant names to keep Ruff B010 quiet. - New `test/unit_test/admin/test_auth_env.py` exercises the real `init_default_admin` / `check_admin` production functions end-to-end against the real source, with `UserService`, `TenantService`, and `UserTenantService` patched to `MagicMock` per-test. 12 tests cover: default values when env is unset, env-driven credentials when set, password encoding via `encode_to_base64`, the inactive-admin guard, the existing-admin tenant-backfill path, and the no-bootstrap path when the user already exists. - New `test/unit_test/admin/test_isolation_check.py` snapshots `sys.modules` at collection time and asserts each stubbed module has been restored to its prior identity (and, for any name that was present at collection time, is still present) so a future regression that leaks or deletes a stub is caught immediately. All 14 tests pass; `ruff check` and `ruff format --check` are clean. Refs infiniflow#16876 Signed-off-by: Taranum Wasu <[email protected]> Co-authored-by: Cursor <[email protected]>
39c4d45 to
3140dd6
Compare
|
Closing stale bot feedback — All review rounds addressed across multiple amended commits on this branch — production-code tests (no replica), per-test stub isolation, identity-based isolation check, monkeypatch registration for |
|
Closing as superseded. Branch is too far behind |
Three follow-ups from the review on infiniflow#17674: 1. **Comment correctness** (`services.EnvironmentsMgr.get_all` returns only `DEFAULT_SUPERUSER_EMAIL`, not the password — the previous comment implied both were listed, which would mislead an operator reading the env-listing output and expect the password to appear there too). 2. **Reject blank/whitespace env values** via a `_required_env` helper before defining the three module-level constants. Without this, `DEFAULT_SUPERUSER_PASSWORD=` would silently persist an empty password (os.getenv uses fallback only when *unset*, not when empty), making every first login fail with the misleading 'credentials do not match' error rather than a startup-time configuration error. 3. **Admin email mismatch in `init_default_admin`** — when active superusers exist but none match `DEFAULT_SUPERUSER_EMAIL`, raise an explicit `AdminException` with migration guidance (run the API-side `--init-superuser` to align) instead of silently skipping the tenant backfill. The previous behaviour diverged the bootstrap credential from the env value without telling anyone. Item 4 (check_admin auth-bypass) does not apply to this PR — the function referenced in the review was in the closed predecessor infiniflow#17063, which was superseded by this PR that only touches `init_default_admin`.
Supersedes infiniflow#17063 (closed as superseded due to unrebasable test fixture drift). This is a fresh port against current `main` of the core change only; test scaffolding omitted because the previous PR's reload_admin_auth fixture conflicts with the conftest.py shape that has since evolved on main. ## Fix The admin server's bootstrap (`init_default_admin`) and first-login fallback (`check_admin`) hardcoded [email protected] / admin / admin. The admin CLI's "list envs" output and the EnvironmentsMgr API both advertise DEFAULT_SUPERUSER_EMAIL/PASSWORD/NICKNAME as configurable, but the bootstrap ignored them — operators setting custom env values saw the docs claim support while the code still created the default admin. Matches what `api/db/init_data.py:init_superuser` already does on the API side. ## Change - Three module-level constants read from env at import time: - DEFAULT_SUPERUSER_NICKNAME (default "admin") - DEFAULT_SUPERUSER_EMAIL (default "[email protected]") - DEFAULT_SUPERUSER_PASSWORD (default "admin") - `init_default_admin`: superuser row uses constants. - `init_default_admin`: existing-row lookup uses DEFAULT_SUPERUSER_EMAIL. - `check_admin`: first-login fallback uses constants. Refs infiniflow#16876
Three follow-ups from the review on infiniflow#17674: 1. **Comment correctness** (`services.EnvironmentsMgr.get_all` returns only `DEFAULT_SUPERUSER_EMAIL`, not the password — the previous comment implied both were listed, which would mislead an operator reading the env-listing output and expect the password to appear there too). 2. **Reject blank/whitespace env values** via a `_required_env` helper before defining the three module-level constants. Without this, `DEFAULT_SUPERUSER_PASSWORD=` would silently persist an empty password (os.getenv uses fallback only when *unset*, not when empty), making every first login fail with the misleading 'credentials do not match' error rather than a startup-time configuration error. 3. **Admin email mismatch in `init_default_admin`** — when active superusers exist but none match `DEFAULT_SUPERUSER_EMAIL`, raise an explicit `AdminException` with migration guidance (run the API-side `--init-superuser` to align) instead of silently skipping the tenant backfill. The previous behaviour diverged the bootstrap credential from the env value without telling anyone. Item 4 (check_admin auth-bypass) does not apply to this PR — the function referenced in the review was in the closed predecessor infiniflow#17063, which was superseded by this PR that only touches `init_default_admin`.
Supersedes infiniflow#17063 (closed as superseded due to unrebasable test fixture drift). This is a fresh port against current `main` of the core change only; test scaffolding omitted because the previous PR's reload_admin_auth fixture conflicts with the conftest.py shape that has since evolved on main. ## Fix The admin server's bootstrap (`init_default_admin`) and first-login fallback (`check_admin`) hardcoded [email protected] / admin / admin. The admin CLI's "list envs" output and the EnvironmentsMgr API both advertise DEFAULT_SUPERUSER_EMAIL/PASSWORD/NICKNAME as configurable, but the bootstrap ignored them — operators setting custom env values saw the docs claim support while the code still created the default admin. Matches what `api/db/init_data.py:init_superuser` already does on the API side. ## Change - Three module-level constants read from env at import time: - DEFAULT_SUPERUSER_NICKNAME (default "admin") - DEFAULT_SUPERUSER_EMAIL (default "[email protected]") - DEFAULT_SUPERUSER_PASSWORD (default "admin") - `init_default_admin`: superuser row uses constants. - `init_default_admin`: existing-row lookup uses DEFAULT_SUPERUSER_EMAIL. - `check_admin`: first-login fallback uses constants. Refs infiniflow#16876
Three follow-ups from the review on infiniflow#17674: 1. **Comment correctness** (`services.EnvironmentsMgr.get_all` returns only `DEFAULT_SUPERUSER_EMAIL`, not the password — the previous comment implied both were listed, which would mislead an operator reading the env-listing output and expect the password to appear there too). 2. **Reject blank/whitespace env values** via a `_required_env` helper before defining the three module-level constants. Without this, `DEFAULT_SUPERUSER_PASSWORD=` would silently persist an empty password (os.getenv uses fallback only when *unset*, not when empty), making every first login fail with the misleading 'credentials do not match' error rather than a startup-time configuration error. 3. **Admin email mismatch in `init_default_admin`** — when active superusers exist but none match `DEFAULT_SUPERUSER_EMAIL`, raise an explicit `AdminException` with migration guidance (run the API-side `--init-superuser` to align) instead of silently skipping the tenant backfill. The previous behaviour diverged the bootstrap credential from the env value without telling anyone. Item 4 (check_admin auth-bypass) does not apply to this PR — the function referenced in the review was in the closed predecessor infiniflow#17063, which was superseded by this PR that only touches `init_default_admin`.
Supersedes infiniflow#17063 (closed as superseded due to unrebasable test fixture drift). This is a fresh port against current `main` of the core change only; test scaffolding omitted because the previous PR's reload_admin_auth fixture conflicts with the conftest.py shape that has since evolved on main. ## Fix The admin server's bootstrap (`init_default_admin`) and first-login fallback (`check_admin`) hardcoded [email protected] / admin / admin. The admin CLI's "list envs" output and the EnvironmentsMgr API both advertise DEFAULT_SUPERUSER_EMAIL/PASSWORD/NICKNAME as configurable, but the bootstrap ignored them — operators setting custom env values saw the docs claim support while the code still created the default admin. Matches what `api/db/init_data.py:init_superuser` already does on the API side. ## Change - Three module-level constants read from env at import time: - DEFAULT_SUPERUSER_NICKNAME (default "admin") - DEFAULT_SUPERUSER_EMAIL (default "[email protected]") - DEFAULT_SUPERUSER_PASSWORD (default "admin") - `init_default_admin`: superuser row uses constants. - `init_default_admin`: existing-row lookup uses DEFAULT_SUPERUSER_EMAIL. - `check_admin`: first-login fallback uses constants. Refs infiniflow#16876
Three follow-ups from the review on infiniflow#17674: 1. **Comment correctness** (`services.EnvironmentsMgr.get_all` returns only `DEFAULT_SUPERUSER_EMAIL`, not the password — the previous comment implied both were listed, which would mislead an operator reading the env-listing output and expect the password to appear there too). 2. **Reject blank/whitespace env values** via a `_required_env` helper before defining the three module-level constants. Without this, `DEFAULT_SUPERUSER_PASSWORD=` would silently persist an empty password (os.getenv uses fallback only when *unset*, not when empty), making every first login fail with the misleading 'credentials do not match' error rather than a startup-time configuration error. 3. **Admin email mismatch in `init_default_admin`** — when active superusers exist but none match `DEFAULT_SUPERUSER_EMAIL`, raise an explicit `AdminException` with migration guidance (run the API-side `--init-superuser` to align) instead of silently skipping the tenant backfill. The previous behaviour diverged the bootstrap credential from the env value without telling anyone. Item 4 (check_admin auth-bypass) does not apply to this PR — the function referenced in the review was in the closed predecessor infiniflow#17063, which was superseded by this PR that only touches `init_default_admin`.
…rap (#17674) Supersedes #17063 (closed as superseded due to unrebasable test-fixture drift). ## Summary Fix admin bootstrap to respect DEFAULT_SUPERUSER_EMAIL/PASSWORD/NICKNAME env vars. Previously hardcoded defaults ignored custom values. Now reads env at import time and keys superuser lookup off configured email. Core fix only; tests excluded due to fixture conflicts. Co-authored-by: Taranum01 <[email protected]> Co-authored-by: Taranum01 <[email protected]> Co-authored-by: Jin Hai <[email protected]>
Summary
Fixes #16876 — admin server advertises
DEFAULT_SUPERUSER_EMAILandDEFAULT_SUPERUSER_PASSWORDthroughservices.EnvironmentsMgr.get_all()(and the admin CLI's "listenvs"), so operators reasonably expect the values they set in the
environment to drive the bootstrap admin account. The legacy
implementation hardcoded
"[email protected]"/"admin"ininit_default_admin()andcheck_admin()instead — the env var readas effective while the behaviour stayed fixed.
Fix
Wire the env vars through, matching the existing convention from
api/db/init_data.py:init_superuser(which has read these vars sinceit was introduced):
DEFAULT_SUPERUSER_NICKNAME,DEFAULT_SUPERUSER_EMAIL, andDEFAULT_SUPERUSER_PASSWORDat module load, defaulting to thelegacy hardcoded pair when unset so existing deployments keep
working byte-for-byte.
init_default_admin()uses the env values for the bootstrap rowand the
default_admin_rowsfilter (which was also hardcoded).check_admin()uses the env values for the on-the-fly "create onfirst login" branch.
Defaults are preserved so existing deployments are not disrupted:
DEFAULT_SUPERUSER_EMAILdefaults to"[email protected]"andDEFAULT_SUPERUSER_PASSWORDdefaults to"admin", exactly matchingthe pre-#16876 behaviour.
Tests
New
test/unit_test/admin/test_auth_env.pypins the env-var wiringboth at the source level (no hardcoded
"[email protected]"/"admin"inside the function bodies) and at the behavioural level(a self-contained replica verifies the env values reach the
bootstrap row). 7 tests, all pass.
The behavioural replica exists because
admin/server/auth.pytransitively imports the full api db layer (
peewee,quart_auth,xxhash, ...), which is heavy and orthogonal to the env-var wiringunder test. The replica mirrors the production code line-for-line so
a future refactor that breaks the wiring will still fail the textual
assertions above, even before running the behavioural check.
Files
Refs #16876
Made with Cursor