-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates call to io.jwt.decode, http_api -> input
Signed-off-by: Jonathan Dursi <jonathan@dursi.ca>
- Loading branch information
Showing
1 changed file
with
19 additions
and
15 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,35 +1,39 @@ | ||
package httpapi.authz | ||
|
||
import input as http_api | ||
# http_api = { | ||
# "path": ["finance", "salary", "alice"], | ||
# "user": "alice", | ||
# "method": "GET", | ||
# "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiYWxpY2UiLCJhenAiOiJhbGljZSIsInN1Ym9yZGluYXRlcyI6W10sImhyIjpmYWxzZX0.rz3jTY033z-NrKfwrK89_dcLF7TN4gwCMj-fVBDyLoM" | ||
# } | ||
import input | ||
|
||
# io.jwt.decode takes one argument (the encoded token) and has three outputs: | ||
# the decoded header, payload and signature, in that order. Our policy only | ||
# cares about the payload, so we ignore the others. | ||
token = {"payload": payload} { io.jwt.decode(http_api.token, _, payload, _) } | ||
token = {"payload": payload} { io.jwt.decode(input.token, [_, payload, _]) } | ||
|
||
# Ensure that the token was issued to the user supplying it. | ||
user_owns_token { http_api.user = token.payload.azp } | ||
user_owns_token { input.user == token.payload.azp } | ||
|
||
default allow = false | ||
|
||
# Allow users to get their own salaries. | ||
allow { | ||
http_api.method = "GET" | ||
http_api.path = ["finance", "salary", username] | ||
username = token.payload.user | ||
some username | ||
input.method == "GET" | ||
input.path = ["finance", "salary", username] | ||
token.payload.user == username | ||
user_owns_token | ||
} | ||
|
||
# Allow managers to get their subordinate' salaries. | ||
allow { | ||
http_api.method = "GET" | ||
http_api.path = ["finance", "salary", username] | ||
token.payload.subordinates[_] = username | ||
some username | ||
input.method == "GET" | ||
input.path = ["finance", "salary", username] | ||
token.payload.subordinates[_] == username | ||
user_owns_token | ||
} | ||
|
||
# Allow HR members to get anyone's salary. | ||
allow { | ||
input.method == "GET" | ||
input.path = ["finance", "salary", _] | ||
token.payload.hr == true | ||
user_owns_token | ||
} |