feat(gateway): per-user tool restrictions (RBAC) via user_roles config#3995
Open
Mibayy wants to merge 2 commits into
Open
feat(gateway): per-user tool restrictions (RBAC) via user_roles config#3995Mibayy wants to merge 2 commits into
Mibayy wants to merge 2 commits into
Conversation
|
I want this for WhatsApp too. |
|
Hi, any status updates? |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #3897
Problem
All authorized gateway users get identical access to every enabled tool, including
terminalandexecute_code. Prompt-based restrictions are unreliable — the LLM can ignore them.Solution
Code-level per-user tool filtering, configured in
config.yamlundergateway.user_roles. The filter runs in_run_agentbefore theAIAgentis created, so restricted toolsets are never registered with the model in the first place.Config example
Precedence:
allowed_tools(allowlist, supportsfnmatchwildcards likemcp__*): takes full precedence. Special valueallskips filtering.blocked_tools(denylist): applied whenallowed_toolsis absent.defaultentry matches any user not explicitly listed.Changes
gateway/config.pyUserRoledataclass withrole,allowed_tools,blocked_toolsUserRole.apply(toolsets)— pure filter function usingfnmatchGatewayConfig.user_roles: Dict[str, UserRole]fieldGatewayConfig.get_user_role(user_id)— lookup withdefaultfallbackfrom_dict/to_dictsupportgateway/run.py_run_agent, afterenabled_toolsetsis resolved, callget_user_role(source.user_id).apply(enabled_toolsets)What this is NOT
This is not authentication (covered by
TELEGRAM_ALLOWED_USERSetc.) — it's a second layer that controls what tools an already-authenticated user can invoke. It operates at toolset granularity (same keys asplatform_toolsetsin config). Fine-grained per-tool filtering within a toolset can be added later if needed.