From 5f05a50a854abf16748d4a84eb8afa54f14d9fa7 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 8 Oct 2024 09:53:54 +0200 Subject: [PATCH 01/22] add body support for the opa plugin --- apisix/plugins/opa.lua | 1 + apisix/plugins/opa/helper.lua | 23 +++++++++ t/plugin/opa3.t | 91 +++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 t/plugin/opa3.t diff --git a/apisix/plugins/opa.lua b/apisix/plugins/opa.lua index 0475529f0c17..fd4989077b28 100644 --- a/apisix/plugins/opa.lua +++ b/apisix/plugins/opa.lua @@ -51,6 +51,7 @@ local schema = { with_route = {type = "boolean", default = false}, with_service = {type = "boolean", default = false}, with_consumer = {type = "boolean", default = false}, + with_body = {type = "boolean", default = false}, }, required = {"host", "policy"} } diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index 638adcf0ef87..a14baee41f89 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -45,8 +45,31 @@ local function build_http_request(conf, ctx) headers = core.request.headers(ctx), query = core.request.get_uri_args(ctx), } + + + if conf.with_body then + http.body = get_body() + end + + return http end +local function get_body() + local original_body, err = core.request.get_body() + if err ~= nil then + error("opa - failed to get request body: ", err) + end + if body = nil then + return nil + end + -- decode to prevent double encoded json objects + body, err = core.json.decode(original_body) + if err ~nil then + -- if its not json, the body can just be added + body = original_body + end + return body +end local function build_http_route(conf, ctx, remove_upstream) local route = core.table.deepcopy(ctx.matched_route).value diff --git a/t/plugin/opa3.t b/t/plugin/opa3.t new file mode 100644 index 000000000000..05f256f98304 --- /dev/null +++ b/t/plugin/opa3.t @@ -0,0 +1,91 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +use t::APISIX 'no_plan'; + +repeat_each(1); +no_long_string(); +no_root_location(); + +add_block_preprocessor(sub { + my ($block) = @_; + + if (!defined $block->request) { + $block->set_value("request", "GET /t"); + } +}); + +run_tests(); + +__DATA__ + + +=== TEST 1: setup route with plugin +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "methods": ["POST"], + "plugins": { + "opa": { + "host": "http://127.0.0.1:8181", + "policy": "example", + "with_body": true + } + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + }, + "uris": ["/hello", "/test"] + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(code..body) + } + } +--- response_body +passed + +=== TEST 3: hit route (with empty request) +--- request +POST /hello +--- response_body +200 + +=== TEST 4: hit route (with json request) +--- request +POST /hello +{ + "hello": "world" +} +--- response_body +200 {"hello": "world"} + +=== TEST 5: hit route (with non-json request) +--- request +POST /hello +hello world +--- response_body +200 hello world \ No newline at end of file From a04ec4baa6cfbdb522304553629a0d6a5551e750 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 8 Oct 2024 10:50:06 +0200 Subject: [PATCH 02/22] fix method calls and test names --- apisix/plugins/opa/helper.lua | 38 +++++++++++++++++------------------ t/plugin/opa3.t | 8 ++++---- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index a14baee41f89..c1506b81f751 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -35,8 +35,25 @@ local function build_var(conf, ctx) end +local function get_body_for_request() + local original_body, err = core.request.get_body() + if err ~= nil then + error("opa - failed to get request body: ", err) + end + if body == nil then + return nil + end + -- decode to prevent double encoded json objects + body, err = core.json.decode(original_body) + if err ~= nil then + -- if its not json, the body can just be added + body = original_body + end + return body +end + local function build_http_request(conf, ctx) - return { + local http = { scheme = core.request.get_scheme(ctx), method = core.request.get_method(), host = core.request.get_host(ctx), @@ -48,29 +65,12 @@ local function build_http_request(conf, ctx) if conf.with_body then - http.body = get_body() + http.body = get_body_for_request() end return http end -local function get_body() - local original_body, err = core.request.get_body() - if err ~= nil then - error("opa - failed to get request body: ", err) - end - if body = nil then - return nil - end - -- decode to prevent double encoded json objects - body, err = core.json.decode(original_body) - if err ~nil then - -- if its not json, the body can just be added - body = original_body - end - return body -end - local function build_http_route(conf, ctx, remove_upstream) local route = core.table.deepcopy(ctx.matched_route).value diff --git a/t/plugin/opa3.t b/t/plugin/opa3.t index 05f256f98304..bb0fd87f00d6 100644 --- a/t/plugin/opa3.t +++ b/t/plugin/opa3.t @@ -66,15 +66,15 @@ __DATA__ } } --- response_body -passed +200passed -=== TEST 3: hit route (with empty request) +=== TEST 2: hit route (with empty request) --- request POST /hello --- response_body 200 -=== TEST 4: hit route (with json request) +=== TEST 3: hit route (with json request) --- request POST /hello { @@ -83,7 +83,7 @@ POST /hello --- response_body 200 {"hello": "world"} -=== TEST 5: hit route (with non-json request) +=== TEST 4: hit route (with non-json request) --- request POST /hello hello world From c86bc2cb8e5a89ccb15716f92b4b360d626de384 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 8 Oct 2024 10:53:16 +0200 Subject: [PATCH 03/22] fix linting issues --- apisix/plugins/opa/helper.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index c1506b81f751..ad053cb1906b 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -34,13 +34,12 @@ local function build_var(conf, ctx) } end - -local function get_body_for_request() +local function get_body_for_request() local original_body, err = core.request.get_body() if err ~= nil then error("opa - failed to get request body: ", err) end - if body == nil then + if body == nil then return nil end -- decode to prevent double encoded json objects @@ -67,7 +66,7 @@ local function build_http_request(conf, ctx) if conf.with_body then http.body = get_body_for_request() end - + return http end From 7b1a8b61c78dd41c4b6d19fdb9d20a19bd0b22ad Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 8 Oct 2024 12:49:06 +0200 Subject: [PATCH 04/22] fix tests --- apisix/plugins/opa.lua | 2 +- apisix/plugins/opa/helper.lua | 1 - ci/pod/docker-compose.plugin.yml | 5 ++++- ci/pod/opa/with_body.rego | 29 +++++++++++++++++++++++++++++ t/plugin/opa3.t | 16 ++++++++-------- 5 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 ci/pod/opa/with_body.rego diff --git a/apisix/plugins/opa.lua b/apisix/plugins/opa.lua index fd4989077b28..e7df086cbd1d 100644 --- a/apisix/plugins/opa.lua +++ b/apisix/plugins/opa.lua @@ -51,7 +51,7 @@ local schema = { with_route = {type = "boolean", default = false}, with_service = {type = "boolean", default = false}, with_consumer = {type = "boolean", default = false}, - with_body = {type = "boolean", default = false}, + with_body = {type = "boolean", default = false} }, required = {"host", "policy"} } diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index ad053cb1906b..a67d11bec97b 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -62,7 +62,6 @@ local function build_http_request(conf, ctx) query = core.request.get_uri_args(ctx), } - if conf.with_body then http.body = get_body_for_request() end diff --git a/ci/pod/docker-compose.plugin.yml b/ci/pod/docker-compose.plugin.yml index 55f2b443c495..6c8dadea82aa 100644 --- a/ci/pod/docker-compose.plugin.yml +++ b/ci/pod/docker-compose.plugin.yml @@ -183,11 +183,14 @@ services: restart: unless-stopped ports: - 8181:8181 - command: run -s /example.rego /echo.rego /data.json /with_route.rego + command: run -s /example.rego /echo.rego /data.json /with_route.rego /with_body.rego volumes: - type: bind source: ./ci/pod/opa/with_route.rego target: /with_route.rego + - type: bind + source: ./ci/pod/opa/with_body.rego + target: /with_body.rego - type: bind source: ./ci/pod/opa/example.rego target: /example.rego diff --git a/ci/pod/opa/with_body.rego b/ci/pod/opa/with_body.rego new file mode 100644 index 000000000000..f5606d3ff242 --- /dev/null +++ b/ci/pod/opa/with_body.rego @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +package with_body + +import input.request + +default allow = false + +allow { + request.method == "POST" +} + +allow { + request.body +} \ No newline at end of file diff --git a/t/plugin/opa3.t b/t/plugin/opa3.t index bb0fd87f00d6..3a72e4c84756 100644 --- a/t/plugin/opa3.t +++ b/t/plugin/opa3.t @@ -39,13 +39,13 @@ __DATA__ content_by_lua_block { local t = require("lib.test_admin").test local code, body = t('/apisix/admin/routes/1', - ngx.HTTP_PUT, - [[{ + ngx.HTTP_PUT, + [[{ "methods": ["POST"], "plugins": { "opa": { "host": "http://127.0.0.1:8181", - "policy": "example", + "policy": "with_body", "with_body": true } }, @@ -62,17 +62,17 @@ __DATA__ if code >= 300 then ngx.status = code end - ngx.say(code..body) + ngx.say(body) } } --- response_body -200passed +passed === TEST 2: hit route (with empty request) --- request POST /hello --- response_body -200 +hello world === TEST 3: hit route (with json request) --- request @@ -81,11 +81,11 @@ POST /hello "hello": "world" } --- response_body -200 {"hello": "world"} +hello world === TEST 4: hit route (with non-json request) --- request POST /hello hello world --- response_body -200 hello world \ No newline at end of file +hello world From 6eeaac5d183d288e238464aed27571279c266607 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 8 Oct 2024 12:51:21 +0200 Subject: [PATCH 05/22] linting fixes --- apisix/plugins/opa/helper.lua | 2 +- ci/pod/opa/with_body.rego | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index a67d11bec97b..c0650fc7a103 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -65,7 +65,7 @@ local function build_http_request(conf, ctx) if conf.with_body then http.body = get_body_for_request() end - + return http end diff --git a/ci/pod/opa/with_body.rego b/ci/pod/opa/with_body.rego index f5606d3ff242..9a9ef2a5463b 100644 --- a/ci/pod/opa/with_body.rego +++ b/ci/pod/opa/with_body.rego @@ -26,4 +26,4 @@ allow { allow { request.body -} \ No newline at end of file +} From cea6be4b928ca09bbf2a379b9482741158bf5c9a Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 8 Oct 2024 12:59:35 +0200 Subject: [PATCH 06/22] fix linting --- t/plugin/opa3.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/plugin/opa3.t b/t/plugin/opa3.t index 3a72e4c84756..ebc3faac530d 100644 --- a/t/plugin/opa3.t +++ b/t/plugin/opa3.t @@ -40,7 +40,7 @@ __DATA__ local t = require("lib.test_admin").test local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, - [[{ + [[{ "methods": ["POST"], "plugins": { "opa": { From 3aa6a48e3a83026e244c38fd74e2e0472a5f3d84 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 8 Oct 2024 13:05:45 +0200 Subject: [PATCH 07/22] add doc --- docs/en/latest/plugins/opa.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/latest/plugins/opa.md b/docs/en/latest/plugins/opa.md index 12d79a2e36da..528b751153c8 100644 --- a/docs/en/latest/plugins/opa.md +++ b/docs/en/latest/plugins/opa.md @@ -46,6 +46,7 @@ The `opa` Plugin can be used to integrate with [Open Policy Agent (OPA)](https:/ | with_route | boolean | False | false | | When set to true, sends information about the current Route. | | with_service | boolean | False | false | | When set to true, sends information about the current Service. | | with_consumer | boolean | False | false | | When set to true, sends information about the current Consumer. Note that this may send sensitive information like the API key. Make sure to turn it on only when you are sure it is safe. | +| with_body | boolean | False | false | | When set to true, sends the request body. | ## Data definition From 656a3f09e0d551dff3b5d816fa0b308dca995ca8 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 8 Oct 2024 13:29:55 +0200 Subject: [PATCH 08/22] clean --- t/plugin/opa3.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/plugin/opa3.t b/t/plugin/opa3.t index ebc3faac530d..315f1278bdb0 100644 --- a/t/plugin/opa3.t +++ b/t/plugin/opa3.t @@ -40,7 +40,7 @@ __DATA__ local t = require("lib.test_admin").test local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, - [[{ + [[{ "methods": ["POST"], "plugins": { "opa": { From 13c775f971f7b3e03e3d0d07a905a1058cc53987 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 8 Oct 2024 13:32:59 +0200 Subject: [PATCH 09/22] still lintign --- t/plugin/opa3.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/plugin/opa3.t b/t/plugin/opa3.t index 315f1278bdb0..440bdd69b4d2 100644 --- a/t/plugin/opa3.t +++ b/t/plugin/opa3.t @@ -40,7 +40,7 @@ __DATA__ local t = require("lib.test_admin").test local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, - [[{ + [[{ "methods": ["POST"], "plugins": { "opa": { From 73738b7e879c7bc6d7c46d720437dbffe2f565c9 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Wed, 9 Oct 2024 07:45:17 +0200 Subject: [PATCH 10/22] fix linter issues --- apisix/plugins/opa/helper.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index c0650fc7a103..5369f52cab2a 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -39,11 +39,11 @@ local function get_body_for_request() if err ~= nil then error("opa - failed to get request body: ", err) end - if body == nil then + if original_body == nil then return nil end -- decode to prevent double encoded json objects - body, err = core.json.decode(original_body) + local body, err = core.json.decode(original_body) if err ~= nil then -- if its not json, the body can just be added body = original_body From cf69c83ee42174c7f47bb823d846203020c2d2bd Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Mon, 14 Oct 2024 07:14:24 +0200 Subject: [PATCH 11/22] change the error call --- apisix/plugins/opa/helper.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index 5369f52cab2a..648a9fea7375 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -37,7 +37,7 @@ end local function get_body_for_request() local original_body, err = core.request.get_body() if err ~= nil then - error("opa - failed to get request body: ", err) + error("opa - failed to get request body: " .. err) end if original_body == nil then return nil From 0b0e045c3014998a0f8b0250a5d90de2d0b171e0 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 7 Jan 2025 08:09:28 +0100 Subject: [PATCH 12/22] Update apisix/plugins/opa/helper.lua Co-authored-by: Ming Wen --- apisix/plugins/opa/helper.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index 648a9fea7375..59e3a8c35cca 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -63,7 +63,12 @@ local function build_http_request(conf, ctx) } if conf.with_body then - http.body = get_body_for_request() + local body, err = get_body_for_request() + if err then + core.log.warn(err) + else + http.body = body + end end return http From fdc9b53926b72182b6ebfda79127c28201855fd8 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Tue, 7 Jan 2025 08:09:38 +0100 Subject: [PATCH 13/22] Update apisix/plugins/opa/helper.lua Co-authored-by: Ming Wen --- apisix/plugins/opa/helper.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index 59e3a8c35cca..b798d9ac97eb 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -37,7 +37,7 @@ end local function get_body_for_request() local original_body, err = core.request.get_body() if err ~= nil then - error("opa - failed to get request body: " .. err) + return nil, "failed to get request body: " .. err end if original_body == nil then return nil From 6d1d6721ccbf8e189806b663046735a98e4445b9 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Mon, 31 Mar 2025 09:50:52 +0200 Subject: [PATCH 14/22] Update apisix/plugins/opa/helper.lua Co-authored-by: Baoyuan --- apisix/plugins/opa/helper.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index b798d9ac97eb..11d9e676b4f9 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -36,7 +36,7 @@ end local function get_body_for_request() local original_body, err = core.request.get_body() - if err ~= nil then + if err then return nil, "failed to get request body: " .. err end if original_body == nil then From 897599c3697edb5e81d6d7b1d55cbffbde9f18b3 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Mon, 31 Mar 2025 10:03:13 +0200 Subject: [PATCH 15/22] add docu and change log level --- apisix/plugins/opa/helper.lua | 2 +- docs/en/latest/plugins/opa.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apisix/plugins/opa/helper.lua b/apisix/plugins/opa/helper.lua index 11d9e676b4f9..7b7a4b9b3dee 100644 --- a/apisix/plugins/opa/helper.lua +++ b/apisix/plugins/opa/helper.lua @@ -65,7 +65,7 @@ local function build_http_request(conf, ctx) if conf.with_body then local body, err = get_body_for_request() if err then - core.log.warn(err) + core.log.error(err) else http.body = body end diff --git a/docs/en/latest/plugins/opa.md b/docs/en/latest/plugins/opa.md index 528b751153c8..f93beb7b0ad6 100644 --- a/docs/en/latest/plugins/opa.md +++ b/docs/en/latest/plugins/opa.md @@ -79,7 +79,8 @@ The JSON below shows the data sent to the OPA service by APISIX: }, "route": {}, "service": {}, - "consumer": {} + "consumer": {}, + "body": {} } ``` @@ -88,6 +89,7 @@ Each of these keys are explained below: - `type` indicates the request type (`http` or `stream`). - `request` is used when the `type` is `http` and contains the basic request information (URL, headers etc). - `var` contains the basic information about the requested connection (IP, port, request timestamp etc). +- `body` constains the http-body of the request - `route`, `service` and `consumer` contains the same data as stored in APISIX and are only sent if the `opa` Plugin is configured on these objects. ### OPA service to APISIX From f01ac3936eaf816acface8b3e5091671f7420854 Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Thu, 17 Apr 2025 12:51:57 +0200 Subject: [PATCH 16/22] fix typo --- docs/en/latest/plugins/opa.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/latest/plugins/opa.md b/docs/en/latest/plugins/opa.md index f93beb7b0ad6..6296812223c5 100644 --- a/docs/en/latest/plugins/opa.md +++ b/docs/en/latest/plugins/opa.md @@ -89,7 +89,7 @@ Each of these keys are explained below: - `type` indicates the request type (`http` or `stream`). - `request` is used when the `type` is `http` and contains the basic request information (URL, headers etc). - `var` contains the basic information about the requested connection (IP, port, request timestamp etc). -- `body` constains the http-body of the request +- `body` contains the http-body of the request - `route`, `service` and `consumer` contains the same data as stored in APISIX and are only sent if the `opa` Plugin is configured on these objects. ### OPA service to APISIX From c4fdd13f5a56b98db23d467ecdba50ead3c37332 Mon Sep 17 00:00:00 2001 From: LuciaCabanillasRodriguez Date: Mon, 9 Jun 2025 15:55:21 +0200 Subject: [PATCH 17/22] reindex opa3.t --- t/plugin/opa3.t | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/t/plugin/opa3.t b/t/plugin/opa3.t index 440bdd69b4d2..412a646e3038 100644 --- a/t/plugin/opa3.t +++ b/t/plugin/opa3.t @@ -32,7 +32,6 @@ run_tests(); __DATA__ - === TEST 1: setup route with plugin --- config location /t { @@ -68,12 +67,16 @@ __DATA__ --- response_body passed + + === TEST 2: hit route (with empty request) --- request POST /hello --- response_body hello world + + === TEST 3: hit route (with json request) --- request POST /hello @@ -83,6 +86,8 @@ POST /hello --- response_body hello world + + === TEST 4: hit route (with non-json request) --- request POST /hello From 463b92f004fdf9bd88f00158f970ec486d448263 Mon Sep 17 00:00:00 2001 From: LuciaCabanillasRodriguez Date: Wed, 25 Jun 2025 14:50:18 +0200 Subject: [PATCH 18/22] security warning --- docs/en/latest/plugins/opa.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/latest/plugins/opa.md b/docs/en/latest/plugins/opa.md index 6296812223c5..b047b63d8e20 100644 --- a/docs/en/latest/plugins/opa.md +++ b/docs/en/latest/plugins/opa.md @@ -46,7 +46,7 @@ The `opa` Plugin can be used to integrate with [Open Policy Agent (OPA)](https:/ | with_route | boolean | False | false | | When set to true, sends information about the current Route. | | with_service | boolean | False | false | | When set to true, sends information about the current Service. | | with_consumer | boolean | False | false | | When set to true, sends information about the current Consumer. Note that this may send sensitive information like the API key. Make sure to turn it on only when you are sure it is safe. | -| with_body | boolean | False | false | | When set to true, sends the request body. | +| with_body | boolean | False | false | | When set to true, sends the request body. Note that this may send sensitive information such as passwords or API keys. Make sure to enable it only if you understand the security implications. | ## Data definition From 8f6bd310e8381c829c9a7af7eb1f1cff462c7699 Mon Sep 17 00:00:00 2001 From: LuciaCabanillasRodriguez Date: Mon, 30 Jun 2025 09:33:10 +0200 Subject: [PATCH 19/22] updated Chinese documentation --- docs/zh/latest/plugins/opa.md | 100 +++++++++++++++++----------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/docs/zh/latest/plugins/opa.md b/docs/zh/latest/plugins/opa.md index a72a2f1a9520..d59839c62679 100644 --- a/docs/zh/latest/plugins/opa.md +++ b/docs/zh/latest/plugins/opa.md @@ -2,11 +2,11 @@ title: opa keywords: - Apache APISIX - - API 网关 - - Plugin + - API Gateway + - 插件 - Open Policy Agent - opa -description: 本篇文档介绍了 Apache APISIX 通过 opa 插件与 Open Policy Agent 对接的相关信息。 +description: 本文档包含有关 Apache APISIX opa 插件的信息。 ---