Unable to access environment variable #519
Replies: 3 comments 2 replies
-
I put the following test case together which illustrates how to use an environment variable with io.jwt.verify_hs256(). If you think this test case would be useful to have in the OPA test suite, I'd be happy to create a pull request for it. Currently, I've added the test to the /sdk/opa_test.go file in my fork. `
package system rt := opa.runtime() grant { claims := payload { authenticatedUser := a {
} |
Beta Was this translation helpful? Give feedback.
-
I think that's where my confusion is. So I started poking in around in various tests and commits to understand further. In this commit there is an example of a config that defines an "env" field with environment variables. See tsandall's comment on Oct 16, 2018. Based upon my testing it appears an environment variable could be passed in to OPA in two ways.
I'll create a PR to illustrate both cases and let you decide if it makes sense to include them in OPA's test suite. |
Beta Was this translation helpful? Give feedback.
-
Here is the pull request! |
Beta Was this translation helpful? Give feedback.
-
I'm attempting to access the 'OAUTH_TOKEN_VERIFY_KEY' environment variable via the opa.runtime built-in function to provide the verify key for our oauth token in the following manner.
claims := payload {
io.jwt.verify_rs256(input.token, opa.runtime().env.OAUTH_TOKEN_VERIFY_KEY)
[_, payload, _] := io.jwt.decode(input.token)
}
The environment variable is provided via the following configuration:
{
"services": {
"types": {
"url": "https://[our-host]/"
}
},
"bundles": {
"types": {
"resource": "/authorization/bundles/types",
"polling": {
"min_delay_seconds": 5,
"max_delay_seconds": 15
}
}
},
"decision_logs": {
"console": false
},
"env": {
"OAUTH_TOKEN_VERIFY_KEY" : "[our key]"
}
}
The config is passed in to OPA using the sdk.Options type:
opa, err := sdk.New(ctx, sdk.Options{
ID: fmt.Sprintf("%s-opa", bundleName),
Config: bytes.NewReader(config),
...
})
However, the policy does not evaluate correctly as a result of the environment variable.
Is there an example that I can refer to that illustrates how set up the environment variable so that it can be accessed in a policy?
Beta Was this translation helpful? Give feedback.
All reactions