Skip to content

Commit

Permalink
Updates call to io.jwt.decode, http_api -> input
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Dursi <jonathan@dursi.ca>
  • Loading branch information
ljdursi authored and tsandall committed Aug 16, 2019
1 parent f9e71d7 commit 7e55264
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions api_authz/docker/policy/api_authz_token.rego
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
}

0 comments on commit 7e55264

Please sign in to comment.