diff --git a/README.md b/README.md index 3322d6e7..c4444ccd 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ Every stack starts from the same [standard setup](documentation/standard-setup.m | **AdGuard Home Sync** | Tool that copies the configuration of one AdGuard Home instance to replicas. | [Details](services/adguardhome-sync) | | **Caddy** | Web server and reverse proxy with automatic HTTPS. | [Details](services/caddy) | | **DDNS Updater** | Updater that keeps DNS records pointed at your current public IP address. | [Details](services/ddns-updater) | +| **EdgeWatch** | Scanner that watches your internet-facing ports and alerts you when they change. | [Details](services/edgewatch) | | **FlareSolverr** | Proxy that solves Cloudflare and DDoS-GUARD challenges. | [Details](services/flaresolverr) | | **Nessus** | Vulnerability scanner from Tenable, with the limited free Nessus Essentials license. | [Details](services/nessus) | | **NetBox** | Network documentation tool for IP addresses, racks, devices, connections, and circuits. | [Details](services/netbox) | diff --git a/services/edgewatch/.env b/services/edgewatch/.env new file mode 100644 index 00000000..1f17f696 --- /dev/null +++ b/services/edgewatch/.env @@ -0,0 +1,26 @@ +#URL=https://github.com/tailscale-dev/ScaleTail +# To run a second copy, copy the folder under another name and change SERVICE. + +# Service Configuration +# Service name (e.g., adguard). Used as hostname in Tailscale and for container naming (app-${SERVICE}). +SERVICE=edgewatch +# Docker image URL from container registry (e.g., adguard/adguardhome:latest). +IMAGE_URL=ghcr.io/crypt0rr/edgewatch:latest + +# Network Configuration +# Port of the web interface. EdgeWatch listens on loopback only, so compose.yaml has no "ports:" section that uses it. +SERVICEPORT=8080 +# Preferred DNS server for Tailscale. Uncomment the "dns:" section in compose.yaml to enable. +DNS_SERVER=9.9.9.9 + +# Tailscale Configuration +# Auth key from https://console.tailscale.com/admin/settings/keys. See: https://tailscale.com/kb/1085/auth-keys#generate-an-auth-key for instructions. +TS_AUTHKEY= + +# Optional Service variables +# PUID=1000 + +# Time Zone setting for containers. See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones +TZ=Europe/Amsterdam + +# EdgeWatch reads its settings from config.yaml in this folder, not from environment variables. diff --git a/services/edgewatch/README.md b/services/edgewatch/README.md new file mode 100644 index 00000000..75d387e4 --- /dev/null +++ b/services/edgewatch/README.md @@ -0,0 +1,82 @@ +# EdgeWatch + +[EdgeWatch](https://github.com/crypt0rr/EdgeWatch) scans your internet-facing systems on a schedule with Nmap and Naabu, learns which ports and services are expected, and notifies you when the exposed surface changes. + +This stack runs EdgeWatch with a Tailscale sidecar, as described in [the standard setup](../../documentation/standard-setup.md). EdgeWatch has no built-in Tailscale support and its image contains no Tailscale client, so the sidecar publishes the web interface with Tailscale Serve, the proxy that the upstream documentation describes. + +## At a glance + +| Item | Value | +| ------------- | --------------------------------------------------------- | +| Web interface | `https://edgewatch..ts.net` | +| Service port | `8080` | +| Image | `ghcr.io/crypt0rr/edgewatch:latest` | +| Data | `./edgewatch-data/` (database and keys), `./config.yaml` | + +## Before you start + +- **Set `web.allowed_hosts` in `config.yaml`.** Replace `` in `edgewatch..ts.net` with your Tailnet DNS name, such as `tail1234`. If you change `SERVICE` in `.env`, change the first part of the name as well. Until you set it, EdgeWatch stops at start with `web.allowed_hosts[0]: invalid host name "edgewatch..ts.net"`. It answers any other host name with `421 Misdirected Request`. +- **Let Docker create `./edgewatch-data`, or create it as root.** EdgeWatch runs as root without the capability to override file permissions, so the folder must belong to root. Docker creates it that way at the first start. To create it yourself, as upstream does, run `sudo install -d -m 0750 -o 0 -g 0 ./edgewatch-data`. +- **Docker Engine 25 or later.** The health check uses `start_interval`, which older Docker Engine releases do not support. +- **Scan only systems you own or may assess.** Full-range UDP scans can take hours and create a lot of traffic. + +## Deviations from the standard setup + +- **Configuration file.** EdgeWatch reads its settings from `config.yaml`, which the stack mounts read-only. It is upstream's `config.example.yaml` with `web.allowed_hosts` and `web.trusted_proxies` set for Tailscale Serve, which connects from loopback. Compose cannot write the file from a `configs` block, because the container's root filesystem is read-only. +- **Scans use the network of the `tailscale` container.** Upstream runs EdgeWatch with host networking. Here, as in every stack, the application shares the network of the sidecar. Scans reach the internet through the stack's Docker network, and Tailnet devices when your Tailnet policy allows it. They cannot reach containers on other Docker networks until you attach those networks, as described under "Configuration", and the scanners cannot see the host's own network interfaces. The address `127.0.0.1` is the loopback of the `tailscale` container. +- **No `ports` block.** EdgeWatch accepts connections on `127.0.0.1` only, so a published host port cannot reach it. Use Tailscale Serve. +- **Hardening from upstream.** The `application` container drops every capability and adds back `NET_RAW` for Nmap and Naabu, and `SETUID`, `SETGID`, and `KILL`, which EdgeWatch uses to run each scanner and the notification process under its own unprivileged user. It also sets `no-new-privileges`, a read-only root filesystem, and a `/tmp` tmpfs of 128 MB. `TMPDIR` points to the data folder, where Nmap, Naabu, and SQLite write their temporary files. +- **Limits from upstream.** The container may use 512 MB of memory, which covers a scan of a `/16`. It gets seven minutes to stop, so the daemon can save a large scan, and its log is limited to three files of 10 MB. +- **Health check.** The check calls `/healthz` every 30 seconds, with a start period of 20 minutes so that database migrations can finish after an upgrade. + +## First run + +1. Get the one-time setup token, which expires after 15 minutes: + + ```sh + docker compose logs application | grep setup_token + ``` + +2. Open the web interface and create the first administrator with the token. +3. Open **Jobs → New job** and follow the guided setup to choose targets, ports, a schedule, and alerts. + +If the token expired before you finished, or the log no longer shows it because the container was recreated, issue a new one: + +```sh +docker compose exec application edgewatch admin setup-token --config /etc/edgewatch/config.yaml --force +``` + +## Configuration + +- **Settings.** Edit `config.yaml` and apply it with `docker compose up -d --force-recreate application`. The [configuration reference](https://edgewatch.offsec.nl/reference/configuration/) describes every setting, such as `retention`, `scanner.target_exclusions`, and `backup`. +- **Time zone.** The stack passes `TZ` from `.env`, which sets the time zone of the daemon log. The optional `timezone` setting in `config.yaml` also sets it for the web interface and notifications. +- **Naabu SYN scans.** A Naabu profile with `scan_type: syn` also needs `NET_ADMIN`. Add it to `cap_add` of the `application` service in a `compose.override.yaml`, as upstream's `compose.syn.yaml` does. +- **Other Docker networks.** Docker keeps networks apart, so the scanners cannot reach containers in other stacks. To scan them, attach their networks to the `tailscale` service, for example in a `compose.override.yaml`. The `application` service uses the network of the `tailscale` service and cannot join networks itself. + + ```yaml + services: + tailscale: + networks: + - default # Keep the network of this stack + - other-stack + + networks: + other-stack: + name: other-stack_default # The name that docker network ls shows + external: true + ``` + + Then add the containers to a job by name or IP address. The network must exist before this stack starts, and the other stack cannot remove it while this stack is attached. For Tailnet targets, use Tailscale IP addresses: `TS_ACCEPT_DNS=true` would resolve MagicDNS names, but container names would no longer resolve. +- **Metrics.** Tailscale Serve forwards every path, so when you enable `web.metrics`, every Tailnet device that may reach this one can request `/metrics`, which then only needs the bearer token. Upstream recommends keeping `/metrics` off the proxy. See [health and metrics](https://edgewatch.offsec.nl/deployment/reverse-proxies/#health-and-metrics). +- **Back up** `./edgewatch-data` as a whole. It holds the database and the generated encryption keys. See [backup and recovery](https://edgewatch.offsec.nl/operations/backup-recovery/). + +## Troubleshooting + +- **`mkdir /var/lib/edgewatch/tmp: permission denied`.** `./edgewatch-data` does not belong to root. Stop the stack, then run `sudo chown -R 0:0 ./edgewatch-data` and `sudo chmod 0750 ./edgewatch-data`. +- **`421 Misdirected Request`.** The address you opened is not in `web.allowed_hosts`. Check the name against `docker compose exec tailscale tailscale status --json | jq -r .Self.DNSName`, without the final dot, and recreate the container. + +## Links + +- [EdgeWatch documentation](https://edgewatch.offsec.nl/) +- [Installation](https://edgewatch.offsec.nl/getting-started/installation/), [Tailscale Serve and reverse proxies](https://edgewatch.offsec.nl/deployment/reverse-proxies/), and [container hardening](https://edgewatch.offsec.nl/deployment/container-hardening/) +- [EdgeWatch source code](https://github.com/crypt0rr/EdgeWatch) diff --git a/services/edgewatch/compose.yaml b/services/edgewatch/compose.yaml new file mode 100644 index 00000000..80650e1a --- /dev/null +++ b/services/edgewatch/compose.yaml @@ -0,0 +1,99 @@ +configs: + ts-serve: + content: | + {"TCP":{"443":{"HTTPS":true}}, + "Web":{"$${TS_CERT_DOMAIN}:443": + {"Handlers":{"/": + {"Proxy":"http://127.0.0.1:8080"}}}}, + "AllowFunnel":{"$${TS_CERT_DOMAIN}:443":false}} + +services: +# Make sure you have updated/checked the .env file with the correct variables. +# Every variable used in this file must be defined there, unless it has a default such as ${VAR:-value}. + # Tailscale Sidecar Configuration + tailscale: + image: tailscale/tailscale:latest # Image to be used + container_name: tailscale-${SERVICE} # Name for local container management + hostname: ${SERVICE} # Name used within your Tailscale environment + environment: + - TS_AUTHKEY=${TS_AUTHKEY} + - TS_STATE_DIR=/var/lib/tailscale + - TS_SERVE_CONFIG=/config/serve.json # Tailscale Serve configuration to expose the web interface on your local Tailnet - remove this line if not required + - TS_USERSPACE=false + - TS_ENABLE_HEALTH_CHECK=true # Enable healthcheck endpoint: "/healthz" + - TS_LOCAL_ADDR_PORT=127.0.0.1:41234 # The : for the healthz endpoint + #- TS_ACCEPT_DNS=true # Uncomment only if the service must resolve MagicDNS names - this replaces Docker DNS, so Compose service names no longer resolve + - TS_AUTH_ONCE=true + configs: + - source: ts-serve + target: /config/serve.json + volumes: + - ./config:/config # Config folder used to store Tailscale files - you may need to change the path + - ./ts/state:/var/lib/tailscale # Tailscale requirement - you may need to change the path + devices: + - /dev/net/tun:/dev/net/tun # Network configuration for Tailscale to work + cap_add: + - net_admin # Tailscale requirement + # No ports block: EdgeWatch accepts connections on loopback only, so a published host port cannot reach it. + # If any DNS issues arise, use your preferred DNS provider by uncommenting the config below + #dns: + # - ${DNS_SERVER} + healthcheck: + test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:41234/healthz"] # Check Tailscale has a Tailnet IP and is operational + interval: 1m # How often to perform the check + timeout: 10s # Time to wait for the check to succeed + retries: 3 # Number of retries before marking as unhealthy + start_period: 10s # Time to wait before starting health checks + restart: always + + # Application + application: + image: ${IMAGE_URL} # Image to be used + network_mode: service:tailscale # Sidecar configuration to route the service through Tailscale + container_name: app-${SERVICE} # Name for local container management + environment: # Variables are declared in .env file. + - TZ=${TZ} + # Nmap, Naabu, and SQLite write their temporary files to the data folder, not to the small /tmp tmpfs. + - TMPDIR=/var/lib/edgewatch/tmp + # The hardening below follows the upstream compose.yaml. EdgeWatch runs as root with every capability dropped. + # NET_RAW is for Nmap and Naabu. SETUID, SETGID, and KILL let EdgeWatch start each scanner and the + # notification process under their own unprivileged user and stop them. Without them, scans fail. + cap_drop: + - ALL + cap_add: + - NET_RAW + - SETUID + - SETGID + - KILL + security_opt: + - no-new-privileges:true + read_only: true + tmpfs: + - /tmp:size=128m,mode=1777 + volumes: + - ./config.yaml:/etc/edgewatch/config.yaml:ro # EdgeWatch configuration - set web.allowed_hosts to the Tailnet address first + - ./${SERVICE}-data:/var/lib/edgewatch # Database, encryption keys, and temporary scan files + # Upstream limits: a scan of a /16 needs about 344 MB, and the daemon needs up to six minutes to save a large scan when it stops. + deploy: + resources: + limits: + memory: 512M + stop_grace_period: 7m + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + depends_on: + tailscale: + condition: service_healthy + restart: true # Restart this service when Compose restarts the sidecar, whose network it uses + # The long start period lets database migrations finish after an upgrade. /healthz answers 503 until then. + healthcheck: + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/healthz"] # Check if the service is responding + interval: 30s # How often to perform the check + timeout: 10s # Time to wait for the check to succeed + retries: 3 # Number of retries before marking as unhealthy + start_period: 20m # Time to wait before starting health checks + start_interval: 5s # How often to check during the start period + restart: always diff --git a/services/edgewatch/config.yaml b/services/edgewatch/config.yaml new file mode 100644 index 00000000..f4cf4279 --- /dev/null +++ b/services/edgewatch/config.yaml @@ -0,0 +1,192 @@ +# EdgeWatch configuration for this stack, based on config.example.yaml from +# https://github.com/crypt0rr/EdgeWatch. All settings are described at +# https://edgewatch.offsec.nl/reference/configuration/ +# After a change, recreate the container: +# docker compose up -d --force-recreate application + +database: /var/lib/edgewatch/edgewatch.db +retention: 90d + +# Optional IANA timezone for this deployment. When set, daemon log timestamps, +# CLI status times, times in notification messages, and every signed-in web +# console follow it, and new jobs default to it. Omit it to keep UTC in the +# container and each browser's own timezone in the console. Each job still +# runs its schedule in its own timezone field. +# timezone: Europe/Amsterdam + +# The administration UI is loopback-only. In this stack, loopback belongs to +# the network of the Tailscale container, and Tailscale Serve publishes the UI +# at https://..ts.net. +web: + listen: 127.0.0.1:8080 + # Host names accepted when the UI is reached through a reverse proxy or + # tunnel. Loopback addresses and localhost are always accepted. Replace + # with your Tailnet DNS name, such as tail1234, and edgewatch with + # SERVICE from .env if you changed it. EdgeWatch answers any other name with + # 421 Misdirected Request. + allowed_hosts: + - edgewatch..ts.net + # Optional source for a modified or forked build. The Source code links in + # the console redirect here; official builds link to their exact Git tag. + # Use an HTTPS URL containing the complete corresponding source and build + # instructions for the running version. + # source_url: https://github.com/your-org/EdgeWatch/tree/your-build-tag + # Trust only proxy addresses or networks that directly connect to EdgeWatch. + # Only this one client-IP header is read; other forwarding headers are ignored. + # The default is x-forwarded-for. Use forwarded only if your proxy controls it, + # or none to ignore forwarding headers even when trusted proxies are configured. + forwarded_header: x-forwarded-for + # Tailscale Serve connects from loopback and sets X-Forwarded-For and + # X-Forwarded-Proto. + trusted_proxies: + - 127.0.0.1/32 + - ::1/128 + # The sign-in and anonymous rate limits count an IPv6 client by its network + # of this prefix length, so every address of one /64 shares one budget. + # Audit records keep the full address. 32 to 128; use 128 to count each + # address on its own when unrelated clients share one /64. The default is 64. + # ipv6_rate_limit_prefix: 64 + # Optional separate key for encrypting the TOTP seed. The default is + # ./edgewatch-data/auth.key; an explicit file must contain 32 raw bytes or 64 hex + # characters, be mode 0600, and be mounted into the container. + # auth_key_file: /run/secrets/edgewatch-auth-key + # Live-update streams the deployment keeps open (one per open console, at + # most four per account), and the most one business unit may hold. With + # more than one active unit, each unit gets an equal share of + # max_live_streams, at least 4 and at most max_live_streams_per_unit. + # max_live_streams: 256 + # max_live_streams_per_unit: 64 + # Opt-in Prometheus metrics at GET /metrics, deployment aggregates only. + # The token file holds one bearer token of 32 to 1024 printable characters + # and must be mode 0400 or 0600; scrapers send it as + # "Authorization: Bearer ". Keep /metrics off public proxies. + # GET /healthz needs no configuration. + # metrics: + # enabled: true + # token_file: /run/secrets/edgewatch-metrics-token + +scheduler: + max_concurrent_scans: 1 + # Approximate Nmap probes permitted per run unless an administrator enables + # high-cost work for a job. Naabu has a separate budget below because its + # full-range discovery probes are much lighter than Nmap probes. + max_probe_count: 5000000 + # Naabu 1-65535 discovery budget. The default covers the editor's 256-host + # expansion limit (about 16.8M probes) with headroom. + max_naabu_probe_count: 20000000 + +# Structured daemon logs are emitted as JSON on stdout. Other CLI commands +# write the same log to stderr so their printed result stays on stdout. Use +# debug while diagnosing a request, or warn/error to reduce routine output. +# The default is info. +log: + level: info + +# In this stack, scans use the network of the Tailscale container and leave +# the host through Docker's network, not through host networking. Loopback +# here is the Tailscale container's own. The list below is +# the default: it refuses loopback and link-local targets, and the IPv4 +# link-local range includes the 169.254.169.254 cloud metadata endpoint. Other +# metadata endpoints are not excluded by default. Add the ones your provider +# uses, such as fd00:ec2::254/128 (AWS IPv6 instance metadata) or +# 100.100.100.200/32 (Alibaba Cloud). An explicit list replaces the defaults. +# Set target_exclusions: [] only when an administrator has deliberately +# accepted the risk and needs to monitor the host's own local surface. The +# list also keeps the notification destinations of business units away from +# these addresses, and [] allows every address for them too. +scanner: + target_exclusions: + - 127.0.0.0/8 + - 169.254.0.0/16 + - ::1/128 + - fe80::/10 + # Nmap and Naabu use distinct leased UIDs/GIDs from 60000–60063, with only + # their raw-packet capabilities. Reserve these host IDs for scanner use; with + # rootless Docker or user-namespace remapping, reserve the corresponding + # mapped host IDs. auto (the default) keeps the daemon running but refuses + # scanner launches if the pool or required seccomp filter is unavailable. + # required also refuses daemon startup and direct scan commands; off disables + # scanner isolation. + sandbox: auto + # Landlock limits Nmap and Naabu to the system files a scan reads and the + # files EdgeWatch passes to them; only Naabu may also create files, below + # /tmp. The scanner seccomp filter is independent of Landlock and remains + # required in sandboxed modes; without it scanner launches fail closed. + # auto (the default) permits scans without Landlock when identity and seccomp + # are enforced; required refuses scanner work without Landlock; off disables + # only Landlock. EdgeWatch keeps passed files in tmp/scanner beside the + # database, whatever TMPDIR names. + landlock: auto + # The most addresses the targets of one job may expand to when it scans, + # in every unit. A scan keeps every address in the daemon's memory: a /16 + # (65536, the default) peaked at about 344 MB of compose.yaml's 512 MiB, so + # raise it only with matching memory. 1 to 1000000. + # max_job_hosts: 65536 + +# Check the latest stable GitHub release at startup and every three hours. +# Set enabled: false for offline or privacy-sensitive deployments. A check +# reveals the host's public IP and EdgeWatch user agent to GitHub. +updates: + enabled: true + +# Opening a public host in the console performs an on-demand RDAP lookup. +# Set enabled: false for isolated or privacy-sensitive deployments. Lookups +# need direct HTTPS egress and ignore HTTPS_PROXY, so also set enabled: false +# where only a proxy reaches the internet. +enrichment: + rdap: + enabled: true + +notifications: + # Add notification destinations on the Notifications page of the web + # console. They are encrypted with ./edgewatch-data/notification.key. To supply the + # key separately (for example as a Docker secret), set this to a file + # containing 32 raw bytes or 64 hexadecimal characters, mode 0600. + # encryption_key_file: /run/secrets/edgewatch-notification-key + # + # Deprecated: urls and urls_file. The daemon imports each URL listed here + # once as an encrypted destination in the web console and then no longer + # uses it; each start warns until you remove both keys. A later release + # refuses to start while either is set. A URL file must be a regular, + # owner-readable (0400 or 0600) file with one Shoutrrr URL per line; symlinks + # and files larger than 1 MiB are rejected at startup. + # urls_file: /run/secrets/edgewatch-notification-urls + # urls: [] + # + # Notifications are delivered by a short-lived process that runs as the + # unprivileged UID 65531 without capabilities, restricted with Landlock. + # auto (the default) does so when the container grants SETUID, SETGID and + # KILL and that process can read the certificate authorities SSL_CERT_FILE + # and SSL_CERT_DIR name; required refuses to start without it; off never + # uses it. + sandbox: auto + +# Optional backups that the daemon takes on a schedule. They are off unless +# directory is set, an absolute path to an existing directory that EdgeWatch +# does not create. Each scheduled backup is checked as the backup command +# checks its output (quick_check, foreign_key_check, and the schema) before it +# is published as edgewatch-scheduled-YYYYMMDDTHHMMSSZ.db, and the daemon keeps +# the newest keep of those files, removing older scheduled backups. When an +# existing database needs a schema upgrade, the daemon also writes and verifies +# a pre-migration backup there before schema writes begin. Separately from +# keep, it retains the copy just written, the latest three other copies, and +# the newest copy for each qualifying (upgrade limit, source schema) pair in +# the unfinished-upgrade chain. Each limit is considered separately, so a +# source schema can have multiple protected copies. Retrying a failed upgrade +# never removes the copy the previous release can open. If the backup cannot be +# created or verified, migration stops. Without directory, the daemon warns and +# continues without a backup. +# schedule is a five-field cron expression in the timezone above, or UTC, +# without a TZ= prefix; it defaults to "0 3 * * *", and keep to 7 (1 to 1000). +# edgewatch health and the console report the newest good backup and any +# failure. A backup holds every business unit's data; keep the directory as +# private as ./edgewatch-data and copy the backups, with notification.key and +# auth.key, off the host. +# backup: +# directory: /var/lib/edgewatch/backups +# schedule: "0 3 * * *" +# keep: 7 + +# Jobs are created and scheduled from the web interface. YAML jobs from older +# releases are intentionally not imported; they remain inactive with a +# startup warning so they can be recreated and reviewed explicitly.