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 force-enable-realip-module #5887

Merged
merged 1 commit into from
Jul 17, 2020

Conversation

dschwar
Copy link
Contributor

@dschwar dschwar commented Jul 13, 2020

What this PR does / why we need it:

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Which issue/s this PR fixes

How Has This Been Tested?

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 13, 2020
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jul 13, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @dschwar!

It looks like this is your first PR to kubernetes/ingress-nginx 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/ingress-nginx has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @dschwar. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 13, 2020
@ElvinEfendi
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 13, 2020
@dschwar
Copy link
Contributor Author

dschwar commented Jul 13, 2020

/check-cla

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 13, 2020
@ElvinEfendi
Copy link
Member

ElvinEfendi commented Jul 13, 2020

@aledbf what do you think of the naming? The idea here is to be able to control enablement of Real IP module independent UseForwardedHeaders and Proxy Protocol. Because sometimes we need to configure Real IP module only, but not trust X-Forwarded-Host and X-Forwarded-Proto headers.

@ElvinEfendi
Copy link
Member

@dschwar can you also add another test case that tests this new setting in combination with UseForwardedHeaders setting?

@ElvinEfendi
Copy link
Member

@dschwar we will also need a docs adjustment once we agree on the change.

Alternative to this would be relying on https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#proxy-real-ip-cidr to toggle the configuration of Real IP module. But that would be implicit and would introduce backward incompatibility.

@ElvinEfendi
Copy link
Member

Given we have proxy-real-ip-cidr, let's keep the new name as close to it as possible, so let's call it enable-real-ip instead.

Also @dschwar I think it would be a lot cleaner to implement @XaF's idea about setting the value of EnableRealIp attribute base on the values of UseForwardedHeaders and UseProxyProtocol. Then in the template we can simply do if $cfg.EnableRealIp.

Once these two things are addressed we can merge this PR (you will also need to squash the commits).

@dschwar
Copy link
Contributor Author

dschwar commented Jul 15, 2020

Also @dschwar I think it would be a lot cleaner to implement @XaF's idea about setting the value of EnableRealIp attribute base on the values of UseForwardedHeaders and UseProxyProtocol. Then in the template we can simply do if $cfg.EnableRealIp.

I played around with this and I feel like it introduces a lot of complexity and fragility to determine if we should enable realip. I'd prefer not to go with this.

We'd end up with code like

	if val, ok := conf[useForwardedHeaders]; ok {
		b, _ := strconv.ParseBool(val)
		if b {
			shouldEnableRealIp = true
		}
	}

	if val, ok := conf[useProxyProtocol]; ok {
		b, _ := strconv.ParseBool(val)
		if b {
			shouldEnableRealIp = true
		}
	}

	if val, ok := conf[enableRealIp]; ok {
		b, _ := strconv.ParseBool(val)
		if shouldEnableRealIp || b {
			delete(conf, enableRealIp)
		}
		if b {
			shouldEnableRealIp = true
		}
	}

which isn't cleaner IMO.

@dschwar dschwar force-pushed the force-use-forwarded-for branch 3 times, most recently from 75d0aed to 4a5536b Compare July 15, 2020 16:23
@@ -712,6 +715,7 @@ func NewDefault() Configuration {
EnableUnderscoresInHeaders: false,
ErrorLogLevel: errorLevel,
UseForwardedHeaders: false,
EnableRealIp: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is needed, @ElvinEfendi can you confirm?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we want to default this to false. (It probably defaults to false when unset but better be explicit)

@dschwar dschwar force-pushed the force-use-forwarded-for branch 2 times, most recently from 3448126 to 21c3620 Compare July 15, 2020 17:52
@dschwar dschwar marked this pull request as ready for review July 15, 2020 19:36
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 15, 2020
@ElvinEfendi
Copy link
Member

/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 Jul 15, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dschwar, ElvinEfendi

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 Jul 15, 2020
@aledbf
Copy link
Member

aledbf commented Jul 15, 2020

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 15, 2020
@aledbf
Copy link
Member

aledbf commented Jul 15, 2020

I will remove the hold after the 0.34.1 release

@ElvinEfendi
Copy link
Member

I will remove the hold after the 0.34.1 release

@aledbf assuming this release is for the bug fix and will happen shortly?

@aledbf
Copy link
Member

aledbf commented Jul 15, 2020

@aledbf assuming this release is for the bug fix and will happen shortly?

Yes

@XaF
Copy link

XaF commented Jul 15, 2020

I played around with this and I feel like it introduces a lot of complexity and fragility to determine if we should enable realip. I'd prefer not to go with this.

I usually prefer logic in code than in templates. Code is for logic, templates not as much. Wouldn't a loop solve the readability complexity here?

enableRealIpParameters := []..{useForwardedHeaders, useProxyProtocol, enableRealIp}
shouldEnableRealIp := false
for _, parameter := range enableRealIpParameters {
  if val, ok := conf[parameter]; ok {
    b, _ := strconv.ParseBool(val)
    if b {
      shouldEnableRealIp = true
    }
  }
}

Not feeling too strongly about this though, as long as the feature is there!

@dschwar
Copy link
Contributor Author

dschwar commented Jul 16, 2020

@aledbf it looks like 0.34.1 has been released, can we merge this?

@aledbf
Copy link
Member

aledbf commented Jul 17, 2020

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 17, 2020
@k8s-ci-robot k8s-ci-robot merged commit e825af8 into kubernetes:master Jul 17, 2020
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants