Skip to content

fix(auth): treat superusers as tenant users#2611

Merged
daryllimyt merged 3 commits intomainfrom
feat/superuser-as-regular-user
May 5, 2026
Merged

fix(auth): treat superusers as tenant users#2611
daryllimyt merged 3 commits intomainfrom
feat/superuser-as-regular-user

Conversation

@daryllimyt
Copy link
Copy Markdown
Contributor

@daryllimyt daryllimyt commented May 5, 2026

Summary

  • Treat User.is_superuser as platform-admin eligibility instead of implicit tenant-context privilege.
  • Resolve superuser tenant access through normal org/workspace membership and RBAC paths across HTTP auth, MCP, OIDC, SAML, and invitation flows.
  • Keep explicit superadmin routes on SuperuserRole, and prevent AuthenticatedUserOnly from activating platform privileges.
  • Update frontend post-auth routing so superusers land in the workspace app when they have tenant memberships, with /admin as the fallback when they have no org access.

Validation

  • uv run pytest tests/unit/test_admin_org_invitations_service.py tests/unit/test_auth_middleware.py tests/unit/test_mcp_auth.py tests/unit/test_mcp_oidc_session.py tests/unit/test_organization_membership.py tests/unit/test_organization_service.py tests/unit/test_saml_client_config.py -q
  • uv run pytest tests/unit/api/test_api_users_router.py -q
  • uv run ruff check <changed Python files>
  • uv run ruff format --check tracecat/auth/credentials.py tests/unit/test_auth_middleware.py
  • uv run basedpyright <changed Python files>
  • pnpm -C frontend test -- src/lib/auth-redirect.test.ts tests/auth-ui-matrix.test.tsx --runInBand
  • pnpm -C frontend exec biome check src/app/workspaces/layout.tsx src/lib/auth-redirect.ts src/lib/auth-redirect.test.ts tests/auth-ui-matrix.test.tsx
  • pnpm -C frontend run typecheck

Pre-commit also ran during commit and passed after regenerating the frontend client.


Summary by cubic

Treat superusers as tenant users: platform admin is opt-in and tenant access comes only from org/workspace membership and RBAC. Frontend keeps superusers on normal routes; only redirect to /admin when they have no org memberships.

  • Refactors

    • Unify tenant auth paths: remove superuser-only tenant shortcuts across HTTP auth, MCP, OIDC, and SAML; all tenant access resolves via memberships and scopes.
    • Redefine Role.is_platform_superuser to mean explicit platform-admin execution; authenticated_user_only no longer enables it; scope computation updated.
    • MCP: resolve_role, list_user_workspaces, and org-role resolution use memberships/RBAC; superusers no longer bypass checks; issued tokens set is_platform_superuser=false.
    • OIDC (MCP): session resolution derives org from the user’s memberships; API updated to resolve_authorize_session(user); tokens no longer carry platform-superuser execution.
    • Invitations: allow inviting and accepting superuser accounts as regular members; remove multi-tenant blocks in org services.
    • SAML: drop automatic org access for superusers; allow only via membership, pending invite, or first superadmin bootstrap.
    • Org deletion: restricted to org owners/admins through tenant RBAC.
    • Tests: make the registry integration auth setup deterministic by seeding a membership and owner role, hashing the test password, and setting the org cookie.
  • Frontend

    • Post-auth redirect: remove superuser special-casing; honor returnUrl; use /admin only when a superuser has no org memberships.
    • Workspace layout: detect “no memberships”; redirect superusers to /admin; regular users see the help screen. Updated tests and generated client docs.

Written for commit 6d3557d. Summary will update on new commits.

@daryllimyt daryllimyt temporarily deployed to internal-registry-ci May 5, 2026 04:40 — with GitHub Actions Inactive
@daryllimyt daryllimyt had a problem deploying to internal-registry-ci May 5, 2026 04:40 — with GitHub Actions Failure
@blacksmith-sh

This comment has been minimized.

@zeropath-ai
Copy link
Copy Markdown

zeropath-ai Bot commented May 5, 2026

No security or compliance issues detected. Reviewed everything up to 6d3557d.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► frontend/src/app/workspaces/layout.tsx
    Handle users with no organization memberships
    Redirect superusers with no org memberships to admin route
Refactor ► frontend/src/client/services.gen.ts
    Update documentation for organization delete restriction
Enhancement ► frontend/src/lib/auth-redirect.test.ts
    Update tests for multi-tenant superuser redirect logic
Refactor ► frontend/src/lib/auth-redirect.ts
    Remove redirect logic for multi-tenant superusers
Refactor ► frontend/tests/auth-ui-matrix.test.tsx
    Mock useParams and usePathname
    Add mock for ApiError with body property
    Add mock for getNoOrgMembershipsError function
    Mock useWorkspaceManager hook
    Update tests to reflect changes in superuser redirect logic
    Add test for superusers with no organization memberships
Refactor ► packages/tracecat-admin/tracecat_admin/services/bootstrap.py
    Update docstring for create_dev_user function
Bug Fix ► packages/tracecat-ee/tracecat_ee/admin/organizations/service.py
    Remove restriction preventing invitations to existing superusers
Enhancement ► tests/integration/test_install_and_run_custom_remote_registry_flow.py
    Ensure test user has platform and tenant access before running tests
    Set organization context using cookies for org-scoped endpoints
Enhancement ► tests/unit/test_admin_org_invitations_service.py
    Allow superusers to be invited as regular organization members
Enhancement ► tests/unit/test_auth_middleware.py
    Add test for authenticated_user_only decorator not activating superuser privileges
    Update test for role dependency with multi-tenant superuser to resolve regular org user context
    Update test for role dependency with superuser to resolve workspace membership without platform scopes
Enhancement ► tests/unit/test_mcp_auth.py
    Update tests for superuser role resolution to use RBAC for workspace access
    Update tests for listing user workspaces to use membership rows for superusers
    Update tests for resolving org role token to use membership org for superusers
Enhancement ► tests/unit/test_mcp_oidc_session.py
    Allow superuser to resolve authorize session using membership org
    Error when superuser has no organization membership during authorize session
Enhancement ► tests/unit/test_organization_membership.py
    Update test for superuser role to indicate tenant roles do not inherit platform superuser privileges
Enhancement ► tests/unit/test_organization_service.py
    Allow superuser accounts to be invited as regular organization members
    Allow superuser accounts to accept organization invitations as users
Enhancement ► tests/unit/test_saml_client_config.py
    Adjust test for SAML bootstrap allowance based on multi-tenancy
Refactor ► tracecat/auth/credentials.py
    Remove is_unprivileged function

@daryllimyt daryllimyt marked this pull request as ready for review May 5, 2026 05:27
@daryllimyt daryllimyt requested a review from jordan-umusu May 5, 2026 05:27
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci May 5, 2026 05:31 — with GitHub Actions Inactive
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 23 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@daryllimyt daryllimyt had a problem deploying to internal-registry-ci May 5, 2026 05:31 — with GitHub Actions Failure
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci May 5, 2026 05:45 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci May 5, 2026 05:46 — with GitHub Actions Inactive
@daryllimyt daryllimyt merged commit a30ecb0 into main May 5, 2026
19 checks passed
@daryllimyt daryllimyt deleted the feat/superuser-as-regular-user branch May 5, 2026 13:24
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