mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-03 00:40:25 +02:00
log subset of headers
This commit is contained in:
parent
5d86c84978
commit
5039c00e27
7 changed files with 134 additions and 39 deletions
|
@ -1,7 +1,6 @@
|
|||
package controlplane
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
envoy_data_accesslog_v3 "github.com/envoyproxy/go-control-plane/envoy/data/accesslog/v3"
|
||||
|
@ -25,7 +24,6 @@ func (srv *Server) StreamAccessLogs(stream envoy_service_accesslog_v3.AccessLogS
|
|||
}
|
||||
|
||||
for _, entry := range msg.GetHttpLogs().LogEntry {
|
||||
requestHeaders := getRequestHeaders(entry)
|
||||
reqPath := entry.GetRequest().GetPath()
|
||||
var evt *zerolog.Event
|
||||
if reqPath == "/ping" || reqPath == "/healthz" {
|
||||
|
@ -34,9 +32,12 @@ func (srv *Server) StreamAccessLogs(stream envoy_service_accesslog_v3.AccessLogS
|
|||
evt = log.Info(stream.Context())
|
||||
}
|
||||
evt = evt.Str("service", "envoy")
|
||||
for _, field := range srv.currentConfig.Load().Config.Options.GetAccessLogFields() {
|
||||
evt = populateLogEvent(field, evt, entry, requestHeaders)
|
||||
|
||||
fields := srv.currentConfig.Load().Config.Options.GetAccessLogFields()
|
||||
for _, field := range fields {
|
||||
evt = populateLogEvent(field, evt, entry)
|
||||
}
|
||||
evt = log.HTTPHeaders(evt, fields, entry.GetRequest().GetRequestHeaders())
|
||||
evt.Msg("http-request")
|
||||
}
|
||||
}
|
||||
|
@ -46,12 +47,7 @@ func populateLogEvent(
|
|||
field log.AccessLogField,
|
||||
evt *zerolog.Event,
|
||||
entry *envoy_data_accesslog_v3.HTTPAccessLogEntry,
|
||||
requestHeaders map[string]string,
|
||||
) *zerolog.Event {
|
||||
if headerName, ok := field.IsForHeader(); ok {
|
||||
return evt.Str("header."+headerName, requestHeaders[http.CanonicalHeaderKey(headerName)])
|
||||
}
|
||||
|
||||
switch field {
|
||||
case log.AccessLogFieldAuthority:
|
||||
return evt.Str(string(field), entry.GetRequest().GetAuthority())
|
||||
|
@ -83,14 +79,6 @@ func populateLogEvent(
|
|||
}
|
||||
}
|
||||
|
||||
func getRequestHeaders(entry *envoy_data_accesslog_v3.HTTPAccessLogEntry) map[string]string {
|
||||
m := map[string]string{}
|
||||
for k, v := range entry.GetRequest().GetRequestHeaders() {
|
||||
m[http.CanonicalHeaderKey(k)] = v
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func stripQueryString(str string) string {
|
||||
if idx := strings.Index(str, "?"); idx != -1 {
|
||||
str = str[:idx]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue