CXH-2390: fix org-level role grants in baton-slack-enterprise #40
All Vouch review confidence checks passed
Residual risk 0.35 = Change Risk (0.59) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #40"
general
weight: 0.35
c1-squire-dev[bot]
Connectors could never grant Enterprise Grid organization-level roles: any provisioning of
organization_adminororganization_ownerfailed immediately with Slack'sinvalid_argumentserror, because the connector sent those role names to a Slack endpoint that only accepts the 15 granular system role IDs. Two production occurrences are confirmed in Datadog (tenant action IDs3Ijrm2kqVKkxhfJb3jB7kHmaK0pand3IiyNvynQnoXspiOqaiyTe7mQak, teamE0B87GJMZJP, both fatal). This PR routes organization-level roles through the org-level Slack API —admin.users.setAdmin/admin.users.setOwner/admin.users.setRegular, which Slack documents as acting at workspace or organization level depending on which ID you pass — and leaves every granular role on the path it already used.Context
Linear: CXH-2390
The write path (
enterpriseRoleType.Grant()/Revoke()) treated all 18 enterprise roles identically and POSTed every one toadmin.roles.addAssignments/admin.roles.removeAssignmentswithrole_id: organization_admin(or its siblings). Slack's docs for that endpoint accept only granularRl0Xrole IDs fromadmin.roles.list; the org-level names fail top-level parameter validation — the emptyrejected_users/rejected_entitiesin the prod error confirm Slack rejected the request before evaluating any user or team. The read path already treated these three roles as a special case (they are derived from each user'sIsAdmin/IsOwner/IsPrimaryOwnerflags), but the write path never got the matching branch.What changed
pkg/connector/enterprise_roles.go(~L267-340)Where:
Grant(),Revoke(), and the neworgRoleToWorkspaceRolehelper.What changed
main).organization_admin/organization_ownerfirst reads the user's current standing: if the user already holds the role (an organization owner counts as holding admin too, since the sync emits both grants for owners), the grant completes asGrantAlreadyExistswithout any write — Slack'ssetAdminwould otherwise demote an owner to plain admin. Otherwise the grant callsSetWorkspaceRole(ctx, orgID, userToSet, "admin"/"owner"), routing toadmin.users.setAdmin/admin.users.setOwnerwithteam_idset to the enterprise ID the builder already carried but never read. Nousers.infocall is needed to resolve a team anymore (the old path resolved the user's home team only to feed the granular endpoint).organization_ownerdemotes the user to organization admin viaadmin.users.setAdminwith the org ID — it revokes only the owner role, not the admin role that org owners also carry. Revokingorganization_adminfirst checks the user's current ownership: if the user still holds the owner role, the revoke is refused with a clear "revoke the owner role first" error (revoking both at once would silently strip ownership an access review did not ask for); otherwise the user is demoted viaadmin.users.setRegular. Neither path ever touchesadmin.roles.removeAssignmentswith an org role name.organization_primary_ownerreturns aPermissionDeniederror explaining Slack does not allow modifying the primary owner via the API, before any HTTP call.InvalidArgument(mirroring the guard the granular client method already has) — it never falls through to the granular path with an org role name.already_admin/already_ownermap toGrantAlreadyExists; on the revoke path each arm maps its own already-downgraded signal (already_adminon the owner-revoke arm,already_regularon the admin-revoke arm) toGrantAlreadyRevoked. Slack'sinvalid_role_for_useris deliberately NOT treated as success — Slack documents it as a refusal of the demotion, so it surfaces as a real error rather than silently reporting a revoke that did not happen. Unmatched errors fail closed with the connector-prefixed wrapped error and gRPC code.pkg/connector/enterprise_roles_guard_test.go(new file)Where: whole file; test functions
TestEnterpriseRoleGrant_OrgRolesUseOrgLevelAPI,TestEnterpriseRoleRevoke_OrgRolesDowngradeToRegular,TestEnterpriseRole_PrimaryOwnerRefusedBeforeHTTP,TestEnterpriseRoleGrant_GranularRolesUnchanged, idempotency and guard-order tests, and the classification tripwire.Why
setAdmin/setOwnerwith the enterprise ID, the owner revoke hitssetAdmin, the admin revoke hitssetRegular(after the ownership check) and is refused while the user still owns, the primary owner produces zero HTTP requests, and granular roles still reachadmin.roles.addAssignmentswith theirRl…role ID and the user's home team.invalid_arguments.How far this is verified
./pkg/connectorpass (scripts/validate-changes.sh) at every pushed head; the new guard tests pass fresh, including with-race.clean— a full sync of this branch was replayed against a Slack API mock built from Slack's official docs and produced exactly the same objects (0 lost / 0 gained resources, entitlements, grants) as currentmain, with no new static findings. (A mock proves the connector walks the documented API, not that Slack behaves; the provisioning arms are covered by the guard tests and a mock-backed end-to-end probe, not by a sync recording.)cmd/baton-slack-enterpriseand ran it (--help) successfully; it exercised no sync because the repo declares no smoke mock.840f114); two later review passes on the resolved bot threads kept it clean.b2c3d642d), after three fix passes during review: the bot caught that revoking one org role stripped both roles (revokes are now per-arm — owner revoke demotes to admin only), that revokingorganization_ownerfrom a non-owner would have promoted the user (an ownership precheck now returnsGrantAlreadyRevokedwith no write), and a compile error one of those fixes briefly introduced. All five bot threads are replied and resolved.invalid_role_for_userwas being treated as "already revoked" when Slack documents it as a refusal (now fails closed), and granting an org role to a current owner would have demoted them (now an idempotentGrantAlreadyExistsno-op) — both fixed; round 2 verified those fixes and raised 2 minor ones (a stale comment that could mislead a future maintainer, and a fail-open helper default) — both fixed. Every deep-review thread is replied and resolved.main.invalid_role_for_userIS documented (a refusal) and deliberately produces a real error.Risk — what to look at hardest
SetWorkspaceRole) with the enterprise ID in theteam_idfield. That three-string argument order is the highest-risk swap site, and the guard tests pin the exact form parameters to catch a transposition.users.inforead to check ownership before demoting; that lookup failing fails the revoke closed rather than guessing.Release Notes
Granting or revoking the Enterprise Grid Organization Admin and Organization Owner roles through the connector now works: those requests go to Slack's org-level admin API instead of an endpoint that rejected them with
invalid_arguments. Revoking Organization Owner demotes the user to organization admin; revoking Organization Admin demotes the user to a regular member — and is refused with a clear error while the user still holds the owner role, so an access review can no longer silently strip ownership it did not ask to revoke. The Organization Primary Owner role remains read-only — attempts to grant or revoke it return a clear error, since Slack's API does not allow modifying the primary owner.