···152152 NodeID int `toml:"node-id"`
153153 // Whether audit reports should be stored whenever an audit event occurs.
154154 Collect bool `toml:"collect"`
155155- // Whether audit reports should include principal's IP address.
156156- IncludeIPs bool `toml:"include-ip"`
155155+ // If not empty, includes the principal's IP address in audit reports, with the value specifying
156156+ // the source of the IP address. If the value is "X-Forwarded-For", the last item of the
157157+ // corresponding header field (assumed to be comma-separated) is used. If the value is
158158+ // "RemoteAddr", the connecting host's address is used. Any other value is disallowed.
159159+ IncludeIPs string `toml:"include-ip"`
157160 // Endpoint to notify with a `GET /<notify-url>?<id>` whenever an audit event occurs.
158161 NotifyURL *URL `toml:"notify-url"`
159162}
···132132133133func serve(ctx context.Context, listener net.Listener, handler http.Handler) {
134134 if listener != nil {
135135- handler = panicHandler(handler)
136136-137135 server := http.Server{Handler: handler}
138136 server.Protocols = new(http.Protocols)
139137 server.Protocols.SetHTTP1(true)
···537535 }
538536 backend = NewObservedBackend(backend)
539537540540- go serve(ctx, pagesListener, ObserveHTTPHandler(http.HandlerFunc(ServePages)))
541541- go serve(ctx, caddyListener, ObserveHTTPHandler(http.HandlerFunc(ServeCaddy)))
538538+ middleware := chainHTTPMiddleware(
539539+ panicHandler,
540540+ remoteAddrMiddleware,
541541+ ObserveHTTPHandler,
542542+ )
543543+ go serve(ctx, pagesListener, middleware(http.HandlerFunc(ServePages)))
544544+ go serve(ctx, caddyListener, middleware(http.HandlerFunc(ServeCaddy)))
542545 go serve(ctx, metricsListener, promhttp.Handler())
543546544547 if config.Insecure {
+2-5
src/pages.go
···99 "fmt"
1010 "io"
1111 "maps"
1212- "net"
1312 "net/http"
1413 "net/url"
1514 "os"
···802801803802func ServePages(w http.ResponseWriter, r *http.Request) {
804803 r = r.WithContext(WithPrincipal(r.Context()))
805805- if config.Audit.IncludeIPs {
806806- if ipAddress, _, err := net.SplitHostPort(r.RemoteAddr); err == nil {
807807- GetPrincipal(r.Context()).IpAddress = proto.String(ipAddress)
808808- }
804804+ if config.Audit.IncludeIPs != "" {
805805+ GetPrincipal(r.Context()).IpAddress = proto.String(r.RemoteAddr)
809806 }
810807 // We want upstream health checks to be done as closely to the normal flow as possible;
811808 // any intentional deviation is an opportunity to miss an issue that will affect our