Skip to content

fix(auth): allow API keys to manage workspace tables#2762

Open
mcm wants to merge 1 commit into
TracecatHQ:mainfrom
mcm:mcm/tables-actor-role
Open

fix(auth): allow API keys to manage workspace tables#2762
mcm wants to merge 1 commit into
TracecatHQ:mainfrom
mcm:mcm/tables-actor-role

Conversation

@mcm
Copy link
Copy Markdown
Contributor

@mcm mcm commented May 23, 2026

Problem

Every endpoint in tracecat/tables/router.py was declared with WorkspaceUserRouteRole, which sets allow_api_key=False. Service-account API keys were therefore rejected with 403 before the per-endpoint require_scope(...) check ever ran, regardless of which table:* scopes the key actually held.

On top of that — and what makes this PR broader than the recent siblings — the table:* scopes were never added to the service-account assignable allowlist (WORKSPACE_SERVICE_ACCOUNT_ASSIGNABLE_SCOPES). So even after flipping the dependency, admins couldn't actually grant table access to an API key. This PR opens both halves.

Changes

  • tracecat/tables/router.py — swap WorkspaceUserRouteRoleWorkspaceActorRouteRole on all 18 endpoints (and the import). Actor is a superset of User, so user-session callers see no behavior change.
  • tracecat/service_accounts/constants.py — add table:read, table:create, table:update, table:delete to WORKSPACE_SERVICE_ACCOUNT_ASSIGNABLE_SCOPES. ORG_SERVICE_ACCOUNT_ASSIGNABLE_SCOPES picks them up via union, no separate edit. The scopes themselves are already defined in tracecat/authz/scopes.py (present in the VIEWER / EDITOR / ADMIN preset sets).
  • tests/unit/test_service_accounts_validation.pytable:read and table:create move from the workspace "rejects user-only" parametrize list into the "allows supported API-key" list, alongside the new table:update / table:delete. Same shuffle on the org-variant lists.

Compatibility

  • User sessions: unchanged. Actor accepts User callers the same as User does.
  • Existing service accounts: unchanged. The new scopes are merely assignable — no key is automatically granted table:*. Admins must explicitly grant them, same as any other scope.
  • Migrations: none required.

Precedent

Follows the same route-role-swap pattern as #2759 (workspace variables and case attachments). This one is the broadest of the recent series because it adds entirely new entries to the service-account assignable allowlist, rather than just flipping a dependency on routes whose scopes were already assignable.

Test plan

  • ruff check clean on changed files
  • ruff format --diff clean on changed files
  • basedpyright --warnings reports 0 errors / 0 warnings on changed files
  • CI test suite (pytest requires the full docker stack; deferred to CI)

Summary by cubic

Allow service-account API keys to manage workspace tables by enabling API-key access on tables routes and making table:* scopes assignable. User sessions are unchanged; admins can now grant table:read|create|update|delete to service accounts.

  • Bug Fixes
    • Swapped WorkspaceUserRouteRoleWorkspaceActorRouteRole on all /tables endpoints so API keys aren’t rejected before scope checks.
    • Added table:read, table:create, table:update, table:delete to WORKSPACE_SERVICE_ACCOUNT_ASSIGNABLE_SCOPES (org allowlist picks them up via union).
    • Updated scope-assignability tests to reflect the new table scopes.

Written for commit 33a2653. Summary will update on new commits. Review in cubic

/tables/* routes were declared with WorkspaceUserRouteRole, which sets
allow_api_key=False — service accounts were 403'd before scope checks
ran. The table:* scopes weren't in the service-account assignable
allowlist either, so this opens both halves.

- Swap WorkspaceUserRouteRole -> WorkspaceActorRouteRole on all table
  endpoints
- Add table:{read,create,update,delete} to
  WORKSPACE_SERVICE_ACCOUNT_ASSIGNABLE_SCOPES
- Update parametrized assignability tests to match

Follows the pattern in TracecatHQ#2759.
@zeropath-ai
Copy link
Copy Markdown

zeropath-ai Bot commented May 23, 2026

No security or compliance issues detected. Reviewed everything up to 33a2653.

Security Overview
Detected Code Changes
Change Type Relevant files
Configuration changes ► tests/unit/test_service_accounts_validation.py
    Add table scopes to test data
► tracecat/service_accounts/constants.py
    Add table scopes to constants
Refactor ► tracecat/tables/router.py
    Replace WorkspaceUserRouteRole with WorkspaceActorRouteRole

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 3 files

Confidence score: 5/5

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

Re-trigger cubic

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.

1 participant