-
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.
Merge pull request #76 from CanDIG/daisieh/opa-v1
Upgrade Opa to v1.0.0
- Loading branch information
Showing
8 changed files
with
210 additions
and
195 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
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,46 +1,48 @@ | ||
package system.authz | ||
|
||
import rego.v1 | ||
|
||
# this defines authentication to have access to opa at all | ||
# from: https://www.openpolicyagent.org/docs/v0.22.0/security/#token-based-authentication-example | ||
|
||
# Reject requests by default | ||
default allow = false | ||
default allow := false | ||
|
||
# Site admin should be able to see anything | ||
allow { | ||
data.permissions.site_admin == true | ||
allow if { | ||
data.permissions.site_admin == true | ||
} | ||
|
||
# Any service should be able to verify that a service is who it says it is: | ||
allow { | ||
input.path == ["v1", "data", "service", "verified"] | ||
input.method == "POST" | ||
allow if { | ||
input.path == ["v1", "data", "service", "verified"] | ||
input.method == "POST" | ||
} | ||
|
||
# Opa should be able to store its vault token | ||
allow { | ||
input.path == ["v1", "data", "store_token"] | ||
input.method == "PUT" | ||
input.headers["X-Opa"][_] == data.opa_secret | ||
allow if { | ||
input.path == ["v1", "data", "store_token"] | ||
input.method == "PUT" | ||
input.headers["X-Opa"][_] == data.opa_secret | ||
} | ||
|
||
# Service-info path for healthcheck | ||
allow { | ||
input.path == ["v1", "data", "service", "service-info"] | ||
input.method == "GET" | ||
allow if { | ||
input.path == ["v1", "data", "service", "service-info"] | ||
input.method == "GET" | ||
} | ||
|
||
# The authx library uses these paths: | ||
authx_paths = { | ||
"permissions": ["v1", "data", "permissions"], | ||
"user_id": ["v1", "data", "idp", "user_key"] | ||
authx_paths := { | ||
"permissions": ["v1", "data", "permissions"], | ||
"user_id": ["v1", "data", "idp", "user_key"], | ||
} | ||
|
||
# An authorized user has a valid token (and passes in that same token for both bearer and body) | ||
# Authz users can access the authx paths | ||
allow { | ||
input.path == authx_paths[_] | ||
input.method == "POST" | ||
data.permissions.valid_token == true | ||
input.body.input.token == input.identity | ||
allow if { | ||
input.path == authx_paths[_] | ||
input.method == "POST" | ||
data.permissions.valid_token == true | ||
input.body.input.token == input.identity | ||
} |
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
Oops, something went wrong.