Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supprot OPA plugin complex response #5779

Merged
merged 26 commits into from
Dec 15, 2021

Conversation

bzp2010
Copy link
Contributor

@bzp2010 bzp2010 commented Dec 13, 2021

What this PR does / why we need it:

Enhance OPA plug-in functionality to support overwriting of status codes, response headers, and response bodies when validation is rejected.

stage 2 of #5714

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@bzp2010 bzp2010 added the enhancement New feature or request label Dec 13, 2021
@bzp2010 bzp2010 self-assigned this Dec 13, 2021
@bzp2010 bzp2010 force-pushed the feat-opa-stage2 branch 6 times, most recently from 53d5b57 to 4954a7d Compare December 13, 2021 09:03
@bzp2010
Copy link
Contributor Author

bzp2010 commented Dec 13, 2021

Summary

The OPA plugin is enhanced in this PR to support overriding the status code, request header and request body in case of a failed check.

  • Update OPA policy
  • Update plugin

Description

A response containing the following can be sent to APISIX in the OPA policy.

{
  "result": {
    "allow": false,
    "status_code": 302,
    "headers": {
      "Location": "http://example.com/auth"
    },
    "reason": {
      "test": "test"
    }
  }
}

The status code, response header, and reason are all optional respectively, and the reason can be a string or object, and the plugin will automatically JSON encode according to the data type.

apisix/plugins/opa.lua Show resolved Hide resolved
apisix/plugins/opa.lua Outdated Show resolved Hide resolved
apisix/plugins/opa.lua Show resolved Hide resolved
apisix/plugins/opa.lua Show resolved Hide resolved
@bzp2010
Copy link
Contributor Author

bzp2010 commented Dec 15, 2021

ping @shuaijinchao PTAL thanks

@bzp2010 bzp2010 merged commit 6ce20fc into apache:master Dec 15, 2021
@anderseknert
Copy link

👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants