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

reverse proxy: use Rewrite instead of Director #324

Open
wants to merge 1 commit into
base: sig-auth-acceptance
Choose a base branch
from

Conversation

stlaz
Copy link
Collaborator

@stlaz stlaz commented Nov 14, 2024

This is to mitigate Golang's behavior with ReverseProxy.Director when, after the outgoing request is mutated, any headers specified by "Connection" would get rmoved from the mutated request. ReverseProxy.Rewrite() is only called once the headers specified in "Connection" were already removed from the outgoing-to-be request.

Fixes #319

edit: useful resources for more context:

This is to mitigate Golang's behavior with `ReverseProxy.Director`
when, after the outgoing request is mutated, any headers specified by
"Connection" would get rmoved from the mutated request.
`ReverseProxy.Rewrite()` is only called once the headers specified in
"Connection" were already removed from the outgoing-to-be request.
@stlaz stlaz added the sig-auth-acceptance issues created during review for sig-auth-acceptance label Nov 14, 2024
@stlaz stlaz self-assigned this Nov 14, 2024
target := cfg.KubeRBACProxyInfo.UpstreamURL
pr.SetURL(target)
pr.Out.Host = target.Host
copyHeaderIfSet(pr.In, pr.Out, "X-Forwarded-For")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it make sense to add the IP address of the client, if not already set?

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For#syntax

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pr.SetXForwarded() does that but only if X-Forwarded-For is already set

Rewrite: func(pr *httputil.ProxyRequest) {
target := cfg.KubeRBACProxyInfo.UpstreamURL
pr.SetURL(target)
pr.Out.Host = target.Host
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you set it, after rewrite removed it? To keep the same behavior as with the Director?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I meant to keep the behavior the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig-auth-acceptance issues created during review for sig-auth-acceptance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants