feature: Add client ip to inbound request information (#1678)

* feature: Add client ip to inbound request information
* feature (workers): Add the user's client IP to a session's connection information (#1749)
This commit is contained in:
Jim authored and GitHub committed 2021-12-09 20:41:08 -05:00
1 parent 2cfa027406
commit baa1d88f1f
36 files changed
+563 -169

No files matched your search

+8 -1
View File
@@ -11,6 +11,7 @@ import (
"github.com/hashicorp/boundary/internal/observability/event"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/go-secure-stdlib/base62"
"github.com/hashicorp/go-secure-stdlib/listenerutil"
)
// GeneratedTraceId returns a boundary generated TraceId or "" if an error occurs when generating
@@ -102,7 +103,7 @@ func WrapWithOptionals(ctx context.Context, with *writerWrapper, wrap http.Respo
// WrapWithEventsHandler will wrap the provided http.Handler with a
// handler that adds an Eventer to the request context and starts/flushes gated
// events of type: observation and audit
func WrapWithEventsHandler(h http.Handler, e *event.Eventer, kms *kms.Kms) (http.Handler, error) {
func WrapWithEventsHandler(h http.Handler, e *event.Eventer, kms *kms.Kms, listenerCfg *listenerutil.ListenerConfig) (http.Handler, error) {
const op = "common.WrapWithEventsHandler"
if h == nil {
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing handler")
@@ -124,12 +125,18 @@ func WrapWithEventsHandler(h http.Handler, e *event.Eventer, kms *kms.Kms) (http
event.WriteError(ctx, op, err, event.WithInfoMsg("unable to create id for event", "method", r.Method, "url", r.URL.RequestURI()))
return
}
clientIp, err := ClientIpFromRequest(ctx, listenerCfg, r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
event.WriteError(ctx, op, err, event.WithInfoMsg("unable to determine client ip"))
}
info := &event.RequestInfo{
EventId: id,
Id: GeneratedTraceId(ctx),
PublicId: publicId,
Method: r.Method,
Path: r.URL.RequestURI(),
ClientIp: clientIp,
}
ctx, err = event.NewRequestInfoContext(ctx, info)
if err != nil {