fix(credentials): reflect workspace permission in credential member role#4699
fix(credentials): reflect workspace permission in credential member role#4699minijeong-log wants to merge 11 commits into
Conversation
Workspace admin users were incorrectly assigned 'member' role on credential_member when workspace-scoped secrets were created or synced. Only the workspace owner got 'admin'. Now workspace permissions table is consulted: owner/admin → credential admin, write/read → member. - environment.ts: query workspace permissions in ensureWorkspaceCredentialMemberships - route.ts POST: apply same mapping during credential creation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview This updates the credential creation flow in Reviewed by Cursor Bugbot for commit 573ebd6. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR fixes workspace admin users being incorrectly assigned
Confidence Score: 3/5The fix is correct on the two paths it touches but leaves a third membership-insertion path ( Two of the three places that write apps/sim/lib/credentials/environment.ts — the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Workspace credential created or synced] --> B{Type: env_workspace or service_account?}
B -- No --> C[Insert single credentialMember as admin for creator]
B -- Yes --> D[Fetch workspace member IDs + workspace permissions]
D --> E[For each member user]
E --> F{Is owner OR creator OR wsPermission === 'admin'?}
F -- Yes --> G[role = 'admin']
F -- No --> H[role = 'member']
G --> I[Insert/Update credentialMember row]
H --> I
subgraph "createWorkspaceEnvCredentials (NOT updated)"
J[Fetch workspace member IDs ONLY] --> K[For each member user]
K --> L{Is owner?}
L -- Yes --> M[role = 'admin']
L -- No --> N[role = 'member — workspace admins get wrong role']
end
|
…ntials Address Bugbot review: the parallel credential creation path (createWorkspaceEnvCredentials) still used owner-only admin logic. Now queries workspace permissions table for consistent role mapping.
Address Bugbot review: permissions query was executed N times (once per credential) inside ensureWorkspaceCredentialMemberships loop. Now queried once in the caller and passed as a Map parameter.
Derive memberUserIds from wsPermissionRows + workspace owner instead of calling getWorkspaceMemberUserIds separately. This removes a duplicate query on the permissions table at every call site.
…ency The credential creator (session.user.id) was always granted admin role regardless of their workspace permission. This created inconsistency with environment.ts sync logic which correctly derives role solely from workspace permission. Now both paths use the same mapping.
All callers now derive member IDs from workspace permission rows directly, making this function dead code.
Adopt upstream's onConflictDoUpdate pattern for ensureWorkspaceCredentialMemberships while preserving our permission-based role mapping fix.
Write-only users could create secrets but got 'member' role, making them unable to edit/delete their own secrets. Now credential creation requires workspace admin permission, consistent with the role mapping.
Revert admin-only restriction — write users can create secrets. Ensure the acting user (creator) always gets admin role on the credential via actingUserId parameter in ensureWorkspaceCredentialMemberships and session.user.id check in route.ts POST. Role mapping: - workspace owner → admin - credential creator (actingUserId/session.user.id) → admin - workspace admin permission → admin - write/read → member
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 305e02c. Configure here.
…emberships actingUserId is not always the credential creator — sync is called from member addition, permission changes, and invitation acceptance. Creator admin is only applied in route.ts POST (direct creation). Sync paths use pure workspace permission mapping.

Closes #4698
Summary
Workspace admin users were incorrectly assigned
memberrole oncredential_memberwhen workspace-scoped secrets were created or synced. Only the workspace owner gotadmin. Now the workspacepermissionstable is consulted to determine the correct credential role.Mapping
workspace.ownerId)Changes
environment.ts: Query workspace permissions inensureWorkspaceCredentialMembershipsand mapadminpermission → credentialadminroleroute.tsPOST: Apply same mapping during credential creationTest Plan
credential_memberroles match the mapping above