-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENG-8083 trusted proxies #27
Conversation
f467cb9
to
76244dc
Compare
xff/xff.go
Outdated
@@ -148,3 +147,21 @@ func New(l log.Logger, allowedSubnets []string) (grpc.StreamServerInterceptor, g | |||
} | |||
return streamer, unaryer | |||
} | |||
|
|||
func XFFHandler(l log.Logger, mux *http.ServeMux, allowedSubnets []string) http.Handler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe HTTPHandler makes more sense.
handler = xffmw.Handler(mux) | ||
} else { | ||
handler = mux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to handle mux
being nil and then using http.DefaultServeMux
xff/xff.go
Outdated
// New returns a set of grpc interceptors that will replace peer.IP with X-FORWARDED-FOR value if the peer ip within a subnet in allowedSubnets | ||
// If allowedSubnets is nil it will look for subents in the TRUSTED_PROXIES env var. | ||
// If allowedSubnets is nil and TRUSTED_PROXIES is empty then X-FORWARDED-FOR will be ignored (no proxy is trusted). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment needs updating with the new name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♀️ thanks for catching that
b77e5d7
to
0beccbe
Compare
Signed-off-by: Kelly Deng <[email protected]>
Signed-off-by: Kelly Deng <[email protected]>
Signed-off-by: Kelly Deng <[email protected]>
Signed-off-by: Kelly Deng <[email protected]>
0beccbe
to
0de4348
Compare
xff/xff.go
Outdated
@@ -118,8 +118,8 @@ func ParseTrustedProxies() []string { | |||
return result | |||
} | |||
|
|||
// New returns a set of grpc interceptors that will replace peer.IP with X-FORWARDED-FOR value if the peer ip within a subnet in allowedSubnets | |||
// If allowedSubnets is nil it will look for subents in the TRUSTED_PROXIES env var. | |||
// GRPCMiddlewares returns a set of grpc interceptors that will replace peer.IP with X-FORWARDED-FOR value if the peer ip within a subnet in allowedSubnets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I just noticed some grammatical issue here from before, can you fix though? Maybe to read like:
if the peer IP is within one of the subents in allowedSubnets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Kelly Deng <[email protected]>
6a1749a
to
884567e
Compare
Description
Handles the case when hegel is running behind a reverse proxy.
This was already handled for the grpc endpoints, so this pr is specifically for the http endpoints.
Why is this needed
Hegel looks up the remote user ip from the request, then passes that ip to retrieve the associated piece of hardware. If hegel is behind a proxy, then the remote user ip will be the proxy's ip (and hegel won't be able to get the correct piece of hardware).
Fixes: #
How Has This Been Tested?
How are existing users impacted? What migration steps/scripts do we need?
No migration needed.
Checklist:
I have: