Skip to content

Harden web control auth and upload inputs#24

Open
ceej640 wants to merge 4 commits into
gently-project:developmentfrom
ceej640:ceej/fix-web-auth-hardening
Open

Harden web control auth and upload inputs#24
ceej640 wants to merge 4 commits into
gently-project:developmentfrom
ceej640:ceej/fix-web-auth-hardening

Conversation

@ceej640

@ceej640 ceej640 commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • gate HTTP image and 3D volume upload routes with the existing control-role dependency
  • validate uploaded array shape, dtype, byte count, and base64 before reshaping
  • make /ws and /ws/agent use the same account/token role resolver as REST control routes
  • let read-only launcher commands such as --sessions run without ANTHROPIC_API_KEY and avoid creating a hidden first-run admin password
  • add focused tests for legacy token, account roles, route auth, and upload validation

Stacking

This branch is stacked on #23 so the full suite can collect. Once #23 merges into 0.22-dev, this PR should reduce to the auth/upload hardening commit.

Verification

  • uv run pytest tests/test_web_auth_hardening.py tests/test_data_catalog.py -q
  • uv run pytest -q
    • 561 passed, 4 skipped

@pskeshu

pskeshu commented Jun 1, 2026 via email

Copy link
Copy Markdown
Collaborator

@ceej640

ceej640 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

Yes, I agree. This PR hardens the existing auth/upload surfaces, but it does not solve day-to-day account administration on the DiSPIM Gently server.

I would keep this PR scoped as the lower-level enforcement/auth correctness layer, then add user management as a separate operator/admin PR. The useful shape is probably:

  • admin-only CLI commands for users list/add/disable/reset-password/set-role/rotate-token
  • a small authenticated admin page for the same operations when someone is at the microscope server
  • explicit roles such as admin, operator, and viewer
  • no implicit first-run hidden credentials
  • audit log entries for account changes
  • a documented recovery path for a locked-out local server

That would make the server easier to operate without weakening the security hardening in this patch.

@ceej640

ceej640 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up implemented from this thread in commit a81d15f.

What changed:

  • Added account-store methods for role changes, password resets, and deletion, with last-admin protection.
  • Added admin-only API routes to list, update, and delete web UI users.
  • Added launcher CLI account management commands: --users, --add-user, --set-role, --reset-password, and --delete-user.
  • Made the launcher import the agent lazily so account-management commands can run even when runtime dependencies like gently_perception are not installed.

Verification:

  • python launch_gently.py --help
  • pytest tests/test_web_auth_hardening.py -q -p no:cacheprovider

@ceej640

ceej640 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up implemented from the user-management thread in commit 19577ab.

What changed:

  • Added an admin-only /admin/users page for listing users, creating users, changing roles, resetting passwords, and deleting users.
  • Added a header users link that appears only for signed-in admins.
  • Kept the page backed by the existing admin-only account API from this PR.
  • Prevented duplicate usernames from silently replacing an existing account.
  • Updated the auth template route calls to the current Starlette request-first TemplateResponse form; the admin page test exposed that issue.

Verification:

  • pytest tests/test_web_auth_hardening.py -q -p no:cacheprovider
  • non-writing compile check for accounts.py and auth_routes.py
  • git diff --check

Note: Node is not installed in this environment, so I could not run a separate JS syntax check. The admin route/template access path is covered by FastAPI TestClient.

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.

2 participants