Skip to content

Commit

Permalink
✨ feat(envoy-proxy): Log HTTP request payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier97 committed Nov 22, 2023
1 parent 79446f3 commit ea1306b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/envoy-proxy/config/envoy-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/envoy-proxy/config/request-logger.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ea1306b

Please sign in to comment.