ModSecurity is an open-source Web Application Firewall (WAF) designed to protect web applications from malicious attacks. It is maintained by the open-source community and supports various programming languages and web servers. The platform Load Balancer (ALB) supports configuring ModSecurity, allowing for individual configurations at the Ingress level.
Term | Explanation |
---|---|
owasp-core-rules | The OWASP Core Rule Set is an open-source ruleset used to detect and prevent common web application attacks. |
Configure ModSecurity by adding annotations to the corresponding resource's YAML file or by configuring CR.
Add the following annotations to the metadata.annotations field of the corresponding YAML file to configure ModSecurity.
Ingress-Nginx Compatible Annotations
Annotation | Type | Applicable Object | Explanation |
---|---|---|---|
nginx.ingress.kubernetes.io/enable-modsecurity | bool | Ingress | Enable ModSecurity. |
nginx.ingress.kubernetes.io/enable-owasp-core-rules | bool | Ingress | Enable the OWASP Core Rule Set. |
nginx.ingress.kubernetes.io/modsecurity-transaction-id | string | Ingress | Used to identify unique transaction IDs for each request, aiding in logging and debugging. |
nginx.ingress.kubernetes.io/modsecurity-snippet | string | Ingress, ALB, FT, Rule | Allows users to insert custom ModSecurity configurations to meet specific security requirements. |
ALB Special Annotations
Annotation | Type | Applicable Object | Explanation |
---|---|---|---|
alb.modsecurity.cpaas.io/use-recommend | bool | Ingress | Enable or disable recommended ModSecurity rules; set to true to apply a predefined set of security rules. |
alb.modsecurity.cpaas.io/cmref | string | Ingress | Reference specific configurations, e.g., custom security configurations can be loaded by specifying the ConfigMap's reference path ($ns/$name#$section ). |
Open the ALB, FT, or Rule configuration file that needs to be configured.
Add the following fields under spec.config as required.
Save and apply the configuration file.
If ModSecurity is not configured in the Rule, it will attempt to find the configuration in FT; if there is no configuration in FT, it will use the configuration from ALB.
The following example deploys an ALB named waf-alb
and a demo backend application named hello
. Additionally, an Ingress named ing-waf-enable
is deployed, which defines the /waf-enable
route and configures ModSecurity rules. Any request containing the query parameter test
, where the value includes the string test
, will be blocked.