Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
26 changes: 26 additions & 0 deletions services/edgewatch/.env
Original file line number Diff line number Diff line change
@@ -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.
82 changes: 82 additions & 0 deletions services/edgewatch/README.md
Original file line number Diff line number Diff line change
@@ -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.<tailnet>.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 `<tailnet>` in `edgewatch.<tailnet>.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.<tailnet>.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)
99 changes: 99 additions & 0 deletions services/edgewatch/compose.yaml
Original file line number Diff line number Diff line change
@@ -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 <addr>:<port> 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
Loading