Skip to content

improvement(api-keys): move to workspace level - #1765

Merged
icecrasher321 merged 22 commits into
stagingfrom
fix/workspace-api-keys
Oct 30, 2025
Merged

improvement(api-keys): move to workspace level#1765
icecrasher321 merged 22 commits into
stagingfrom
fix/workspace-api-keys

Conversation

@icecrasher321

@icecrasher321icecrasher321 commented Oct 30, 2025

Copy link
Copy Markdown
Collaborator

Summary

Move API Keys to workspace level. No concept of pinned api key anymore.

The billed account can be selected in the settings modal.

Cleanup unused columns in workflow table isPublished, marketplaceData, collaborators.

Type of Change

  • Other: Platform Improvement

Testing

Tested with different permissions -- different trigger paths.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

waleedlatif1and others added 16 commits October 11, 2025 22:23
* improvement(performance): remove unused source/target indices, add index on snapshot id (#1603)
* fix(blog): rename building to blogs with redirect (#1604)
* improvement(privacy-policy): updated privacy policy for google (#1602)
* updated privacy policy for google
* update terms, privacy, and emails to incl address and update verbiage
* feat(guardrails): added guardrails block/tools and docs (#1605)
* Adding guardrails block
* ack PR comments
* cleanup checkbox in dark mode
* cleanup
* fix supabase tools
* fix(inference-billing): fix inference billing when stream is true via API, add drag-and-drop functionality to deployed chat (#1606)
* fix(inference): fix inference billing when stream is true via API
* add drag-and-drop to deployed chat
* feat(mistal): added mistral as a provider, updated model prices (#1607)
* feat(mistal): added mistral as a provider, updated model prices
* remove the ability for a block to reference its own outluts
* fixed order of responses for guardrails block
* feat(versions): added the ability to rename deployment versions (#1610)
* fix(vulns): fix various vulnerabilities and enhanced code security (#1611)
* fix(vulns): fix SSRF vulnerabilities
* cleanup
* cleanup
* regen docs
* remove unused deps
* fix failing tests
* cleanup
* update deps
* regen bun lock
* fix(debug-mode): remove duplicate debug mode flag (#1714)
* feat(i18n): update translations (#1709)
* improvement(condition): added variable and envvar highlighting for condition input (#1718)
* fix(dashboard): add additional context for paginated logs in dashboard, add empty state when selected cell has no data (#1719)
* fix(dashboard): add additional context for paginated logs in dashboard, add empty state when selected cell has no data
* apps/sim
* renaming
* remove relative import
* feat(tools): added webflow OAuth + tools (#1720)
* feat(tools): added webflow OAuth + tools
* remove itemId from delete item
* remove siteId
* added webhook triggers + oauth scopes + site/collection selector
* update sample payload for webflow triggers
* cleanup
* fix discord color
* feat(i18n): update translations (#1721)
* improvement(schedule): fix UI bug with schedule modal (#1722)
* fix(already-cancelled-sub): UI should allow restoring subscription
* restore functionality fixed
* fix
@vercel

vercelBot commented Oct 30, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentPreviewCommentsUpdated (UTC)
docsSkippedSkippedOct 30, 2025 6:15pm

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This PR migrates API authentication from workflow-level pinned keys to workspace-level billing accounts. The changes remove the concept of pinned API keys entirely and introduce workspace billing settings.

Key architectural changes:

  • Database migration adds workspace.billedAccountUserId (defaults to owner) and workspace.allowPersonalApiKeys (defaults to true)
  • Removes workflow.pinnedApiKeyId, workflow.deployedState, and workflow.collaborators columns
  • API authentication now resolves through workspace context, checking both workspace keys and personal keys (if allowed)
  • Billing attribution for scheduled jobs and webhooks now uses workspace billed account instead of pinned API key owner
  • Workspace API token creation/deletion restricted to billed account user only (previously admin/write)
  • Frontend simplified deployment flow by removing API token selection UI

Workflow execution changes:

  • Schedule execution resolves actor from workspace billed account, falling back to workflow owner
  • Webhook processor uses new resolveWorkflowActorUserId helper to determine billing account
  • Middleware validates tokens based on workspace settings and user permissions

UI improvements:

  • Settings modal adds billed account selector (admins only)
  • API settings adds toggle for allowing personal API tokens
  • Deploy modal simplified to show "Workspace API keys" or "Personal API keys" label instead of selection dropdown

Confidence Score: 5/5

  • This PR is safe to merge with proper testing - clean architectural refactor with comprehensive changes
  • Score reflects thorough implementation across all layers (database, backend, frontend) with proper permission checks, migration handles existing data safely by defaulting billedAccountUserId to owner, and authentication logic properly validates workspace settings and user permissions
  • No files require special attention - all changes follow consistent patterns and include proper validation

Important Files Changed

File Analysis

FilenameScoreOverview
packages/db/migrations/0102_tidy_human_cannonball.sql5/5Migration removes pinned API key concept, adds workspace billing settings (billed_account_user_id defaults to owner, allow_personal_api_keys defaults to true)
packages/db/schema.ts5/5Schema updated to remove workflow.pinnedApiKeyId/deployedState/collaborators, adds workspace.billedAccountUserId and workspace.allowPersonalApiKeys
apps/sim/lib/api-key/service.ts5/5Refactored authenticateApiKeyFromHeader to check workspace settings and validate personal API key permissions for workspace context
apps/sim/background/schedule-execution.ts5/5Changed actor resolution from pinned API key owner to workspace billed account user, falls back to workflow owner
apps/sim/lib/webhooks/processor.ts5/5Added resolveWorkflowActorUserId helper to get billed account from workspace, replaced pinned API key logic
apps/sim/app/api/workflows/middleware.ts5/5Middleware authentication updated to check workspace/personal keys based on workflow context, removed pinned key validation
apps/sim/app/api/workspaces/[id]/route.ts5/5Added PATCH support for updating billedAccountUserId (must be admin) and allowPersonalApiKeys settings
apps/sim/app/api/workspaces/[id]/api-keys/route.ts5/5Workspace API key creation/deletion now restricted to billed account user only (was admin/write previously)

Sequence Diagram

sequenceDiagram
participant User
participant UI as Settings UI
participant API as Workspace API
participant DB as Database
participant Workflow as Workflow Execution
participant Auth as Auth Service
Note over User,DB: Configure Workspace Billing
User->>UI: Select billed account admin
UI->>API: Update workspace settings
API->>DB: Validate admin permissions
API->>DB: Set billedAccountUserId
DB-->>API: Success
API-->>UI: Settings updated
Note over User,Auth: Create Workspace Authentication
User->>UI: Create workspace auth token
UI->>API: Request token creation
API->>DB: Verify user is billed account
alt User is billed account
API->>DB: Create workspace token
DB-->>API: Token created
API-->>UI: Success
else User is not billed account
API-->>UI: Access denied
end
Note over Workflow,Auth: Execute Workflow
Workflow->>Auth: Execute with token
Auth->>DB: Get workspace billing config
DB-->>Auth: Config retrieved
alt Workspace token type
Auth->>DB: Validate workspace token
DB-->>Auth: Token authenticated
else Personal token type
Auth->>DB: Check user permissions
Auth->>DB: Validate personal token
DB-->>Auth: Token authenticated
end
Auth->>DB: Get billedAccountUserId
DB-->>Auth: Billed account retrieved
Auth-->>Workflow: Execute with billing attribution
Loading

29 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@icecrasher321
icecrasher321 merged commit fe9ebbf into stagingOct 30, 2025
9 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/workspace-api-keys branch November 8, 2025 23:28
waleedlatif1 added a commit that referenced this pull request Nov 12, 2025
* fix(billing): should allow restoring subscription (#1728)
* fix(already-cancelled-sub): UI should allow restoring subscription
* restore functionality fixed
* fix
* improvement(api-keys): move to workspace level
* remove migration to prep merge
* remove two more unused cols
* prep staging merge
* add migration back
---------
Co-authored-by: Waleed <walif6@gmail.com>
Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com>
@waleedlatif1waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
Sign up for freeto 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.

3 participants

@icecrasher321@waleedlatif1@Sg312