ModSecurity - Web Application Firewall
We have a dedicated ingress-controller with ModSecurity enabled.
To enable and point your application to this ingress-controller, use the following annotations on your ingress manifest file:
annotations: kubernetes.io/ingress.class: "modsec01" nginx.ingress.kubernetes.io/enable-modsecurity: "true" nginx.ingress.kubernetes.io/modsecurity-snippet: | SecRuleEngine On
What is a Web Application Firewall (WAF)?
A Web Application Firewall or WAF helps protect web applications by filtering and monitoring HTTP traffic between a web application and the Internet. A WAF is a layer 7 defense and is one of the most common means of protecting against malicious web application security flaws at the application layer. However, it must be noted that a WAF is not designed and does not protect against all types of attacks.
ModSecurity is an open source, cross platform web application firewall (WAF) developed by Trustwave’s SpiderLabs. It has a robust event-based programming language which provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring and logging.
For the Cloud Platform, ModSecurity has been configured as an opt-in feature. New and current applications will require a specific set of annotations to be added to their ingress manifest file.
We have a dedicated ingress-controller with ModSecurity enabled separate from the default ingress-controller. To point your application to the ModSec ingress-controller, add the following annotation to your ingress manifest file:
To enable ModSecurity for your application, add the following annotation to your ingress manifest file:
This annotation enables ModSecurity for the ingress on the nginx ingress-controller in detection only mode. There is no disruptive action if a critical rule triggers, but it is logged in the nginx-ingress.log file. The
SecRuleEngine is set to
Detection Only Mode.
nginx.ingress.kubernetes.io/modsecurity-snippet: | SecRuleEngine On
SecRuleEngine On configures ModSecurity to actively block traffic classed as malicious using Anomaly Scoring.
The above annotation is optional, but it can be used to pass transactionIDs from nginx.
apiVersion: networking.k8s.io/v1beta1 kind: Ingress name: <ingress-name> namespace: <namespace-name> annotations: kubernetes.io/ingress.class: "modsec01" external-dns.alpha.kubernetes.io/set-identifier: <ingress-name>-<namespace-name>-<colour> external-dns.alpha.kubernetes.io/aws-weight: "100" nginx.ingress.kubernetes.io/enable-modsecurity: "true" nginx.ingress.kubernetes.io/modsecurity-snippet: | SecRuleEngine On spec: tls: - hosts: - <application_url> rules: - host: <application_url> http: paths: - path: / backend: serviceName: app-service servicePort: 8080
(Note - Please change the
namespace-name values in the above example. The
colour should be
blue for ingress in live-1 and
green for ingress in EKS
All disruptive actions are logged in the ModSecurity audit log file and the error log for for nginx ingress-controller.
Fluent-bit is used to ship error logs into the Cloud Platform ELK stack. To view any possible logs, log into Kibana,
kubernetes_ingress index and search for
ModSecurity. You can filter down to a particular host using
log_processed.http_host.log is "host: "test-ingress.url"
Error Log Example:
2019/01/01 11:00:00 [warn] 12647#12647: *1158975 [client 126.96.36.199] ModSecurity: Access denied with code 403 (phase 2). Matched "Operator `Ge' with parameter `5' against variable `TX:ANOMALY_SCORE' (Value: `5' ) [file "/etc/nginx/owasp-modsecurity-crs/rules/ REQUEST-949-BLOCKING-EVALUATION.conf"] [line "01"] [id "00001"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Score: 5)"] [data ""] [severity "2"] [ver ""] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-generic"] [hostname "188.8.131.52"] [uri "/"] [unique_id "12345678.12345"] [ref ""], client: 184.108.40.206, server: test-ingress.url, request: "GET /?exec=/bin/bash HTTP/2.0", host: "test-ingress.url"
The OWASP ModSecurity Core Rule Set (CRS) is a set of generic attack detection rules for use with ModSecurity. These rules are enabled on the ingress-controller level on the dedicated ModSec ingress-controller. The CRS aims to protect web applications from a wide range of attacks, including the OWASP Top Ten, with a minimum of false alerts. The CRS provides protection against many common attack categories, including:
- SQL Injection (SQLi)
- Cross Site Scripting (XSS)
- Local File Inclusion (LFI)
- Remote File Inclusion (RFI)
- PHP Code Injection
- Unix/Windows Shell Injection
- Session Fixation
- Scripting/Scanner/Bot Detection
- Metadata/Error Leakages
The Paranoia Level (PL) setting allows you to choose the desired level of rule checks. For the Cloud Platform implementation, this has been set to PL1. For more information on Paranoia Levels, please go to the
What are paranoia levels, and which level should I choose? section here
Anomaly Scoring Mode
Traditional Detection or Passive Mode is the most basic operating mode where all of the rules are run as individual entities. In this mode no intelligence is shared between rules and each rule has no information about any previous rule matches. That is to say, in this mode, if a rule triggers, it will execute any disruptive/logging actions specified on the current rule.
Anomaly scoring mode implements the concept of Collaborative Detection and Delayed Blocking. Rule logic has been set to decouple the inspection/detection from the blocking functionality. The individual rules can be run so that the detection remains, however instead of applying any disruptive action at that point, the rules will contribute to a transactional anomaly score collection. In addition, each rule will also store meta-data about each rule match (such as the Rule ID, Attack Category, Matched Location and Matched Data) for later logging. For more information in anomaly scoring, click here