feat(auth): replace JWT-as-API-key with hashed PATs + per-space API access gate#1524
Conversation
- Removed the Alert component and its related imports to streamline the error display. - Adjusted the layout of the error screen for better responsiveness and visual clarity. - Updated button styles and structure for improved user interaction.
…ser with auth context across routes
…napshot functions
…pace snapshot functions
…ontext instead of user variable
|
@AnishSarkar22 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Description
api_access_enabledtoggle +API_ACCESS_MANAGEpermission; PATs gated at the RBAC chokepoint (sessions bypass).AuthContext(session or PAT); retire fail-opencurrent_active_user.AuthContext.allow_any_principal) for spaceless probes (/verify-token,/obsidian/health,GET /searchspaces).Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist
High-level PR Summary
This PR replaces short-lived JWT tokens with personal access tokens (PATs) for programmatic API access. The implementation introduces a fail-closed authorization model where PATs are scoped to search spaces with an
api_access_enabledtoggle, ensuring that API access requires explicit opt-in per workspace. The backend adds a newAuthContextabstraction that unifies session-based and PAT-based authentication, replaces allcurrent_active_userdependencies withget_auth_context, and implements RBAC gates that enforce the API access policy. The frontend now features a PAT management UI in user settings, updates the Obsidian connector flow to create tokens on demand, and adds search-space-level API access controls. Migration 166 creates thepersonal_access_tokenstable and adds theapi_access_enabledcolumn to search spaces, with existing spaces defaulting to enabled for backward compatibility.⏱️ Estimated Review Time: 3+ hours
💡 Review Order Suggestion
surfsense_backend/.env.examplesurfsense_backend/app/config/__init__.pysurfsense_backend/app/db.pysurfsense_backend/alembic/versions/166_add_pat_and_api_access.pysurfsense_backend/app/auth/__init__.pysurfsense_backend/app/auth/context.pysurfsense_backend/app/utils/pat.pysurfsense_backend/app/users.pysurfsense_backend/app/schemas/pat.pysurfsense_backend/app/routes/personal_access_tokens_routes.pysurfsense_backend/app/routes/__init__.pysurfsense_backend/app/utils/rbac.pysurfsense_backend/app/routes/search_spaces_routes.pysurfsense_backend/app/schemas/__init__.pysurfsense_backend/app/schemas/search_space.pysurfsense_backend/app/app.pysurfsense_backend/app/routes/obsidian_plugin_routes.pysurfsense_backend/app/automations/services/automation.pysurfsense_backend/app/automations/services/run.pysurfsense_backend/app/automations/services/trigger.pysurfsense_backend/app/agents/chat/multi_agent_chat/main_agent/runtime/factory.pysurfsense_backend/app/agents/chat/multi_agent_chat/main_agent/tools/automation/create.pysurfsense_backend/app/agents/chat/multi_agent_chat/main_agent/tools/registry.pysurfsense_backend/app/automations/actions/builtin/agent_task/invoke.pysurfsense_backend/app/tasks/chat/streaming/agent/builder.pysurfsense_backend/app/tasks/chat/streaming/flows/new_chat/orchestrator.pysurfsense_backend/app/tasks/chat/streaming/flows/resume_chat/orchestrator.pysurfsense_backend/app/gateway/agent_invoke.pysurfsense_backend/app/gateway/auth_invariant.pysurfsense_backend/app/services/chat_comments_service.pysurfsense_backend/app/services/public_chat_service.pysurfsense_backend/tests/integration/test_pat_fail_closed_authz.pysurfsense_backend/tests/unit/test_pat_fail_closed_static.pysurfsense_web/contracts/types/pat.types.tssurfsense_web/lib/apis/pats-api.service.tssurfsense_web/hooks/use-pats.tssurfsense_web/app/dashboard/[search_space_id]/user-settings/components/ApiKeyContent.tsxsurfsense_web/components/assistant-ui/connector-popup/connect-forms/components/obsidian-connect-form.tsxsurfsense_web/components/settings/general-settings-manager.tsxsurfsense_web/contracts/types/search-space.types.tssurfsense_web/lib/apis/search-spaces-api.service.tssurfsense_web/atoms/search-spaces/search-space-mutation.atoms.ts