services: exampleapp: # Your app, built from the Dockerfile in this directory, listening # on port 8081. Publish no port of it: it is reached through rproxy. build: . rproxy: image: git.eeqj.de/sneak/smallwebwaf:latest environment: SWW_RPROXY_WAF_BACKEND: http://waf:8080 SWW_RPROXY_UPSTREAM_URL: http://exampleapp:8081 # The address the refusal pages link to. # SWW_RPROXY_CONTACT_EMAIL: ops@example.com # The netblocks whose X-Forwarded-For rproxy believes. By default # the private ranges, which cover a TLS-terminating proxy on the # Docker network. A proxy elsewhere needs its address added; a # list you give replaces the default, so repeat the private # ranges if they are still wanted. Set but empty, rproxy believes # no forwarded header. # SWW_RPROXY_TRUSTED_PROXIES: 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,203.0.113.5,2001:db8:1::/64 # By default rproxy passes a request to the app while waf gives # no answer. Uncomment this to answer 503 instead. # SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION: deny # The largest request body (default 100M) and response body # (default 1G): a size with K, M or G, or `off`. Raise them for # uploads and downloads larger than that, such as git pushes and # clones or image layers. # SWW_RPROXY_MAX_REQUEST_SIZE: 2G # SWW_RPROXY_MAX_RESPONSE_SIZE: 4G # How long a request may take to reach the app (default 60000, # one minute) and how long its answer may take to reach the # visitor (default 1800000, 30 minutes), in milliseconds or # `off`. Raise the first for slow uploads, the second for long # downloads. # SWW_RPROXY_MAX_REQUEST_TIME_MS: "600000" # SWW_RPROXY_MAX_RESPONSE_TIME_MS: "7200000" # traefik terminates TLS and forwards to rproxy:8080 over its own # network, which the `networks` block at the end of this file names. # No port is published. networks: - default - traefik labels: traefik.enable: "true" # rproxy is on two networks; traefik reaches it on this one. traefik.docker.network: traefik traefik.http.routers.exampleapp.rule: Host(`app.example.com`) traefik.http.routers.exampleapp.entrypoints: websecure traefik.http.routers.exampleapp.tls.certresolver: letsencrypt traefik.http.services.exampleapp.loadbalancer.server.port: "8080" waf: image: git.eeqj.de/sneak/smallwebwaf:latest environment: SWW_COMMAND: waf # `observe` refuses nothing and makes no ban; each log line says # what `enforce` (the default) would have done. Start here to # see what the defaults would refuse on your site. # SWW_WAF_MODE: observe # waf's own messages below `info` (the default), while finding # out why something is refused. # SWW_WAF_LOG_LEVEL: debug # Netblocks whose clients skip every check, such as monitoring. # SWW_WAF_ALLOW_NETS: 192.0.2.10,2001:db8:2::/48 # Netblocks whose clients are refused. # SWW_WAF_DENY_NETS: 198.51.100.128/25,2001:db8:3::/48 # Netblocks exempt from rate limiting and the byte limits, such # as the office and an automation host that calls an API. Their # requests are still checked for attacks. # SWW_WAF_RATE_LIMIT_EXEMPT_NETS: 203.0.113.0/24,198.51.100.7 # Refuse every request from a country, by its two-letter code. # This refuses North Korea, Cuba, Russia and Iran. A client the # lookup cannot place gets through; see SWW_WAF_LOOKUP_SOURCE. # SWW_WAF_TAG_DENY: country=KP,country=CU,country=RU,country=IR # Or from a network, by its AS number: here two hosting networks # that send only scrapers, M247 (AS9009) and WorldStream # (AS49981). Countries and networks go in the one list together. # SWW_WAF_TAG_DENY: asn=9009,asn=49981,country=KP,country=RU # Or let only these countries through; a client the lookup # cannot place is refused too. # SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES: us,de # Address lists that each tag their clients' requests, as # name=URL pairs; this one tags Tor exit nodes. A tag is refused # by adding its name to SWW_WAF_TAG_DENY, such as # `torexit,country=KP`, or given a share of the limits in # SWW_WAF_TAG_LIMIT_PERCENT, such as `torexit:25`. # SWW_WAF_TAG_LISTS: torexit=https://check.torproject.org/torbulkexitlist # A percentage, from 1 to 99, of every limit for a tag: here # half for DigitalOcean (AS14061), a quarter for OVH (AS16276) # and a quarter for China. The lowest of a client's tags applies. # SWW_WAF_TAG_LIMIT_PERCENT: asn=14061:50,asn=16276:25,country=CN:25 # The most requests a client may make in a minute, an hour and a # day (defaults 120, 1500 and 6000), a count or `off`; the next # one bans it. Lower them for a small site, raise them for a # busy API. # SWW_WAF_RATE_LIMIT_PER_MINUTE: "60" # SWW_WAF_RATE_LIMIT_PER_HOUR: "600" # SWW_WAF_RATE_LIMIT_PER_DAY: "3000" # Path prefixes exempt from rate limiting and the byte limits, # such as static assets that one page loads many of. # SWW_WAF_RATE_LIMIT_EXEMPT_PATHS: /assets/,/static/ # Paths only scanners ask for; one request bans the client. Pick # paths your app never serves. # SWW_WAF_TRAP_PATHS: /wp-login.php,/xmlrpc.php,/wp-admin/ # How a refused client is answered: 403 (the default), 429 or # `close`, which drops the connection. # SWW_WAF_BAN_RESPONSE: "429" # The ban for a first broken limit (default 1h) and for a first # clear sign of attack (default 7d): a duration with m, h or d. # A repeat within SWW_WAF_LIMIT_BAN_REPEAT_WINDOW (default 24h) # gets a ban three times as long. # SWW_WAF_LIMIT_BAN_DURATION: 30m # SWW_WAF_ATTACK_BAN_DURATION: 30d # The Core Rule Set, which finds attacks in requests. `block` # (the default) refuses a match, `detect` only logs and alerts # it, `off` runs no rule. Use `detect` while finding out what it # would refuse of your app's ordinary requests. # SWW_WAF_CORE_RULE_SET_MODE: detect # Path prefixes the Core Rule Set does not inspect, for a part of # the app that it keeps matching, such as an editor that posts # HTML or code. # SWW_WAF_CORE_RULE_SET_EXEMPT_PATHS: /api/editor/,/admin/ # The apps each hostname serves, as hostname:app pairs separated # by semicolons, so that each hostname gets its own apps' fixes # to the attack detection and no other's. "Attack detection" in # the README lists the apps. # SWW_WAF_APPS: git.example.com:gitea;blog.example.com:wordpress # Blocklists of addresses and netblocks, text files fetched once # a day, whose clients are refused. # SWW_WAF_BLOCKLIST_URLS: https://www.spamhaus.org/drop/drop.txt,https://www.spamhaus.org/drop/dropv6.txt # With the key of an AbuseIPDB account, a client that has # committed an offence is checked there in the background; one # scored 75 or more (SWW_WAF_ABUSEIPDB_MIN_SCORE) gets what # SWW_WAF_DNSBL_ABUSEIPDB_ACTION says: a quarter of every limit # by default, or `deny`. At most 900 checks a day # (SWW_WAF_ABUSEIPDB_DAILY_BUDGET), under the free plan's 1000. # SWW_WAF_ABUSEIPDB_KEY: api-key-..... # SWW_WAF_DNSBL_ABUSEIPDB_ACTION: deny # By default waf looks each client's address up at GeoJS, a web # service, for its country and AS number. Set `off`, it makes no # external requests for lookups. Every setting at its default # works without them; one that needs a lookup, such as a country # or ASN setting above, then stops the start. Set `file`, it # reads an IPinfo Lite database instead, mounted by its # directory as under `volumes` below, so that a replaced file is # seen. # SWW_WAF_LOOKUP_SOURCE: "off" # SWW_WAF_LOOKUP_SOURCE: file # SWW_WAF_LOOKUP_DB_PATH: /var/lib/ipinfo/ipinfo_lite.mmdb # Alerts about bans, attacks and failures, to an ntfy topic, a # Slack incoming webhook or any webhook. The ntfy token is the # access token ntfy issued for the topic. # SWW_WAF_ALERT_NTFY_URL: https://ntfy.sh/my-alerts # SWW_WAF_ALERT_NTFY_TOKEN: hunter2 # SWW_WAF_ALERT_SLACK_WEBHOOK_URL: https://hooks.slack.com/services/... # Bearer tokens you make up, at least 32 characters each. The # admin token switches on the ban and client endpoints, through # which a ban is lifted, your own included, as # docs/admin-endpoints.md describes. The metrics token switches # on /_sww/metrics. # SWW_WAF_ADMIN_TOKEN: hunter2 # SWW_WAF_METRICS_TOKEN: hunter2 # Any setting can be read from a file instead, by adding _FILE # to its name: the file's contents are the value, less one # newline at the end. That keeps a secret out of this file and # out of `docker inspect`. Mount the files as under `volumes` # below, and set each setting in one form only. # SWW_WAF_ALERT_NTFY_TOKEN_FILE: /etc/sww/tokens/ntfy # SWW_WAF_ADMIN_TOKEN_FILE: /etc/sww/tokens/admin # SWW_WAF_METRICS_TOKEN_FILE: /etc/sww/tokens/metrics # SWW_WAF_ABUSEIPDB_KEY_FILE: /etc/sww/tokens/abuseipdb volumes: # waf's state files: its clients and bans, kept across restarts. - waf-state:/var/lib/sww # Token files, each owned by uid 65532 (the sww user) with mode # 0400, for the _FILE settings above. # - /srv/sww/tokens:/etc/sww/tokens:ro # The IPinfo Lite database, for SWW_WAF_LOOKUP_SOURCE=file. # - /srv/ipinfo:/var/lib/ipinfo:ro volumes: waf-state: # traefik's network, made outside this file. networks: traefik: external: true