Skip to content

How to make opa-envoy-plugin return different status code (401/403) #42

Answered by srenatus
27149chen asked this question in Envoy
Discussion options

You must be logged in to vote

The policy primer docs for envoy have an example of an object response. I would think that you can make use of that, see this sketch:

package envoy.authz

default response = {
  "allowed": false,
  "body": "Unauthorized Request",
  "http_status": 403
}

response = r {
  not is_authenticated
  r := {
    "allowed": false,
    "http_status": 401
  }
}

where is_authenticated is the rule in which you establish authentication.

Note that the query path for this example is envoy/authz/response -- I've always found allow for an object response slightly off the mark.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@27149chen
Comment options

@srenatus
Comment options

@27149chen
Comment options

@srenatus
Comment options

Answer selected by 27149chen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
Converted from issue

This discussion was converted from issue #41 on October 28, 2021 07:22.