Once OPA is done executing policies, the plugin expects the policy evaluation result as either a boolean or an object. If OPA returns any other format or a status code other than 200 OK, the plugin will return a 500 Internal Server Error to the client.
OPA can return a true or false result after a policy evaluation. If the input request meets the defined policies, OPA should send a "result": true response. If the request violates the policy, OPA should send a "result": false response. In this case, any other fields in the response are ignored.
For most use cases, the boolean response should suffice. However, you can configure the policy to return an object if needed. This can be used to inject custom HTTP headers to the request, or to change the HTTP code for rejected requests.
In this case, the OPA response has the following structure:
{
"result": {
"allow": true,
"status": 201,
"headers": {
"key": "value",
"key2": "value2"
},
"message": "value3 or object",
}
}
The only required field in this response is result.allow, which accepts a boolean value.
If result.allow is true, then the key-value pairs in result.headers are injected into the request before it’s forwarded to the upstream service.
If result.allow is set to false, then the key-value pairs in result.headers are injected into the response, the response message is set to result.message, and the status code of the response is set to result.status. If result.status is absent, the default 403 status code is sent. If result.message is absent, then the default unauthorized message is sent.