Capture request/response bodies for audit-log via pre/post-function

Body capture lives in dedicated audit-log-body-capture(-bindings).yaml
files, separate from audit-log.yaml itself, so they can be dropped
without touching the base logging plugin (degrades gracefully to
metadata-only via nil custom_fields). Response body captured in
body_filter (chunk-accumulated) rather than the log phase, which
cannot call kong.response.get_raw_body() directly.
This commit is contained in:
Stéphane Tailland
2026-08-21 14:53:52 +02:00
parent 1c46f9b447
commit 95f9b611b3
7 changed files with 140 additions and 2 deletions
+6 -1
View File
@@ -5,8 +5,13 @@ metadata:
namespace: ${NAMESPACE}
plugin: http-log
# dev only: the raw Authorization (JWT) header is captured in clear text,
# not acceptable as-is for a non-dev environment.
# not acceptable as-is for a non-dev environment. request_body/response_body
# below read from kong.ctx.shared, populated by audit-log-body-capture.yaml
# — nil (and silently omitted) if that file isn't applied.
config:
http_endpoint: ${AUDIT_LOG_ENDPOINT}
method: POST
content_type: application/json
custom_fields_by_lua:
request_body: "return kong.ctx.shared.audit_request_body"
response_body: "return kong.ctx.shared.audit_response_body"