Repository navigation
feat(studio): allow admin owner scope for project endpoints - #13404
Conversation
Add optional ?owner=<principal> handling on project endpoints so an administrator can manage projects on behalf of another user. Normal callers keep existing behavior. Expose project owner in ChatsProject responses as an additive field.
The owner query parameter is used as the principal that names the user's project folder, so an administrator-supplied value must not be trusted as is. Reject a value that is not a well-formed user id (letters, digits, '-' and '_', at most 36 characters) with 400, and a value that names no user with 404. A caller who is not an administrator still gets 403 first, so the answer does not reveal which users exist. The user check goes through a new WithUserLookup handler option, wired to the auth database in the server. Without it, or without an auth database, no owner is known, so the request fails closed. Assisted-by: Claude:claude-sonnet-5-5 go Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Write one info line per request that uses ?owner= to act on behalf of another user, with the caller, the target owner, the HTTP method and the route pattern. The request body and the project id stay out of the log. Assisted-by: Claude:claude-sonnet-5-5 go Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
The comment on ChatsProject.Owner said the field is set only when an administrator acts for someone else, but the handlers fill it on every response, with the caller's own id by default. A project always has an owner, so drop omitempty: the field is part of the contract and a client can rely on it being there. Assisted-by: Claude:claude-sonnet-5-5 go Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Run one table over the routes that take ?owner=: update, archive, restore, read and write the memory, list the chats, put a chat in a project, pull projects into a chat, and list the agents, connections, triggers and loops. For each, a user who is not an administrator gets 403 for another owner (even an unknown one), an administrator gets 404 for an unknown owner and 400 for a malformed one (a slash, a dot segment, a space, too long), and the owner's own id works. Also check that the administrator reads what the owner wrote and that their own projects stay apart. Assisted-by: Claude:claude-sonnet-5-5 go Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Add the owner query parameter and its 400, 403 and 404 answers to the swagger annotations of the project routes and regenerate the swagger files, and describe the administrator's owner scope, its limits and the audit line in the projects reference. Assisted-by: Claude:claude-sonnet-5-5 go Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
|
Thanks for this, and for the reference implementation in the issue. The design is a good fit for provisioning controllers, and I kept the scope as you wrote it: every project handler goes through I pushed five commits on top of your branch (your commit is untouched) so this can merge as one change. Impersonation is a security surface, so I wanted the hardening in before it lands instead of in a follow-up:
One thing is left on your side: the DCO check is red because your original commit has no A UI for this (picking a user to act as, with a visible banner) is a separate follow-up. |
Move the rule behind ?user_id= (admins only, one "User impersonation" audit line, everyone else gets their own id) from the localai endpoints into the auth package as EffectiveUserID, CanImpersonate and LogImpersonation, so routes outside that package can use the same convention. The unexported localai helpers keep their names and behavior and now call the shared ones. Assisted-by: Claude:claude-sonnet-5-5 go Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
The project routes took ?owner= to let an administrator act on the projects of another user. The rest of the API uses ?user_id= for that, so use the same parameter and the shared auth helpers (CanImpersonate, LogImpersonation), and write the same "User impersonation" audit line. One difference stays on purpose: a caller who is not an administrator and names another user gets 403 here, where the other routes quietly use the caller's own account. A client that creates projects for a user must not create them under the wrong account without noticing. Naming your own id works. The order is unchanged: 403, then 400 for an id that is not well formed, then 404 for an unknown user. The owner field of a project in the answers keeps its name. Assisted-by: Claude:claude-sonnet-5-5 go Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Rename the query parameter in the swagger annotations, regenerate the swagger files, and update the projects reference: the parameter, the 403 for a user who is not an administrator, and the audit line. Assisted-by: Claude:claude-sonnet-5-5 go Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
|
Follow-up on my earlier comment: I renamed the parameter from Reason: LocalAI already has an admin impersonation convention.
The DCO check is still red because of the first commit's missing sign-off (see above). |
|
Thanks! FTR, this will help me finish up my implementation of this crossplane provider... |
Closes #13406.
Add optional
?owner=<principal>handling on the project endpoints so an administrator can manage projects on behalf of another user. Normal callers keep existing behavior; non-admin callers passingownerget 403.ChatsProjectresponses exposeowner(additive).studio_projects_test.go: admin create/list/get/delete on behalf of a user; a non-admin cannot useowner.go test ./core/http/routes -run Projectpasses.