feat: gate access behind a Flow User role - #92
Open
KushX wants to merge 2 commits into
Open
Conversation
Flow had no access control. Any logged-in user could drive the assistant through the whitelisted API. Website users included. Add a Flow User role and enforce it on all seven endpoints. Grant it per user from User > Roles. - flow/permissions.py holds the role and the gate - boot exports flow_enabled so the panel skips mounting for others - doctype permissions move from All to Flow User - a patch grants the role to existing System Managers so current users keep access Each grant in the patch is isolated in a savepoint. Another app's user validation cannot abort the migration. Triggers stay ungated. They run as run_as or owner, who need not hold the role.
Contributor
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (2): Last reviewed commit: "fix: sweep every endpoint and make role ..." | Re-trigger Greptile |
The gate sweep listed six of the seven endpoints. attach_file was missing, so a regression there would not have failed the suite. The call map is now asserted against flow.api.__all__ first. A newly exported endpoint fails the test until it is covered. Role creation checked existence, then inserted. Two lifecycle hooks racing could both pass that check. The insert now ignores duplicates, so the insert itself is the safe operation.
Open
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.
Problem
Flow has no access control. Any logged-in user can drive the assistant.
Flow AgentandFlow Modelgrant read toAll.Flow SessionandFlow Rundo the same. None of the seven whitelisted endpoints check a role.This includes website users. They cannot open the desk, but they can still call
/api/method/flow.api.start_run.Change
Add a
Flow Userrole. Enforce it on every whitelisted endpoint. Admins grant it per user from User > Roles.Four layers:
Flow User,desk_access = 1. Created inafter_installandafter_migrate. Idempotent.flow/permissions.pyexposesassert_flow_access(). It runs first in all seven endpoints.boot_sessionexportsflow_enabled. The panel skips mounting when false, so there is no Ctrl+I shortcut. This is presentation only.app_include_jsis static per site, so the bundle still ships to everyone.Allrows on the four doctypes becomeFlow User.Notes
Role permissions are OR'd. Adding a role alone changes nothing, so the
Allrows had to go.The gate is the role alone. A System Manager without
Flow Useris refused.Administratorbypassesfrappe.only_forupstream.Triggers are not gated. They run as
run_asor owner, who need not hold the role.flow/lib/session.pyis untouched for that reason. The whitelisted API is the untrusted boundary. A test pins this.Migration
flow/patches/grant_flow_role.pygrants the role to existing enabled System Managers. Without it, every current user loses access on upgrade.Each grant is isolated in a savepoint. Granting a role saves the User doc, which re-runs every installed app's user validation. Those can reject for reasons unrelated to Flow. A rejection rolls back that one user and the sweep continues. Skipped users are printed at the end.
Fresh installs skip the patch.
install_appmarks patches complete without running them.Tests
flow/tests/test_permissions.pyadds 11 cases:run_aslacks the roleTwo existing suites needed a change.
test_ai_apiandtest_flow_agentcreate users that must first clear the doctype read check. Those tests cover session ownership and User Permission, not the role gate. Without the role they would pass for the wrong reason.Full suite run locally: 499 tests, no new failures against the base branch.