2

For regulatory purposes, I'm trying to log the entire response when using the nginx ingress controller for Kubernetes. From looking at the documentation and other answers here, I'm using the body_filter_by_lua_block directive.

My configmap for setting this up looks like this

apiVersion: v1
kind: ConfigMap
metadata:
 name: nginx-configuration
 namespace: ingress-nginx
 labels:
   app.kubernetes.io/name: ingress-nginx
   app.kubernetes.io/part-of: ingress-nginx
data:
 server-snippet: | 
   lua_need_request_body on;

   set $resp_body '';
   body_filter_by_lua_block {
       local resp_body = string.sub(ngx.arg[1], 1, 1000)
       ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body
       if ngx.arg[2] then
           ngx.var.resp_body = ngx.ctx.buffered
       end
   }
 log-format-upstream: |
   Response body: $resp_body

When a request is received, the following is logged:

Response body:

It seems the $resp_body is empty. I have a suspicion that this might be related to the body_filter_by_lua_block running later than the logging, however, it should run in the content phase whereas the logging should be in the later logging phase.

I'm probably missing something obvious here - but I think I've tried most combinations.

mhermann
  • 21
  • 3
  • I'm coming to the realization that this might be related to the fact that the ingress controller uses proxy_pass – mhermann Aug 26 '20 at 07:52

0 Answers0