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

Add XFF header for external-auth requests #2851

Closed
wants to merge 1 commit into from

Conversation

Miouge1
Copy link
Contributor

@Miouge1 Miouge1 commented Jul 26, 2018

What this PR does / why we need it:

The source IP of the request can be useful for the external-auth to make a decision.

Special notes for your reviewer:

fixes #2938

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 26, 2018
@antoineco
Copy link
Contributor

Thanks!

We should consider whether we really want to rewrite the header or rather append to it with $proxy_add_x_forwarded_for:
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#variables

Any opinion in favour or against it?

@Miouge1
Copy link
Contributor Author

Miouge1 commented Jul 26, 2018

I am not well versed with $proxy_add_x_forwarded_for, what would be appended to what?

On the server side of the external-auth, I would expect to see $remote_addr with the value of the ingress controller making the request and $http_x_forwarded_for the IP of the client making the original request.

@antoineco
Copy link
Contributor

antoineco commented Jul 26, 2018

Most web proxies append the IP address of the previous hop separated by a comma to the X-Forwarded-For header instead of replacing its value, as a friendly convention (this principle was also carried out to the more recent and standardized Forwarded header).

The rationale is that you can have a chain of web proxies and each of them can determine from the header:

  • the source IP of the request (client IP)
  • whether the last hop was in a trusted network

I said "friendly" because of course any proxy in the chain can deliberately spoof the header (like you did 🙂).

I found that page as the first Google result, but I know there are many others.

@ElvinEfendi
Copy link
Member

We should consider whether we really want to rewrite the header or rather append to it with $proxy_add_x_forwarded_for:

maybe we should follow what we have for main location block? i.e

            {{ if $all.Cfg.ComputeFullForwardedFor }}
            {{ $proxySetHeader }} X-Forwarded-For        $full_x_forwarded_for;
            {{ else }}
            {{ $proxySetHeader }} X-Forwarded-For        $the_real_ip;
            {{ end }}

here $full_x_forwarded_for will have the whole proxy chain included (see how it's being computed in nginx.tmpl)

@antoineco
Copy link
Contributor

Even better, let's be consistent.

@antoineco
Copy link
Contributor

@Miouge1 does the solution suggested by @ElvinEfendi sound good to you?

@aledbf
Copy link
Member

aledbf commented Aug 23, 2018

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 23, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aledbf, Miouge1

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 23, 2018
@aledbf
Copy link
Member

aledbf commented Aug 23, 2018

This PR also fixes #2938

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
5 participants