-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add ulims authz policy #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MattPrit
wants to merge
4
commits into
main
Choose a base branch
from
feat/mp/add-ulims
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package diamond.policy.beamline | ||
|
|
||
| import data.diamond.policy.admin | ||
| import data.diamond.policy.token | ||
| import rego.v1 | ||
|
|
||
| subject := data.diamond.data.subjects[token.claims.fedid] | ||
|
|
||
| # METADATA | ||
| # title: User Beamlines | ||
| # description: | | ||
| # Identifies all beamlines the subject is authorized to access | ||
| # based on their assigned permissions. | ||
| # entrypoint: true | ||
| user_beamlines contains beamline if { | ||
| token.claims.fedid | ||
| not admin.is_admin(token.claims.fedid) | ||
| some p in subject.permissions | ||
| some beamline in object.get(data.diamond.data.admin, p, []) | ||
| } | ||
|
|
||
| user_beamlines contains beamline if { | ||
| admin.is_admin(token.claims.fedid) | ||
| some beamline in object.keys(data.diamond.data.beamlines) | ||
| } | ||
|
|
||
| user_beamlines contains token.claims.beamline if { | ||
| token.claims.beamline in object.keys(data.diamond.data.beamlines) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package diamond.policy.beamline_test | ||
|
|
||
| import data.diamond.policy.beamline | ||
| import rego.v1 | ||
|
|
||
| diamond_data := { | ||
| "subjects": { | ||
| "alice": { | ||
| "permissions": [], | ||
| "proposals": [1], | ||
| "sessions": [], | ||
| }, | ||
| "bob": { | ||
| "permissions": ["b07_admin"], | ||
| "proposals": [], | ||
| "sessions": [11], | ||
| }, | ||
| "carol": { | ||
| "permissions": ["super_admin"], | ||
| "proposals": [], | ||
| "sessions": [], | ||
| }, | ||
| "desmond": { | ||
| "permissions": [], | ||
| "proposals": [2], | ||
| "sessions": [13], | ||
| }, | ||
| "edna": { | ||
| "permissions": [], | ||
| "proposals": [2], | ||
| "sessions": [13, 14], | ||
| }, | ||
| "oscar": { | ||
| "permissions": [], | ||
| "proposals": [], | ||
| "sessions": [], | ||
| }, | ||
| }, | ||
| "sessions": { | ||
| "11": { | ||
| "beamline": "i03", | ||
| "proposal_number": 1, | ||
| "visit_number": 1, | ||
| }, | ||
| "12": { | ||
| "beamline": "b07", | ||
| "proposal_number": 1, | ||
| "visit_number": 2, | ||
| }, | ||
| "13": { | ||
| "beamline": "b07", | ||
| "proposal_number": 2, | ||
| "visit_number": 1, | ||
| }, | ||
| "14": { | ||
| "beamline": "b07", | ||
| "proposal_number": 2, | ||
| "visit_number": 2, | ||
| }, | ||
| }, | ||
| "proposals": { | ||
| "1": {"sessions": { | ||
| "1": 11, | ||
| "2": 12, | ||
| }}, | ||
| "2": {"sessions": { | ||
| "1": 13, | ||
| "2": 14, | ||
| }}, | ||
| }, | ||
| "beamlines": {"i03": {"sessions": [11]}, "b07": {"sessions": [12, 13, 14]}}, | ||
| "admin": {"b07_admin": ["b07"]}, | ||
| } | ||
|
|
||
| test_user_beamlines_super_admin if { | ||
| beamline.user_beamlines == {"i03", "b07"} with data.diamond.policy.token.claims as {"fedid": "carol"} | ||
| with data.diamond.data as diamond_data | ||
| } | ||
|
|
||
| test_user_beamlines_beamline_admin if { | ||
| beamline.user_beamlines == {"b07"} with data.diamond.policy.token.claims as {"fedid": "bob"} | ||
| with data.diamond.data as diamond_data | ||
| } | ||
|
|
||
| test_user_beamlines_non_admin if { | ||
| beamline.user_beamlines == set() with data.diamond.policy.token.claims as {"fedid": "alice"} | ||
| with data.diamond.data as diamond_data | ||
| } | ||
|
|
||
| test_user_beamlines_service_account if { | ||
| beamline.user_beamlines == {"b07"} with data.diamond.policy.token.claims as {"beamline": "b07"} | ||
| with data.diamond.data as diamond_data | ||
| } | ||
|
|
||
| test_user_beamlines_service_account_bad_beamline_claim if { | ||
| beamline.user_beamlines == set() with data.diamond.policy.token.claims as {"beamline": "area-51-beamline"} | ||
| with data.diamond.data as diamond_data | ||
| } |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package diamond.policy.ulims | ||
|
|
||
| import data.diamond.policy.admin | ||
| import data.diamond.policy.beamline | ||
| import data.diamond.policy.session | ||
| import data.diamond.policy.token | ||
| import rego.v1 | ||
|
|
||
| # METADATA | ||
| # title: Session Restrictions | ||
| # description: | | ||
| # Return the instrument sessions the current user is allowed to see, or null if the user is an admin | ||
| # Requires: | ||
| # - `input.token`, a JWT | ||
| # entrypoint: true | ||
| default session_restrictions := [] | ||
|
|
||
| session_restrictions := null if { | ||
| admin.is_admin(token.claims.fedid) | ||
| } | ||
|
|
||
| session_restrictions := [data.diamond.data.sessions[session_id] | some session_id in session.user_sessions] if { | ||
| not admin.is_admin(token.claims.fedid) | ||
| } | ||
|
|
||
| session_restrictions := [data.diamond.data.sessions[session_id] | some session_id in session.user_sessions] if { | ||
| not token.claims.fedid | ||
| } | ||
|
|
||
| # METADATA | ||
| # title: Filter sessions | ||
| # description: | | ||
| # Filter a provided list of instrument sessions, returning just those that the user has access to | ||
| # Requires: | ||
| # - `input.token`, a JWT | ||
| # - `input.instrument_sessions`, an array representing a list of instrument sessions, [(proposal, visit), ...] | ||
| # entrypoint: true | ||
| filter_sessions contains _session if { | ||
| "*" in session.user_sessions | ||
| some _session in input.instrument_sessions | ||
| proposal_number := format_int(_session[0], 10) | ||
| proposal_number in object.keys(data.diamond.data.proposals) | ||
| session_number := format_int(_session[1], 10) | ||
| session_number in object.keys(data.diamond.data.proposals[proposal_number].sessions) | ||
| } | ||
|
|
||
| filter_sessions contains _session if { | ||
| not "*" in session.user_sessions | ||
| some _session in input.instrument_sessions | ||
| proposal_number := format_int(_session[0], 10) | ||
| session_number := format_int(_session[1], 10) | ||
| format_int(data.diamond.data.proposals[proposal_number].sessions[session_number], 10) in session.user_sessions | ||
| } | ||
|
|
||
| # METADATA | ||
| # title: Filter instruments | ||
| # description: | | ||
| # Filter a provided list of instruments, returning just those that the user has access to | ||
| # Requires: | ||
| # - `input.token`, a JWT | ||
| # - `input.instruments`, an array of strings representing a list of instruments | ||
| # entrypoint: true | ||
| filter_instruments contains _beamline if { | ||
| some _beamline in input.instruments | ||
| _beamline in object.keys(data.diamond.data.beamlines) | ||
| _beamline in beamline.user_beamlines | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally don't like the "null" restrictions, But I understand what you are trying to do here