-
Notifications
You must be signed in to change notification settings - Fork 5
feat: update tiled policy #300
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
ZohebShaikh
wants to merge
5
commits into
DiamondLightSource:main
Choose a base branch
from
ZohebShaikh:update-tiled-authz
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
5 commits
Select commit
Hold shift + click to select a range
daa0f52
feat: update tiled policy
ZohebShaikh 47e8d9c
feat: update policy for service accounts
ZohebShaikh 68333b4
default fedid for machine users ""
ZohebShaikh ea80a92
Fix lint issue
ZohebShaikh 6f9d74d
Use token.claims.fedid
ZohebShaikh 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 |
|---|---|---|
| @@ -1,44 +1,117 @@ | ||
| package diamond.policy.tiled | ||
|
|
||
| import data.diamond.policy.admin | ||
| import data.diamond.policy.session | ||
| import data.diamond.policy.token | ||
| import rego.v1 | ||
|
|
||
| read_scopes := { | ||
| # Assign read & write scopes to clients with tiled-writer audience | ||
| # defaults to read-only scopes | ||
| default scopes := { | ||
| "read:metadata", | ||
| "read:data", | ||
| } | ||
|
|
||
| write_scopes := { | ||
| scopes := { | ||
| "read:metadata", | ||
| "read:data", | ||
| "write:metadata", | ||
| "write:data", | ||
| "create:node", | ||
| "register", | ||
| } if { | ||
| "tiled-writer" in token.claims.aud | ||
| } | ||
|
|
||
| _session := data.diamond.data.proposals[format_int(input.proposal, 10)].sessions[format_int(input.visit, 10)] | ||
|
|
||
| # Returns the session ID if the subject has write permissions for the | ||
| # specific beamline, visit and proposal requested in the input. | ||
| user_session := to_number(_session) if { | ||
| session.write_to_beamline_visit | ||
| _session | ||
| } | ||
|
|
||
| user_session := to_number(_session) if { | ||
| input.proposal in token.claims.subject.proposals | ||
| } | ||
|
|
||
| user_session := to_number(_session) if { | ||
| _session in token.claims.subject.sessions | ||
| } | ||
|
|
||
| user_session := to_number(_session) if { | ||
| input.beamline in beamlines | ||
| input.beamline == session.beamline_for(input.proposal, input.visit) | ||
| _session in data.diamond.data.beamlines[input.beamline].sessions | ||
| } | ||
|
|
||
| default fedid := "" | ||
tpoliaw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| fedid := token.claims.fedid | ||
|
|
||
| # Validates if the subject has permission to modify | ||
| # the specific session in the input. | ||
| default modify_session := false | ||
|
|
||
| modify_session if session.access_session( | ||
tpoliaw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fedid, | ||
| data.diamond.data.sessions[input.session].proposal_number, | ||
| data.diamond.data.sessions[input.session].visit_number, | ||
| ) | ||
|
|
||
| modify_session if { | ||
| data.diamond.data.sessions[input.session].proposal_number in token.claims.subject.proposals | ||
| } | ||
|
|
||
| modify_session if { | ||
| to_number(input.session) in token.claims.subject.sessions | ||
| } | ||
|
|
||
| scopes_for(claims) := read_scopes | write_scopes if { | ||
| "azp" in object.keys(claims) | ||
| endswith(claims.azp, "-blueapi") | ||
| modify_session if { | ||
| session.beamline_for( | ||
| data.diamond.data.sessions[input.session].proposal_number, | ||
| data.diamond.data.sessions[input.session].visit_number, | ||
| ) in beamlines | ||
| } | ||
|
|
||
| scopes_for(claims) := read_scopes if { | ||
| "azp" in object.keys(claims) | ||
| not endswith(claims.azp, "-blueapi") | ||
| subject := data.diamond.data.subjects[token.claims.fedid] if token.claims.fedid | ||
|
|
||
| else := token.claims.subject if token.claims.subject | ||
|
|
||
| # Identifies all beamlines the subject is authorized to access | ||
| # based on their assigned permissions. | ||
| beamlines contains beamline if { | ||
| not admin.is_admin(fedid) | ||
| some p in subject.permissions | ||
| some beamline in object.get(data.diamond.data.admin, p, []) | ||
| } | ||
|
|
||
| scopes_for(claims) := read_scopes if { | ||
| not "azp" in object.keys(claims) | ||
| # Aggregates all session IDs the subject is authorized to view. | ||
| # Admins receive a wildcard "*" granting access to all sessions. | ||
|
|
||
| # Regular users gain session access through three pathways: | ||
| # 1. Direct session membership | ||
| # 2. Access via beamline-level permissions | ||
| # 3. Access via proposal-level permissions | ||
| user_sessions contains "*" if { | ||
| admin.is_admin(fedid) | ||
| } | ||
|
|
||
| default scopes := set() | ||
| user_sessions contains to_number(session) if { | ||
| not admin.is_admin(fedid) | ||
| some session in subject.sessions | ||
| } | ||
|
|
||
| scopes := scopes_for(token.claims) | ||
| user_sessions contains to_number(session) if { | ||
| not admin.is_admin(fedid) | ||
| some beamline in beamlines | ||
| some session in data.diamond.data.beamlines[beamline].sessions | ||
| } | ||
|
|
||
| user_sessions contains user_session if { | ||
| some i in data.diamond.data.sessions | ||
| session.access_session(token.claims.fedid, i.proposal_number, i.visit_number) | ||
| user_session := sprintf( | ||
| `{"proposal": %d, "visit": %d, "beamline": "%s"}`, | ||
| [i.proposal_number, i.visit_number, i.beamline], | ||
| ) | ||
| user_sessions contains to_number(session) if { | ||
| not admin.is_admin(fedid) | ||
| some p in subject.proposals | ||
| some i in data.diamond.data.proposals[format_int(p, 10)] | ||
| some session in i | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.