Skip to content
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

Merged
merged 5 commits into from
Sep 1, 2020

Conversation

kqdeng
Copy link
Contributor

@kqdeng kqdeng commented Aug 19, 2020

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?

  • integration tests
  • manual test

How are existing users impacted? What migration steps/scripts do we need?

No migration needed.

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@kqdeng kqdeng requested a review from a team August 19, 2020 20:03
@kqdeng kqdeng force-pushed the ENG-8083-trusted-proxies branch from f467cb9 to 76244dc Compare August 21, 2020 20:14
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 {
Copy link
Contributor

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.

Comment on lines +161 to +168
handler = xffmw.Handler(mux)
} else {
handler = mux
Copy link
Contributor

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
Comment on lines 121 to 123
// 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).
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♀️ thanks for catching that

@kqdeng kqdeng force-pushed the ENG-8083-trusted-proxies branch from b77e5d7 to 0beccbe Compare August 31, 2020 14:39
@kqdeng kqdeng force-pushed the ENG-8083-trusted-proxies branch from 0beccbe to 0de4348 Compare August 31, 2020 14:43
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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kqdeng kqdeng force-pushed the ENG-8083-trusted-proxies branch from 6a1749a to 884567e Compare September 1, 2020 13:51
@mmlb mmlb added the ready-to-merge Signal to Mergify to merge the PR. label Sep 1, 2020
@mergify mergify bot merged commit 4e05329 into tinkerbell:master Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge Signal to Mergify to merge the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants