HUB
Sign inSign up

msecapps/nginx-waf

By msecapps

•Updated 1 day ago

Image
Security
Developer tools
Web servers
0

738

msecapps/nginx-waf repository overview

⁠nginx-waf

[TR] Resmi nginx:alpine imajı üzerine kurulmuş, ModSecurity v3 ve OWASP Core Rule Set (CRS) v4 içeren, root olmadan çalışan bir Web Application Firewall (WAF) imajı. Nginx güvenlik yamaları yayımlandığında hızla yeniden derlenir.

[EN] A nonroot Web Application Firewall (WAF) image built on the official nginx:alpine image, bundling ModSecurity v3 and the OWASP Core Rule Set (CRS) v4. Rebuilt promptly when Nginx security patches are released.


⁠🏷 Etiketler / Tags

Etiket / TagAçıklama / Description
latestEn güncel build / Latest build
<nginx>-crs<crs> (örn. / e.g. 1.30.7-crs4.30.0)Sabit sürüm / Pinned version

Platformlar / Platforms: linux/amd64, linux/arm64

docker pull msecapps/nginx-waf:latest
Bileşen / ComponentSürüm / Version
Nginx (stable)1.30.8
ModSecurity (libmodsecurity)3.0.17
ModSecurity-nginx connector1.0.4
OWASP CRS4.31.0

⁠🚀 Özellikler / Features

  • Nonroot: nginx kullanıcısı (UID 101) ile çalışır. / Runs as the nginx user (UID 101).
  • Ortam değişkenleriyle ayar / Env-based config: Kural motoru, paranoia seviyesi ve anomali eşikleri -e ile değiştirilir. / Rule engine, paranoia level and anomaly thresholds are set with -e.
  • Kendi kurallarınız / Custom rules: CRS'ten önce ve sonra yüklenen iki ayrı dosya. / Two separate files loaded before and after CRS.
  • JSON audit log: Varsayılan olarak stdout'a JSON formatında yazılır. / Written to stdout as JSON by default.
  • TCP proxy: stream.d/ ile TCP/UDP yönlendirme (örn. PostgreSQL). / TCP/UDP proxying via stream.d/ (e.g. PostgreSQL).

⁠⚙️ Ortam Değişkenleri / Environment Variables

Değişken / VariableVarsayılan / DefaultAçıklama / Description
MODSEC_RULE_ENGINEOnOn, Off, DetectionOnly
PARANOIA1CRS paranoia seviyesi / CRS paranoia level (1–4)
ANOMALY_INBOUND5Gelen istek engelleme eşiği / Inbound blocking threshold
ANOMALY_OUTBOUND4Giden yanıt engelleme eşiği / Outbound blocking threshold
MODSEC_REQ_BODY_LIMIT13107200İstek gövdesi limiti (bayt, dosyalar dahil) / Request body limit (bytes, incl. files)
MODSEC_REQ_BODY_NOFILES_LIMIT131072Dosya hariç gövde limiti (bayt) / Body limit excluding files (bytes)
MODSEC_RESP_BODY_ACCESSOnYanıt gövdesini incele / Inspect response bodies
MODSEC_RESP_BODY_LIMIT1048576Yanıt gövdesi limiti (bayt) / Response body limit (bytes)
MODSEC_AUDIT_ENGINERelevantOnlyOn, Off, RelevantOnly
MODSEC_AUDIT_LOG/dev/stdoutAudit log hedefi / Audit log target
MODSEC_AUDIT_LOG_FORMATJSONJSON veya / or Native

⁠🛠 Kullanım / Usage

⁠1. Hızlı başlangıç / Quick start
docker run -d -p 8080:8080 msecapps/nginx-waf:latest
curl http://localhost:8080/healthz

[TR] WAF'ın çalıştığını test edin; bu istek 403 dönmelidir:

[EN] Test that the WAF works; this request should return 403:

curl -i "http://localhost:8080/?id=1%27%20OR%20%271%27=%271"
⁠2. Reverse proxy

conf.d/app.conf

upstream app_backend {
    zone app_backend 64k;
    server app:3000 resolve;
}

server {
    listen 8080;
    server_name example.com;

    location / {
        proxy_pass http://app_backend;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

docker-compose.yml

services:
  waf:
    image: msecapps/nginx-waf:latest
    ports:
      - "80:8080"
      - "443:8443"
    environment:
      MODSEC_RULE_ENGINE: DetectionOnly   # ilk kurulumda önce izleyin / observe first
      PARANOIA: 1
      ANOMALY_INBOUND: 5
    volumes:
      - ./conf.d:/etc/nginx/conf.d:ro
      - ./ssl:/etc/nginx/ssl:ro
      - ./modsec/before-crs.conf:/etc/modsecurity.d/before-crs.conf:ro
      - ./modsec/after-crs.conf:/etc/modsecurity.d/after-crs.conf:ro
    cap_drop: [ALL]
    security_opt:
      - no-new-privileges:true
    restart: always

  app:
    image: my-app:latest
⁠3. Kendi kurallarınız / Custom rules
Dosya / FileNe zaman yüklenir / LoadedNe için / Use for
/etc/modsecurity.d/before-crs.confCRS'ten önce / before CRSctl:ruleRemoveById, SecAction, CRS uygulama istisnaları / CRS app exclusions
/etc/modsecurity.d/after-crs.confCRS'ten sonra / after CRSSecRuleRemoveById, SecRuleUpdateTargetById

before-crs.conf

# /api/ altında bir SQL injection kuralını kapat
SecRule REQUEST_URI "@beginsWith /api/" \
    "id:10000,phase:1,pass,nolog,ctl:ruleRemoveById=942100"

after-crs.conf

SecRuleRemoveById 920420

[TR] Kendi kural ID'lerinizi 10000–99999 aralığında seçin; CRS bu aralığı kullanmaz.

[EN] Use IDs in the 10000–99999 range for your own rules; CRS does not use this range.

⁠4. TCP proxy (stream)

stream.d/postgres.conf

upstream pg_backend {
    zone pg_backend 64k;
    server postgres:5432 resolve;
}
server {
    listen 5432;
    proxy_pass pg_backend;
}
    volumes:
      - ./stream.d:/etc/nginx/stream.d:ro
⁠5. Şablonlar / Templates

[TR] Resmi nginx imajının şablon desteği çalışır: /etc/nginx/templates/*.conf.template dosyalarındaki ${DEGISKEN} ifadeleri başlangıçta ortam değişkenleriyle doldurulup conf.d/ içine yazılır. Bu özelliği kullanırken conf.d/ klasörünü bağlamayın.

[EN] The official nginx image template support works: ${VAR} expressions in /etc/nginx/templates/*.conf.template are filled from environment variables at startup and written to conf.d/. Do not mount conf.d/ when using this feature.


⁠🔒 Nonroot Notları / Nonroot Notes

  • Portlar / Ports: [TR] Varsayılan site 8080 portunu dinler. Docker 20.10+ konteyner içinde root olmadan 80/443 portlarına da izin verir; Kubernetes'te pod'a net.ipv4.ip_unprivileged_port_start=0 sysctl ayarını verin veya 8080/8443 kullanın. / [EN] The default site listens on 8080. Docker 20.10+ also allows binding 80/443 without root inside the container; in Kubernetes, set the net.ipv4.ip_unprivileged_port_start=0 sysctl on the pod or use 8080/8443.
  • Sertifikalar / Certificates: [TR] Private key dosyası UID 101 tarafından okunabilir olmalıdır. / [EN] The private key must be readable by UID 101.
  • pid: /run/nginx/nginx.pid. [TR] Kendi nginx.conf dosyanızı bağlarsanız pid /run/nginx/nginx.pid; ve load_module modules/ngx_http_modsecurity_module.so; satırlarını ekleyin. / [EN] If you mount your own nginx.conf, include pid /run/nginx/nginx.pid; and load_module modules/ngx_http_modsecurity_module.so;.

⁠🔍 Kontrol / Verification

docker run --rm msecapps/nginx-waf:latest nginx -V 2>&1 | head -1
docker run --rm msecapps/nginx-waf:latest nginx -t

⁠Lisans / License

[TR] Bu imaj; Nginx (BSD-2-Clause), ModSecurity (Apache-2.0) ve OWASP CRS (Apache-2.0) projelerini değiştirmeden içerir.

[EN] This image bundles Nginx (BSD-2-Clause), ModSecurity (Apache-2.0) and OWASP CRS (Apache-2.0) without modification.

Maintainer: Github⁠.

Tag summary

Content type

Image

Digest

sha256:c14d5fac5…

Size

29.4 MB

Last updated

1 day ago

docker pull msecapps/nginx-waf