From be2538aca3d3dbaa44a8310d441808a7a6620e8a Mon Sep 17 00:00:00 2001 From: Jonathan Sokolowski Date: Wed, 20 May 2015 15:23:41 +1000 Subject: [PATCH] http: Extract IP from RemoteAddr correctly --- http/logical.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/http/logical.go b/http/logical.go index 48bf4ed6a..c9e842e62 100644 --- a/http/logical.go +++ b/http/logical.go @@ -2,6 +2,7 @@ package http import ( "io" + "net" "net/http" "strings" "time" @@ -53,6 +54,13 @@ func handleLogical(core *vault.Core) http.Handler { } } + // http.Server will set RemoteAddr to an "IP:port" string + var remoteAddr string + remoteAddr, _, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + remoteAddr = "" + } + // Make the internal request. We attach the connection info // as well in case this is an authentication request that requires // it. Vault core handles stripping this if we need to. @@ -61,7 +69,7 @@ func handleLogical(core *vault.Core) http.Handler { Path: path, Data: req, Connection: &logical.Connection{ - RemoteAddr: r.RemoteAddr, + RemoteAddr: remoteAddr, ConnState: r.TLS, }, }))