Robinyo commented on issue #12374:
URL: https://github.com/apache/apisix/issues/12374#issuecomment-3064188370

   In the logs OPA is returned 200 (OK) but APISIX is returning 403:
   
   For example:
   
   ```
   opa                    | {
   opa                    |   "client_addr": "172.19.0.4:37546",
   opa                    |   "level": "info",
   opa                    |   "msg": "Received request.",
   opa                    |   "req_body": 
"{\"input\":{\"request\":{\"headers\":{\"connection\":\"keep-alive\",\"postman-token\":\"08ed1117-9537-4ad7-8b5c-42eb6da97f5c\",\"content-type\":\"application/json\",\"accept-encoding\":\"gzip,
 deflate, 
br\",\"cache-control\":\"no-cache\",\"user-agent\":\"PostmanRuntime/7.44.1\",\"accept\":\"*/*\",\"host\":\"provider-directory.au.localhost\"},\"query\":{\"_id\":\"adv-hearing-care\"},\"port\":9443,\"path\":\"/fhir/Organization\",\"scheme\":\"https\",\"method\":\"GET\",\"host\":\"provider-directory.au.localhost\"},\"var\":{\"server_addr\":\"172.19.0.4\",\"remote_addr\":\"172.19.0.1\",\"server_port\":\"9443\",\"remote_port\":\"56522\",\"timestamp\":1752274853},\"type\":\"http\"}}",
   opa                    |   "req_id": 36,
   opa                    |   "req_method": "POST",
   opa                    |   "req_params": {},
   opa                    |   "req_path": "/v1/data/organization",
   opa                    |   "time": "2025-07-11T23:00:53Z"
   opa                    | }
   opa                    | {
   opa                    |   "decision_id": 
"97dc5c0e-2d06-478e-9afa-9088b2c4bc66",
   opa                    |   "input": {
   opa                    |     "request": {
   opa                    |       "headers": {
   opa                    |         "accept": "*/*",
   opa                    |         "accept-encoding": "gzip, deflate, br",
   opa                    |         "cache-control": "no-cache",
   opa                    |         "connection": "keep-alive",
   opa                    |         "content-type": "application/json",
   opa                    |         "host": "provider-directory.au.localhost",
   opa                    |         "postman-token": 
"08ed1117-9537-4ad7-8b5c-42eb6da97f5c",
   opa                    |         "user-agent": "PostmanRuntime/7.44.1"
   opa                    |       },
   opa                    |       "host": "provider-directory.au.localhost",
   opa                    |       "method": "GET",
   opa                    |       "path": "/fhir/Organization",
   opa                    |       "port": 9443,
   opa                    |       "query": {
   opa                    |         "_id": "adv-hearing-care"
   opa                    |       },
   opa                    |       "scheme": "https"
   opa                    |     },
   opa                    |     "type": "http",
   opa                    |     "var": {
   opa                    |       "remote_addr": "172.19.0.1",
   opa                    |       "remote_port": "56522",
   opa                    |       "server_addr": "172.19.0.4",
   opa                    |       "server_port": "9443",
   opa                    |       "timestamp": 1752274853
   opa                    |     }
   opa                    |   },
   opa                    |   "labels": {
   opa                    |     "id": "a64fad56-c5b3-40d6-b6be-99cd3d80ff06",
   opa                    |     "version": "1.5.1"
   opa                    |   },
   opa                    |   "level": "info",
   opa                    |   "metrics": {
   opa                    |     "counter_server_query_cache_hit": 1,
   opa                    |     "timer_rego_external_resolve_ns": 250,
   opa                    |     "timer_rego_input_parse_ns": 664583,
   opa                    |     "timer_rego_query_eval_ns": 489209,
   opa                    |     "timer_server_handler_ns": 1644667
   opa                    |   },
   opa                    |   "msg": "Decision Log",
   opa                    |   "path": "organization",
   opa                    |   "req_id": 36,
   opa                    |   "requested_by": "172.19.0.4:37546",
   opa                    |   "result": {
   opa                    |     "request": {
   opa                    |       "method": "GET"
   opa                    |     },
   opa                    |     "result": {
   opa                    |       "allow": true,
   opa                    |       "reason": "request.method == GET"
   opa                    |     }
   opa                    |   },
   opa                    |   "time": "2025-07-11T23:00:53Z",
   opa                    |   "timestamp": "2025-07-11T23:00:53.903028339Z",
   opa                    |   "type": "openpolicyagent.org/decision_logs"
   opa                    | }
   opa                    | {
   opa                    |   "client_addr": "172.19.0.4:37546",
   opa                    |   "level": "info",
   opa                    |   "msg": "Sent response.",
   opa                    |   "req_id": 36,
   opa                    |   "req_method": "POST",
   opa                    |   "req_path": "/v1/data/organization",
   opa                    |   "resp_body": 
"{\"decision_id\":\"97dc5c0e-2d06-478e-9afa-9088b2c4bc66\",\"result\":{\"request\":{\"method\":\"GET\"},\"result\":{\"allow\":true,\"reason\":\"request.method
 == GET\"}}}\n",
   opa                    |   "resp_bytes": 150,
   opa                    |   "resp_duration": 4.565958,
   opa                    |   "resp_status": 200,
   opa                    |   "time": "2025-07-11T23:00:53Z"
   opa                    | }
   apisix                 | 172.19.0.1 - - [11/Jul/2025:23:00:53 +0000] 
provider-directory.au.localhost "GET /fhir/Organization?_id=adv-hearing-care 
HTTP/1.1" 403 225 0.021 "-" "PostmanRuntime/7.44.1" - - - 
"http://provider-directory.au.localhost";
   keycloak.au.localhost  | 2025-07-11 23:01:03,710 TRACE 
[io.vertx.ext.web.impl.RouterImpl] (vert.x-eventloop-thread-7) Router: 
192775273 accepting request GET https://hapi-fhir.au.localhost:9000/health/ready
   ```
   
   apisix-standalone.yml
   
   ```
     - name: provider-directory-api-organization-read
       uri: /fhir/Organization*
       methods: [ "GET" ]
       upstream_id: 1
       plugins:
         opa:
           host: "http://opa:8181";
           policy: "organization"
   ```
   
   policy
   
   ```
   package organization
   
   import rego.v1
   
   import input.request
   
   result := {
       "allow": true,
       "reason": "request.method == GET",
   } if {
        request.method == "GET"
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to