This packages contains a log field filter to extract the user from a basic Authorization HTTP-Header.
xcaddy build --with github.com/ueffel/caddy-basic-auth-filter
See caddy log filter documentation. There will be a new filters to use:
<field> basic_auth_user
- field Probably the only sensible field to use here is:
request>headers>Authorization
Since caddy v2.5.0 logging of credentials needs to be enabled in the global server
options with log_credentials
for
this filter to work. See caddyserver/caddy#4438.
The following example configuration uses the Formatted Log Encoder
format filter {
wrap formatted "{request>host} {request>headers>Authorization} [{ts}] \"{request>method} {request>uri} {request>proto}\""
fields {
request>headers>Authorization basic_auth_user
}
}
localhost admin [1620840157.514536] "GET /some/path HTTP/2.0"
For reference the configuration and output without filters:
format formatted "{request>host} {request>headers>Authorization} [{ts}] \"{request>method} {request>uri} {request>proto}\""
Log output:
localhost ["Basic YWRtaW46YWRtaW4="] [1638732239.578346] "GET /some/path HTTP/2.0"