fix: make chat model sharing work for sharers without directory access - #28703
Merged
Conversation
#28542) This is a bug fix. Chat model sharing UAT (main @ 3c32408) found two bugs when a delegated "Model Sharer" role holds only `chat_model_config:read` + `chat_model_config:share`: This state is reachable entirely through the UI in a normal least-privilege setup: 1. An org admin restricts **Organization Settings → Workspace Sharing** to `none` or `service_accounts`. 2. Under **Organization → Roles**, they create a custom role with only the advanced permissions `chat_model_config:read` and `chat_model_config:share`. 3. Under **Organization → Members**, they assign that role to the person responsible for managing model access. 4. An admin creates a chat model and may initially share it with a group. 5. The delegated sharer signs in, opens **AI Settings → Models → [model] → Share model**, where the failures below occur. - **UAT-05 / UAT-08:** with workspace sharing set to `none`, the sharing dialog errored out entirely ("Resource not found or you do not have access to this resource"). The sharer couldn't view, add, or even remove grants. - **UAT-04:** with workspace sharing set to `service_accounts`, existing group grants rendered as raw UUIDs, and groups didn't appear in the add-principal search. Both have the same cause. The ACL GET returned bare UUID→role maps, so to display names (and to power its add-principal search) the dialog called the generic org directory APIs: list organization members and list groups. Those APIs require `organization_member:read` and `group:read`, which the sharer role doesn't have. Ordinary members only get them as a side effect of a *different* feature: `OrgMemberPermissions` grants member read when the org's workspace sharing mode isn't `none` (so users can pick coworkers to share a workspace with), and group read only when it's `everyone`. The chat dialog was silently borrowing those workspace-sharing permissions, so it only worked when that unrelated org setting happened to grant them: - `none`: no member read → dbauthz rejects the member listing → the dialog's query chain 404s and everything blanks (UAT-05/08). - `service_accounts`: member read but no group read → the group listing silently filters to empty → group grants can't be resolved past their UUIDs (UAT-04). In short: an org setting about who can share workspaces was deciding whether a delegated sharer could manage a chat model ACL. Stop borrowing directory permissions entirely; authorize everything through the model's own share permission, using the two patterns the repo already has for ACL editors: - **Hydrate the ACL GET** to return resolved users and groups instead of UUID maps, like `workspaceACL` and the per-chat ACL already do. Fixes the raw UUIDs. - **Add `GET .../acl/available`** returning assignable org members and groups for the autocomplete, modeled directly on `templateAvailablePermissions` (same query semantics, same share-gate-then-system-context lookup that every sibling ACL endpoint uses). Fixes candidate discovery. The new endpoint exists only because the dialog has no permission-safe way to enumerate principals today; it is plumbing for the fix, not a new feature. This is exactly how template sharing already solves the same problem: `templateACL` returns hydrated principals, and `templateAvailablePermissions` gates on the template then does the lookups under a system context because, per its own comment, "the caller might not have permission to read all users". We differ from the template version only where newer conventions exist: | | Template | This PR | |---|---|---| | Gate | `ActionUpdate` on the template (predates `share`) | `ActionShare` on the model, matching the workspace/chat/MCP ACL endpoints | | User candidates | Site-wide `GetUsers` | Non-system members of the model's org only | | Group hydration | Full member rosters | Member counts, batched in one query | The dialog now runs off the hydrated ACL plus the new endpoint, so all three sharing modes take the same code path, and a discovery failure no longer blanks existing grants. `OrgMemberPermissions`, the directory APIs, and the PATCH (still a sparse UUID→role delta) are untouched. +1274/−191, but only about a third is product code: - **Product (~450):** the two endpoints and hydration helpers (`exp_chats_model_acl.go`, ~240), the dialog rework plus a new colocated autocomplete component (~200), and SDK/site API plumbing (~60). - **Tests (~625):** backend tests updated to hydrated shapes plus new tests that reproduce the two failing UAT sharing modes end-to-end (+418), rewritten and new story play tests (+198), and query/mock updates. - **Generated (~200):** swagger, apidocs, `typesGenerated.ts`, API reference docs. Depends on #28498 (stacked on the `/api/v2` chat API promotion; the new endpoint is registered under both prefixes like its siblings). --------- Co-authored-by: Michael Suchacz <[email protected]> (cherry picked from commit d0e2234)
Contributor
Author
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
ethanndickson
approved these changes
Aug 27, 2026
mtojek
approved these changes
Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #28542
Original PR: #28542 — fix: make chat model sharing work for sharers without directory access
Merge commit: d0e2234
Requested by: @ethanndickson