Skip to content

RBAC: refuse when the role check can't decide (1.5.1, A) - #278

Merged
antiv merged 2 commits into
mainfrom
ccr-af51431d-ob19a4-rbac
Oct 17, 2026
Merged

antiv merged 2 commits into
mainfrom
ccr-af51431d-ob19a4-rbac

Conversation

@antiv

@antiv antiv commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

What and why

Fix A from #276 (plan item 3 in documents/design/2.0-plan.md).

Before each model call, rbac_before_model_callback compares the caller's roles with the agent's allowed_for_roles. In three cases it let the call through, with only a warning:

  1. no user id in the callback context;
  2. no agent name;
  3. no enabled agents_config row for the agent.

get_root_agent_by_name returns None when its query raises, so case 3 also turned a database error into an allow.

All three now refuse with RBAC_ACCESS_DENIED, as the exception path already did, and the mate.rbac_check span records allowed=false. Two more places change the same way:

  • combined_user_profile_and_rbac_callback. It wraps the check, and it used to log a warning and carry on to the model when the check raised. It now refuses.
  • LangGraph check_rbac. It refuses an agent without a config. Its /run_sse already returns 400 without a user id or app name.

Unchanged:

  • Eval and Playground runs (is_eval_run) and the system agents in _should_skip_rbac_check still skip the check.
  • Disabled agents are refused even while still in a cached tree, which is what disabled means.

Behaviour change, in the CHANGELOG and guide: with MATE_PLUGINS_ENABLED=true (off by default), the check runs for every LLM agent in the app. An agent built in code without an agents_config row is therefore refused now, where it used to be allowed with a warning. Nothing shipped is affected:

  • every hardcoded_agents list is empty;
  • agents with the hardcoded flag have rows.

Also the CHANGELOG entry for #260 (#243, thanks to @sourabh65mehta).

How it was tested

  • shared/test/test_rbac_fail_closed.py:

    • no user id, no agent name, no config (ADK), and no config (LangGraph) are refused;
    • the callback chain refuses when the check raises;
    • system agents and eval runs still pass without a config row.
  • The five refusal tests fail on main and pass here.

  • Full suite: 1543 OK. gen_docs.py --check OK.

  • I checked that the real tree keeps config names: I built a real ADK tree from an in-memory database with a sub-agent under two parents.

    • Both instances are named after the config, so the role check finds the row.
    • The {name}_{parent} instance names come only from build_agent_tree, called only by rbac_agent_factory.py, which nothing imports.
  • An independent security review traced every caller:

    • triggers (trigger_runner), Slack, the widget, the OpenAI API, the MCP bridge and A2A;
    • the help agent, standalone builds, evals and the Playground;
    • agents created by the create_agent tool (the row is committed before the cache reload).

    It found no blocking issue. Its non-blocking points are fixed in the second commit: the wrapper failing open, the guide's wording on code-built agents and on LangGraph, and the two extra tests.

Pre-existing, outside this PR (noted on #276):

  • _should_skip_rbac_check matches by name, so a database agent named system_agent, health_check_agent or mate_fallback_agent skips the check.
  • LangGraph checks only the requested app on each turn, not a sub-agent the conversation resumed in.

Checklist

  • Tests added or updated in shared/test/, and python -m unittest discover -s shared/test -p "test_*.py" passes
  • Schema changes have a migration for all three dialects: no schema change
  • Changed a route, env var, model or the tool registry: none
  • Ran python scripts/gen_docs.py drift --base origin/main. docs/dev/auth-and-access.md is updated. These still hold:
    • docs/dev/agent-runtime.md and docs/dev/langgraph-runtime.md describe where the check runs, not its fallbacks;
    • docs/dev/releases.md is listed only because of CHANGELOG.md.
  • New user-facing feature: none
  • No API keys, tokens or credentials in code, logs or tests

rbac_before_model_callback let a model call through, with a warning, when
the context had no user id or no agent name, or when no enabled
agents_config row was found for the agent. get_root_agent_by_name returns
None on a query error too, so a database error also became an allow. All
three now refuse, as the exception path already did, and the
mate.rbac_check span records allowed=false for them. The LangGraph hook
refuses an agent without a config the same way.

Eval and Playground runs (is_eval_run) and the system agents in
_should_skip_rbac_check still skip the check; agents built in code get no
MATE callbacks.

Also the CHANGELOG entry for #260.
… plugin mode

From the security review of the previous commit:
- combined_user_profile_and_rbac_callback caught an exception from the RBAC
  check, logged a warning and went on to the model. It now refuses.
- With MATE_PLUGINS_ENABLED=true the check runs for every LLM agent in the
  app, so an agent built in code without an agents_config row is now
  refused. The guide and CHANGELOG say so instead of claiming code-built
  agents never reach the check, and the LangGraph line says what its hook
  actually adds.
- Tests: system agents and eval runs still pass without a config row, and
  the chain refuses when the check raises.
@antiv antiv mentioned this pull request Oct 17, 2026
24 tasks done
@antiv
antiv merged commit 8feb4b1 into main Oct 17, 2026
2 checks passed
@antiv
antiv deleted the ccr-af51431d-ob19a4-rbac branch October 17, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants