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

help request: OPA PLUGIN #11908

Open
LuciaCabanillasRodriguez opened this issue Jan 13, 2025 · 4 comments
Open

help request: OPA PLUGIN #11908

LuciaCabanillasRodriguez opened this issue Jan 13, 2025 · 4 comments
Labels
question label for questions asked by users

Comments

@LuciaCabanillasRodriguez

Description

Hi,

I’m setting up a route in APISIX where the URI is dynamic and depends on the user making the request. To achieve this, I’m using the OPA plugin. Within its result, I set a field called dynamic_metadata, which contains the URI the user is allowed to access.

However, I haven’t been able to retrieve this value from APISIX to include it as a variable in the URI. I tried configuring this using the proxy-rewrite plugin, but I haven’t achieved the desired result.

I would greatly appreciate any kind of help to resolve this issue.

Thanks!

Environment

  • APISIX version (run apisix version): 3.10.0
  • Operating system (run uname -a):
  • OpenResty / Nginx version (run openresty -V or nginx -V):
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info): 3.5.0
  • APISIX Dashboard version, if relevant: 3.0.1
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):
@dosubot dosubot bot added the question label for questions asked by users label Jan 13, 2025
@kayx23
Copy link
Member

kayx23 commented Jan 14, 2025

Please see if radixtree_uri_with_parameter router option helps: https://docs.api7.ai/apisix/reference/router-options#radixtree_uri_with_parameter

@LuciaCabanillasRodriguez
Copy link
Author

Thank you very much for your comment! Just something like that I was trying, the problem I think is that not all the OPA response is saved in the ctx so if I want to access a particular field of the OPA result I can not access as easily as in the example ctx.curr_req_matched.user_id

@kayx23
Copy link
Member

kayx23 commented Jan 15, 2025

not all the OPA response is saved in the ctx

Perhaps you could use the serverless function to parse the response and register the value into a variable, if appropriate? For instance https://docs.api7.ai/hub/serverless-functions#register-custom-variables

@LuciaCabanillasRodriguez
Copy link
Author

And how could I access that field in the OPA result?
I was trying something like that but I am not very clear on how to get that value:

"proxy-rewrite": {
      "uri": "/${upstream_uri}"
    },
    "serverless-pre-function": {
      "functions": [
        "return function(conf, ctx)\n  local core = require(\"apisix.core\")\n  core.ctx.register_var(\"opa_query\", function(ctx)\n    if ctx.var.opa_result and ctx.var.opa_result.result and ctx.var.opa_result.result.dynamic_metadata and ctx.var.opa_result.result.dynamic_metadata.query then\n      return ctx.var.opa_result.result.dynamic_metadata.query.q\n    end\n    return nil\n  end)\n  local query_q = ctx.var.opa_query\n  if query_q then\n    local encoded_q = core.utils.url_escape(\"publisher==\\\"\" .. query_q .. \"\\\"\")\n    ctx.var.upstream_uri =

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question label for questions asked by users
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants