-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add policy rules for session and proposal access
* session.access: user can access session * session.named_user: user is a named member of the visit * session.matches_beamline: visit is on the given beamline * session.session_beamline: beamline for the given visit * proposal.access: user can access proposal * proposal.named_user: user is a named user on the proposal * admin.admin: user is super admin * admin.beamline_admin: user is admin for the given beamline Rules are only defined if the required fields are included in the input. `admin.beamline_admin` refers to the beamline passed as `input.beamline` not as the beamline for the session defined by `proposal`+`visit`. Previous function `session.beamline` has been renamed to `beamline_for` to distinguish it from the `session.beamline` rule. User is determined from token passed as `input.token`.
- Loading branch information
Showing
6 changed files
with
288 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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,12 +1,16 @@ | ||
package diamond.policy.admin | ||
|
||
import data.diamond.policy.token | ||
import rego.v1 | ||
|
||
is_admin(subject) if { | ||
"super_admin" in data.diamond.data.subjects[subject].permissions # regal ignore:external-reference | ||
} | ||
is_admin[subject] := "super_admin" in data.diamond.data.subjects[subject].permissions | ||
|
||
is_beamline_admin(subject, beamline) if { | ||
some admin in data.diamond.data.subjects[subject].permissions | ||
beamline in data.diamond.data.admin[admin] # regal ignore:external-reference | ||
beamline_admin_for_subject[subject] contains beamline if { | ||
some subject | ||
some role in data.diamond.data.subjects[subject].permissions | ||
some beamline in data.diamond.data.admin[role] | ||
} | ||
|
||
admin := is_admin[token.claims.fedid] # regal ignore:rule-name-repeats-package | ||
|
||
beamline_admin := input.beamline in object.get(beamline_admin_for_subject, token.claims.fedid, []) |
This file contains 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 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,14 +1,23 @@ | ||
package diamond.policy.proposal | ||
|
||
import data.diamond.policy.admin | ||
import data.diamond.policy.token | ||
import rego.v1 | ||
|
||
default on_proposal(_, _) := false | ||
|
||
on_proposal(subject, proposal_number) if { | ||
proposal_number in data.diamond.data.subjects[subject].proposals # regal ignore:external-reference | ||
} | ||
|
||
default access_proposal(_, _) := false | ||
|
||
# Allow if subject has super_admin permission | ||
access_proposal(subject, proposal_number) if admin.is_admin(subject) | ||
access_proposal(subject, proposal_number) if admin.is_admin[subject] # regal ignore:external-reference | ||
|
||
# Allow if subject is on proposal | ||
access_proposal(subject, proposal_number) if on_proposal(subject, proposal_number) | ||
|
||
access := access_proposal(token.claims.fedid, input.proposal) | ||
|
||
named_user := on_proposal(token.claims.fedid, input.proposal) |
This file contains 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 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 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