mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-13 16:14:10 +00:00
fix(pat): close restricted-token paths through workflows, chat, schedules and conversations
A resource restriction was checked on ids in the request, not on what the addressed row pulls in or belongs to. Closed: - Workflow writes for tokens restricted on sources, tools or prompts (a graph names those inside its nodes), and attaching a workflow to an agent unless the token is restricted on workflows too. - Chat for tools-restricted tokens (chat executes tools; rejected at token creation as well), and agent-less chat for tokens restricted on prompts or workflows. - conversation_id on chat: it must belong to the agent being run, or to no agent for agent-less chat. Otherwise the server continued, appended to, or resumed pending tool calls of another agent's conversation. - Schedules for tokens restricted on anything but agents; schedule-id routes for every restricted token. - Conversations and analytics for every restricted token, not only agent-restricted ones. Also: create, first publish and adopt return the agent API key masked to a token without agents:keys; token ids must be canonical UUIDs (urn:uuid: gave a 500); an expired token is reported as expired; token creation takes a per-user advisory lock so the cap cannot be raced; admin revoke-sessions writes a pat_revoked event per token. The UI drops a row whose revoke returns 404 and does not offer a tools restriction next to chat:run.
This commit is contained in:
1 parent
b1ff8f516e
commit
94b5924e36
15 files changed
+393
-64
No files matched your search
@@ -178,13 +178,20 @@ class TestUserLifecycle:
|
||||
|
||||
def test_force_logout(self, client):
|
||||
events = Mock()
|
||||
with _admin(AuthEventsRepository=Mock(return_value=events)), patch(
|
||||
"docsgpt.api.admin.routes.denylist"
|
||||
) as dl:
|
||||
tokens = Mock()
|
||||
tokens.revoke_all_for_user.return_value = ["t1", "t2"]
|
||||
with _admin(
|
||||
AuthEventsRepository=Mock(return_value=events),
|
||||
PersonalAccessTokensRepository=Mock(return_value=tokens),
|
||||
), patch("docsgpt.api.admin.routes.denylist") as dl:
|
||||
dl.deny_user.return_value = True
|
||||
resp = client.post("/api/admin/users/bob/revoke-sessions")
|
||||
assert resp.status_code == 200
|
||||
dl.deny_user.assert_called_once_with("bob")
|
||||
# A forced logout also revokes the user's API tokens, one audit event each.
|
||||
tokens.revoke_all_for_user.assert_called_once_with("bob", reason="admin_sessions_revoked")
|
||||
recorded = [call.args[1] for call in events.insert.call_args_list]
|
||||
assert recorded == ["pat_revoked", "pat_revoked", "admin_sessions_revoked"]
|
||||
|
||||
def test_user_detail(self, client):
|
||||
users = Mock()
|
||||
|
||||
Reference in new issue
Block a user