how to write a policy that will only allow certain keys to exist in data #252
Answered
by
anderseknert
anwar-al-jahwari
asked this question in
OPA and Rego
-
hello everyone, i have a case where the user with a role of client can only update his password and nothing else. how to write that policy? |
Beta Was this translation helpful? Give feedback.
Answered by
anderseknert
Aug 22, 2022
Replies: 1 comment 1 reply
-
Hi @pccrazy 👋 That would depend on how your API is structured, but as an example — if the input were to look something like this: {
"request": {
"method": "PUT",
"path": [
"users",
"abc123",
"password"
]
},
"user": {
"id": "abc123",
"roles": [
"client"
]
}
} A policy to allow updates of the users' password resource could look something like this: package play
import future.keywords.if
import future.keywords.in
default allow := false
allow if {
input.request.method == "PUT"
input.request.path == ["users", input.user.id, "password"]
"client" in input.user.roles
} Full example in the Rego Playground. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
anwar-al-jahwari
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @pccrazy 👋
That would depend on how your API is structured, but as an example — if the input were to look something like this:
A policy to allow updates of the users' password resource could look something like this:
Full exampl…