-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Provide possibility to block IPs, User-Agents and Referers globally #2997
Provide possibility to block IPs, User-Agents and Referers globally #2997
Conversation
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. |
@spa-87 please add e2e tests |
@spa-87 also, please sign the CLA :) |
Codecov Report
@@ Coverage Diff @@
## master #2997 +/- ##
==========================================
+ Coverage 47.54% 47.56% +0.01%
==========================================
Files 77 77
Lines 5639 5658 +19
==========================================
+ Hits 2681 2691 +10
- Misses 2605 2611 +6
- Partials 353 356 +3
Continue to review full report at Codecov.
|
All of these are already possible using https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#lua-resty-waf specifically I know the rule language is not the best but IMO we should not be introducing yet another logic to do the same thing. UPDATE: spoke too early. lua-resty-waf is only per location, not global. |
While I share this, I think we cannot say learn this new thing to "just" add a deny section. If we don't merge this then we need to provide such examples using the lua waf module |
@aledbf that makes sense. Also updated my PR, I overlooked the fact that this PR is providing a way to block globally. |
Hey @aledbf, e2e tests are added and CLA is signed. |
@ElvinEfendi yep, the main difference of the current PR is to provide a possibility to block requests globally for the whole cluster. |
@spa-87 We are doing something quite similar and that should already be possible utilizing the global And a further alternative might be the modsecurity integration - do not have too much experience with it but it is on our roadmap to experiment with it a bit more. |
Get(f.IngressController.HTTPURL). | ||
Set("Host", host). | ||
End() | ||
Expect(len(errs)).Should(BeNumerically("==", 0)) |
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.
This doesn't print the content of the returned error(s), making it hard to troubleshoot from my experience.
Expect(errs).To(BeNil())
does print the content of the errors and is equally valid.
I know we have been abusing this in other tests, but it's never too late to start improving our tests :)
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.
Hey @antoineco , done
@Globegitter yeah, you're right. I missed those configs initially. But now I'm able to achieve the same behavior using |
@spa-87 these new parameters makes sense. Let me test this |
@@ -533,12 +533,22 @@ type Configuration struct { | |||
|
|||
// Checksum contains a checksum of the configmap configuration | |||
Checksum string `json:"-"` | |||
|
|||
// Block all requests from given IPs | |||
BlockIps []string `json:"block-ips"` |
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.
Please change to
BlockCIDRs []string `json:"block-cidrs"`
BlockIps []string `json:"block-ips"` | ||
|
||
// Block all requests with given User-Agent headers | ||
BlockUas []string `json:"block-user-agents"` |
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.
BlockUserAgents
BlockUas []string `json:"block-user-agents"` | ||
|
||
// Block all requests with given Referer headers | ||
BlockRefs []string `json:"block-referers"` |
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.
BlockReferers
@spa-87 first, apologies for the delay. Just some comments about the naming. If you change that we are ok to merge |
Hey @aledbf, no problem with the delay :) |
/lgtm |
@spa-87 thanks! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aledbf, spa-87 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 |
|
||
## block-referers | ||
|
||
A comma-separated list of Referers, requestst from which have to be blocked globally. |
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.
A comma-separated list of Referers, requestst from which have to be blocked globally. | |
A comma-separated list of Referers, requests from which have to be blocked globally. |
Current PR implements possibility to block requests globally based on:
It can be useful for many use-cases: