Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions policy/diamond/policy/tiled/tiled.rego
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ scopes := {
"tiled-writer" in token.claims.aud
}

default service_account_for_beamline := false

service_account_for_beamline if {
input.beamline == token.claims.beamline
"tiled-writer" in token.claims.aud
not token.claims.fedid
}

_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
Expand Down
20 changes: 20 additions & 0 deletions policy/diamond/policy/tiled/tiled_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,23 @@ test_user_session_tags_service_account if {
tiled.user_sessions == set() with data.diamond.data as diamond_data
with data.diamond.policy.token.claims as {"beamline": "b007"}
}

test_service_account_if_beamline_matches if {
tiled.service_account_for_beamline with input as {"beamline": "i22"}
with data.diamond.policy.token.claims as {"beamline": "i22", "aud": ["tiled-writer"]}
}

test_not_service_account_if_beamline_mismatch if {
not tiled.service_account_for_beamline with input as {"beamline": "b21"}
with data.diamond.policy.token.claims as {"beamline": "i22", "aud": ["tiled-writer"]}
}

test_not_service_account_if_missing_aud if {
not tiled.service_account_for_beamline with input as {"beamline": "i22"}
with data.diamond.policy.token.claims as {"beamline": "i22", "aud": ["blueapiCli"]}
}

test_not_service_account_if_fedid_present if {
not tiled.service_account_for_beamline with input as {"beamline": "i22"}
with data.diamond.policy.token.claims as {"beamline": "i22", "aud": ["tiled-writer"], "fedid": "abc12345"}
}
Loading