Repository navigation
Who is signed in, and their memberships with abilities (OFN-4816) - #5299
Merged
Merged
Conversation
…/me (OFN-4816) GET /api/v3/me reads the signed-in person's account (email, names, mfa_enabled and instance role). GET /api/v3/me/memberships pages through their own project_users rows as project-membership resources, each with can_edit_workflows, can_run and can_manage_members, each the answer of one ProjectUsers action on the scope Scope.fetch_all/2 reads for the page. People only: Policies.Users :read_own_account refuses the service account and repo connections with 403 forbidden, whatever their grants.
Security Review ✅
|
…-4816) abilities on each of /api/v3/me/memberships' memberships is now ProjectUsers.actions() mapped to permitted?/2 on the page's scopes, keyed by the action's name, with no rename table. The OpenAPI lists each as a required boolean, and a test holds that list to actions/0. The policy's moduledoc says renaming or removing an action is a breaking API change.
abilities on each membership is now Projects.abilities/0 (access_project, edit_project, edit_workflow, run_workflow, add_project_user), each answered by ProjectUsers.permitted?/2 on the page's scopes. Tests hold the OpenAPI Abilities schema to that list and every entry to ProjectUsers.actions(), so a renamed action fails the build, and pin that access_project is false exactly when blocked_by_mfa? is true for a listed membership.
The signed-in person's users.support_user, as stored, beside role and mfa_enabled. The column allows null, so the OpenAPI marks it nullable.
abilities is now can_edit_project, can_edit_workflows, can_run and can_manage_members, from the keyword list Projects.abilities/0, each answered by ProjectUsers.permitted?/2 for its action on the page's scopes. access_project is dropped. The mapping shields the policy, so the ProjectUsers moduledoc no longer calls its actions API keys; the warning that renaming a key breaks clients sits on @abilities.
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.
Who is signed in, and their memberships with abilities (OFN-4816)
The new front end has no way to ask who is signed in or what they may do in a project. This adds two v3 reads; the front end builds its session context from them.
Routes
GET /api/v3/me: the signed-in person'semail,first_name,last_name,mfa_enabled,support_userand instancerole(userorsuperuser), as ausersresource.GET /api/v3/me/memberships: the caller's ownproject_usersrows asproject-membershipresources, paged and ordered by project name. Each carriesrole,abilitiesand relationships to its project and user.MeControllerfollowsProjectController: theVersionplug and aV3.MeJSONview.Abilities
Four, each mapped to one
Lightning.Policies.ProjectUsersaction and answered byProjectUsers.permitted?/2:can_edit_project:edit_projectcan_edit_workflows:edit_workflowcan_run:run_workflowcan_manage_members:add_project_user(adding and removing pass for the same roles)The mapping is
Projects.abilities/0. The names are API keys; the actions behind them can be renamed freely as long as the list follows. Tests fail if a mapped action stops being a policy action, or if the OpenAPIAbilitieskeys drift from the mapping.Scopes are read once per page with
Scope.fetch_all/2, never per row.In a project whose MFA requirement the caller hasn't met, every ability is
false, because that's the policy's answer.include=memberson projects is unchanged and carries no abilities.Who may call
Policies.Users :read_own_account, sends the service account and repo connections 403forbidden. It names no token grant: a person holds every grant, and naming one would send a repo connectioninsufficient_scope, pointing it at a grant that couldn't help.Which projects are listed
GET /api/v3/projectslists (paginate_projects_for/3): projects scheduled for deletion and sandboxes are left out.Other changes
ProjectJSON.membership/1is public and the user builder moved toUserJSON.member/1, shared byinclude=membersand the new views. Membership ids matchinclude=members.first_name,last_name,mfa_enabledandsupport_userare nullable, as they are in the database.API.mdroute rows and a CHANGELOG entry.Not done
pagevalue falls back to the default, as on every list, rather than a 400;Filters.page/1never refuses.false. Proposed:mfa_requiredfromProjectUsers.blocked_by_mfa?/1, which is additive./me/membershipsnorGET /api/v3/projectslists them;GET /api/v3/projects/:idopens one.Checked
v3/me/reading_test.exs: exact attributes for a session and a personal access token; a superuser seesrole: "superuser"and a support usersupport_user: true; the service account (with every grant) and a repo connection get 403 on both routes.v3/me/memberships_test.exs: the whole body for one membership; only the caller's rows; paging and the next link; ids matchinclude=members; the projects listed matchGET /api/v3/projects, with a scheduled and a sandbox project in the setup.ProjectUsers.permitted?for its action. The test also fails if every role gets the same answers.false. 401 with no auth, viasentinel_sweep_test.Abilitieskeys equal the mapping's names, and each mapped action is aProjectUsersaction (checked to fail on a rename).setup_utils_test.exsthat passes alone (logged). Redocly lint,mix credo --strictandmix formatpass. After it: 990 tests across the API controllers, policies and projects, 0 failures.Client side: OpenFn/lightning-ui#166.