Opa: Accessing data file from rego

Created on 7 Aug 2020  路  2Comments  路  Source: open-policy-agent/opa


I am trying to access data.json in rego and it doesn't work, I guess I may be doing something wrong

package rbac.authz

is_user_owner_or_viewer[data.user_attributes.DataSteward] {
true
}


{
"user_attributes" : {
"DataSteward":"acl.owners",
"DelegatedStewards": "acl.owners"
}
}

When I try to execute the same in rego playground it is working fine , but when I try to execute it using opa executable, I may be missing something. all the files are in the same folder (input.json. testPolicy.rego, data.json)

opa_windows_amd64 eval -i input.json -d testPolicy.rego "data"

https://play.openpolicyagent.org/p/2l89PLAsl3

Expected Behavior

{
"is_user_owner_or_viewer": [
"acl.owners"
]
}

Actual Behavior

"is_user_owner_or_viewer": []

Steps to Reproduce the Problem

Additional Info

Most helpful comment

Awesome, Thanks Pat for your quick response. I was missing -d data.json. It is working now.

All 2 comments

Hi @Jeyakumardevarajulu

To confirm, the JSON snippet:

{
    "user_attributes" : {
        "DataSteward":"acl.owners",
        "DelegatedStewards": "acl.owners"
    }
}

is in a separate file? You will need to include it on the CLI like:

opa_windows_amd64 eval -i input.json -d testPolicy.rego -d data.json "data"

Where the input.json is the INPUT panel of the playground, the testPolicy.rego would be the policy section, and data.json is the DATA panel of the playground.

Awesome, Thanks Pat for your quick response. I was missing -d data.json. It is working now.

Was this page helpful?
0 / 5 - 0 ratings