Skip to content

Extend group-based access with ndp_admin role and endpoint UUID (v0.12.0)#107

Merged
rbardaji merged 10 commits intomainfrom
feature/106-extend-group-access
Apr 22, 2026
Merged

Extend group-based access with ndp_admin role and endpoint UUID (v0.12.0)#107
rbardaji merged 10 commits intomainfrom
feature/106-extend-group-access

Conversation

@rbardaji
Copy link
Copy Markdown
Collaborator

Summary

  • When ENABLE_GROUP_BASED_ACCESS=True, authorize users if any of the following is true:
    1. The user belongs to a group listed in GROUP_NAMES (existing behavior)
    2. The user has the ndp_admin role
    3. The user belongs to the group whose name matches AFFINITIES_EP_UUID
  • When the feature is disabled the behavior is unchanged — any authenticated user is allowed
  • The 403 response body now enumerates all three accepted authorization paths
  • Bump version to 0.12.0

Closes #106

Test plan

  • 12 new unit tests covering the admin role path and the endpoint UUID group path
  • Existing authorization tests still pass (28 cases)
  • Full test suite passes (1045 tests)
  • black --check --diff . passes
  • flake8 api/ tests/ --max-line-length=88 --extend-ignore=E203,W503,E501,F401 passes

Raul Bardaji added 10 commits April 22, 2026 12:20
…dpoint UUID group

Previously, enabling group-based access required a user to belong to
one of the groups listed in GROUP_NAMES. This commit broadens the
authorization rule so that any of the following grants access:

1. Membership in a group listed in GROUP_NAMES (existing behavior)
2. The 'ndp_admin' role on the user's token
3. Membership in the group whose name matches AFFINITIES_EP_UUID

When ENABLE_GROUP_BASED_ACCESS is False the behavior is unchanged. The
forbidden response now describes all three accepted paths.

Refs #106
Add 12 test cases for the two new authorization paths:

- ndp_admin role grants access (including without matching group,
  with empty GROUP_NAMES, case-insensitive, and ignored when the
  roles field is missing or malformed)
- Membership in the AFFINITIES_EP_UUID group grants access (including
  group given as a dict with path, case-insensitive matching, and
  the empty-UUID guard)
- The feature-disabled path remains permissive

Also confirm that a user outside all three paths is denied.

Refs #106
Introduce get_user_for_endpoint_access, a dependency that mirrors the
existing write-operation gate but with an error message tailored to
Endpoint-wide access rather than write operations. Apply it on
/user/info so unauthorized users are rejected at the UI entry point
instead of being allowed to enter the app only to hit 403s on every
write.

Extract the shared 403 response into a small helper so both paths
report the same 'ndp_admin / endpoint UUID group / GROUP_NAMES'
contract with only the context phrase differing.

Refs #106
After obtaining a token through the credentials login flow, validate
it against /user/info before storing it, so authorization errors are
surfaced to the user at login time rather than after entering the app.

Translate 403 responses from /user/info into a user-visible message
('You do not have permission to access this Endpoint.' or the
backend-supplied detail) in the AuthGuard token, credentials, and
existing-session paths.

Refs #106
Verify four behaviors of the new Endpoint-access dependency:

- Feature disabled: any authenticated user is allowed
- Authorized user (via mocked check_group_membership) is passed through
- Unauthorized user raises 403 with a message naming the Endpoint,
  including the ndp_admin role and the configured endpoint UUID
- The pre-existing write-operation dependency still reports its own
  context ('write operations') to ensure the refactor didn't leak
  one context phrase into the other

Refs #106
The previous 403 detail exposed internal authorization jargon
(admin role name, endpoint UUID, configured GROUP_NAMES list,
even an empty []) that end users could not act on. Replace it with
two concise, actionable messages:

  - Endpoint access:
      'You do not have permission to access this Endpoint.
       Please contact the administrator if you believe this is
       a mistake.'
  - Write operations:
      'You do not have permission to perform this operation.
       Please contact the administrator if you believe this is
       a mistake.'

Technical details (required role, endpoint group UUID, configured
group list) are now emitted as a warning in the backend log so
administrators can still diagnose rejections without leaking
implementation details to end users.

Refs #106
Drop the 'if you believe this is a mistake' tail so the 403 detail is
a short two-sentence instruction:

  - 'You do not have permission to access this Endpoint.
     Please contact the administrator.'
  - 'You do not have permission to perform this operation.
     Please contact the administrator.'

Refs #106
@rbardaji rbardaji merged commit 307ff1f into main Apr 22, 2026
1 check passed
@rbardaji rbardaji deleted the feature/106-extend-group-access branch April 22, 2026 19:07
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.

Extend group-based access to accept ndp_admin role and endpoint UUID group

1 participant