From 79446f378b0f878b72901bef50c98c970235979e Mon Sep 17 00:00:00 2001 From: Olivier Karasangabo Date: Tue, 14 Nov 2023 12:41:58 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20feat(envoy-proxy):=20Enable=20a?= =?UTF-8?q?ccess=20logging=20for=20HTTP=20requests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/envoy-proxy/config/envoy-config.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/envoy-proxy/config/envoy-config.yaml b/src/envoy-proxy/config/envoy-config.yaml index e265ac5a..2a53eb34 100644 --- a/src/envoy-proxy/config/envoy-config.yaml +++ b/src/envoy-proxy/config/envoy-config.yaml @@ -38,6 +38,18 @@ static_resources: - name: envoy.access_loggers.stdout typed_config: "@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog + log_format: + json_format: + content_type: "%REQ(Content-Type)%" + downstream_remote_address: "%DOWNSTREAM_REMOTE_ADDRESS%" + hostname: "%HOSTNAME%" + message: "%LOCAL_REPLY_BODY%" + original_path: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%" + response_code: "%RESPONSE_CODE%" + response_code_details: "%RESPONSE_CODE_DETAILS%" + timestamp: "%START_TIME%" + upstream_remote_address: "%UPSTREAM_REMOTE_ADDRESS%" + user_agent: "%REQ(User-Agent)%" http_filters: - name: envoy.filters.http.router typed_config: From ea1306bf5977ca659071de309c022dd16184a1c1 Mon Sep 17 00:00:00 2001 From: Olivier Karasangabo Date: Tue, 14 Nov 2023 12:46:46 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20feat(envoy-proxy):=20Log=20HTTP?= =?UTF-8?q?=20request=20payloads?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/envoy-proxy/config/envoy-config.yaml | 10 ++++++++++ src/envoy-proxy/config/request-logger.lua | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/envoy-proxy/config/request-logger.lua diff --git a/src/envoy-proxy/config/envoy-config.yaml b/src/envoy-proxy/config/envoy-config.yaml index 2a53eb34..399752e5 100644 --- a/src/envoy-proxy/config/envoy-config.yaml +++ b/src/envoy-proxy/config/envoy-config.yaml @@ -50,7 +50,17 @@ static_resources: timestamp: "%START_TIME%" upstream_remote_address: "%UPSTREAM_REMOTE_ADDRESS%" user_agent: "%REQ(User-Agent)%" + payload: "%DYNAMIC_METADATA(envoy.filters.http.lua.request-filter:payload)%" http_filters: + - name: envoy.filters.http.lua + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua + default_source_code: + inline_string: | + local request_logger = require("/etc/envoy/unguard/request-logger") + function envoy_on_request(request_handle) + request_logger.log_payload(request_handle) + end - name: envoy.filters.http.router typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router diff --git a/src/envoy-proxy/config/request-logger.lua b/src/envoy-proxy/config/request-logger.lua new file mode 100644 index 00000000..e172c00d --- /dev/null +++ b/src/envoy-proxy/config/request-logger.lua @@ -0,0 +1,16 @@ +local request_logger = {} + +function request_logger.log_payload(handle) + local payload = "" + for chunk in handle:bodyChunks() do + local chunk_length = chunk:length() + if (chunk_length > 0) then + payload = payload .. chunk:getBytes(0, chunk_length) + end + end + payload = tostring(payload) + handle:streamInfo():dynamicMetadata():set("envoy.filters.http.lua.request-filter", "payload", payload) + return payload +end + +return request_logger