-
Notifications
You must be signed in to change notification settings - Fork 8.4k
modsecurity: Including custom rules file throws error #11531
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
Comments
This issue is currently awaiting triage. If Ingress contributors determines this is a relevant issue, they will accept it by applying the The 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-sigs/prow repository. |
/remove-kind bug
So fix that issue description and see if you get comments based on useful data (if any) |
@longwuyuan Thank you for your feedback. I updated format and content of the issue description. |
The error visible is
does your file have ID ? |
@longwuyuan Yes. The error message refers to the rule id, as I understand it. All rules in the file have a rule id, and the same ruleset works, if I put it in the modsecurity-snippet inside the ingress instance. That's why I assume that the file is not readable. |
If you follow documentation, I can understand what you are trying and work with you. for example follow these
But this is a absolute requirement
Next show the volume mounted but do not use the custom-rules. I want to see the volumes only And then I too can debug the actual error of not being able to use the custom-rulesets from a volume I can join a meet.jit.si session. We can sync on slack |
@longwuyuan Thank you. I will prepare and get back to you. |
thank you |
/triage needs-information |
@longwuyuan Thanks for your help. I try to answer your questions beforehand:
I followed the documentation and configured modsecurity like explained in these docs.
Failed to save resource: admission webhook "validate.nginx.ingress.kubernetes.io" denied the request:
-------------------------------------------------------------------------------
Error: exit status 1
2024/07/16 09:47:21 [emerg] 2357#2357: too long parameter, probably missing terminating "'" character in /tmp/nginx/nginx-cfg939531444:3640
nginx: [emerg] too long parameter, probably missing terminating "'" character in /tmp/nginx/nginx-cfg939531444:3640
nginx: configuration file /tmp/nginx/nginx-cfg939531444 test failed As described in owasp-modsecurity/ModSecurity-nginx#210, nginx has a line limit of 4096 bytes in the configuration file: https://github.com/nginx/nginx/blob/master/src/core/ngx_conf_file.c
...
spec:
volumes:
- name: webhook-cert
secret:
secretName: ingress-nginx-admission
defaultMode: 420
- name: modsecurity-config-custom-default-ruleset-volume
configMap:
name: ingress-nginx-controller
defaultMode: 420
- name: modsecurity-config-custom-extended-ruleset-volume
configMap:
name: ingress-nginx-controller
defaultMode: 420
- name: modsecurity-config-custom-rule-removals-volume
configMap:
name: ingress-nginx-controller
defaultMode: 420
containers:
- volumeMounts:
- name: webhook-cert
readOnly: true
mountPath: /usr/local/certificates/
- name: modsecurity-config-custom-default-ruleset-volume
mountPath: /etc/modsecurity-rules/default.conf
subPath: custom-default-ruleset
- name: modsecurity-config-custom-extended-ruleset-volume
mountPath: /etc/modsecurity-rules/extended.conf
subPath: custom-extended-ruleset
- name: modsecurity-config-custom-rule-removals-volume
mountPath: /etc/modsecurity-rules/removals.conf
subPath: custom-rule-removals
...
Great. How can I reach you? |
I am on Kubernetes Slack in the ingress-nginx-users channel |
I need an invitation, right? Sry, I am not familiar with Slack... |
channel ingress-nginx |
Problem could be resolved. My rulesets still contained the escaping \ for the quotation marks, that are necessary in the modsecurity-snippet. |
What happened:
As the annotation
nginx.ingress.kubernetes.io/modsecurity-snippet
has a limited length (afaik 4000 Bytes) and our ruleset has grown and exceeds that limit, I've been trying to centralize our ruleset.So, I put our custom rulesets in the configmap und mounted them into ingress as a volume:
Configmap
Extract from the deployment
That works fine, the files are correctly mounted in the pod.
Now I try to include the different files in the single ingress instance:
As soon as I tried to rollout that, I get the following error:
Error: exit status 1
2024/07/02 07:31:01 [emerg] 2863#2863: "modsecurity_rules_file" directive Rules must have an ID. File: 0x7f791d3180f0 at line: 1
in /tmp/nginx/nginx-cfg2299842162:3548
nginx: [emerg] "modsecurity_rules_file" directive Rules must have an ID. File: 0x7f791d3180f0 at line: 1
in /tmp/nginx/nginx-cfg2299842162:3548
nginx: configuration file /tmp/nginx/nginx-cfg2299842162 test failed
As you notice above, I manually configured modsecurity. I tried that because the standard way using "modsecurity-snippet" did not work as well. It threw the same error, as soon as I added the "Include"-statement.
If I include an existing modsecurity standard config file like /etc/nginx/modsecurity/modsecurity.conf, it works. That's why I assume, that the problem is maybe due to file permissions. The conf-Files I mount from the configmap belong to user root. Well, that's only an assumption, as I tried different variations.
I can rule out problems with my rules. If I put the rules inside the modsecurity-Snippet-Block of the single ingress instance, they work perfectly fine.
ingress-nginx Helm-Chart-Version: 4.10.0
What you expected to happen:
Rules should be loaded and applied for the ingress instance.
NGINX Ingress controller version
NGINX Ingress controller
Release: v1.10.0
Build: 71f78d4
Repository: https://github.com/kubernetes/ingress-nginx
nginx version: nginx/1.25.3
Kubernetes version
v1.28.5
Environment:
helm ls -A | grep -i ingress
ingress-nginx kube-system 23 2024-06-12 12:10:00.920865595 +0200 CEST deployed ingress-nginx-4.10.0 1.10.0
helm -n <ingresscontrollernamespace> get values <helmreleasename>
kubectl describe ingressclasses
kubectl -n <ingresscontrollernamespace> describe po <ingresscontrollerpodname>
kubectl -n <ingresscontrollernamespace> describe svc <ingresscontrollerservicename>
kubectl -n <appnamespace> describe ing <ingressname>
How to reproduce this issue:
Install ingress-nginx via Helm-Chart version 4.10.0
Set USER-SUPPLIED-VALUES as defined above
Activate modsecurity and include custom rules file through annotation
nginx.ingress.kubernetes.io/modsecurity-snippet
Anything else we need to know:
Investigating the issue, I stumbled upon the following issues:
#8388 > gave me the idea of configuring modsecurity manually
#5673 > gave me the idea of centralizing my rulesets
owasp-modsecurity/ModSecurity-nginx#210 > gave me the information that the snipped length is limited to 4096 bytes, which I can also reproduce
The text was updated successfully, but these errors were encountered: