chore: added docker, openrc, systemd files and docs
15b472f1
6 file(s) · +137 −0
| 1 | + | # syntax=docker/dockerfile:1 |
|
| 2 | + | ||
| 3 | + | FROM golang:1.27-alpine AS build |
|
| 4 | + | ||
| 5 | + | WORKDIR /src |
|
| 6 | + | ||
| 7 | + | COPY go.mod go.sum ./ |
|
| 8 | + | RUN go mod download |
|
| 9 | + | ||
| 10 | + | COPY . . |
|
| 11 | + | ||
| 12 | + | RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /gargantua . |
|
| 13 | + | ||
| 14 | + | FROM alpine:3.22 |
|
| 15 | + | ||
| 16 | + | RUN addgroup -S gargantua && adduser -S -G gargantua gargantua |
|
| 17 | + | ||
| 18 | + | WORKDIR /app |
|
| 19 | + | ||
| 20 | + | COPY --from=build /gargantua /app/gargantua |
|
| 21 | + | COPY --chown=gargantua:gargantua moby.txt /app/moby.txt |
|
| 22 | + | ||
| 23 | + | USER gargantua |
|
| 24 | + | ||
| 25 | + | EXPOSE 8090 |
|
| 26 | + | ||
| 27 | + | ENTRYPOINT ["/app/gargantua"] |
| 23 | 23 | gargantua |
|
| 24 | 24 | ``` |
|
| 25 | 25 | ||
| 26 | + | Alternatively use Docker |
|
| 27 | + | ||
| 28 | + | ```bash |
|
| 29 | + | docker compose up -d --build |
|
| 30 | + | ``` |
|
| 31 | + | ||
| 32 | + | ## Running as a daemon |
|
| 33 | + | ||
| 34 | + | Ready-made service files for systemd and OpenRC live in `deploy/`. Both raise the file-descriptor limit to 1,000,000, since that limit is the ceiling on how many crawlers the tarpit can hold at once. You can read more about this in the [reasoning](#Reasoning). |
|
| 35 | + | ||
| 36 | + | First, build and install the binary and corpus: |
|
| 37 | + | ||
| 38 | + | ```bash |
|
| 39 | + | go build -o gargantua . |
|
| 40 | + | sudo mkdir -p /usr/local/share/gargantua |
|
| 41 | + | sudo cp gargantua /usr/local/bin/gargantua |
|
| 42 | + | sudo cp moby.txt /usr/local/share/gargantua/moby.txt |
|
| 43 | + | ``` |
|
| 44 | + | ||
| 45 | + | ### systemd |
|
| 46 | + | ||
| 47 | + | ```bash |
|
| 48 | + | sudo cp deploy/systemd/gargantua.service /etc/systemd/system/ |
|
| 49 | + | sudo systemctl enable --now gargantua |
|
| 50 | + | ``` |
|
| 51 | + | ||
| 52 | + | The unit uses `DynamicUser`, so no user account needs to be created. Tune behaviour by editing the `Environment=` lines in the unit. |
|
| 53 | + | ||
| 54 | + | ### OpenRC |
|
| 55 | + | ||
| 56 | + | ```bash |
|
| 57 | + | doas adduser -S -D -H gargantua |
|
| 58 | + | doas cp deploy/openrc/gargantua.initd /etc/init.d/gargantua |
|
| 59 | + | doas cp deploy/openrc/gargantua.confd /etc/conf.d/gargantua |
|
| 60 | + | doas rc-update add gargantua default |
|
| 61 | + | doas rc-service gargantua start |
|
| 62 | + | ``` |
|
| 63 | + | ||
| 64 | + | Configuration and the fd limit live in `/etc/conf.d/gargantua`, which OpenRC sources automatically on each start. Edit it and run `doas rc-service gargantua restart` to apply changes. |
|
| 65 | + | ||
| 26 | 66 | ## Configuration |
|
| 27 | 67 | ||
| 28 | 68 | Use the following environment variables to configure Gargantua |
| 1 | + | # /etc/conf.d/gargantua |
|
| 2 | + | ||
| 3 | + | # Raise the file-descriptor limit so the tarpit can hold many simultaneous |
|
| 4 | + | # connections. The kernel ceiling is /proc/sys/fs/nr_open (default 1048576). |
|
| 5 | + | rc_ulimit="-n 1000000" |
|
| 6 | + | ||
| 7 | + | supervise_daemon_args="--env GARGANTUA_HOST=0.0.0.0 \ |
|
| 8 | + | --env GARGANTUA_CORPUS=/usr/local/share/gargantua/moby.txt" |
| 1 | + | #!/sbin/openrc-run |
|
| 2 | + | ||
| 3 | + | name="gargantua" |
|
| 4 | + | description="Gargantua" |
|
| 5 | + | supervisor=supervise-daemon |
|
| 6 | + | ||
| 7 | + | command=/usr/local/bin/gargantua |
|
| 8 | + | command_user="gargantua:gargantua" |
|
| 9 | + | ||
| 10 | + | depend() { |
|
| 11 | + | need net |
|
| 12 | + | } |
| 1 | + | [Unit] |
|
| 2 | + | Description=Gargantua |
|
| 3 | + | Documentation=https://github.com/stevedylandev/gargantua |
|
| 4 | + | After=network-online.target |
|
| 5 | + | Wants=network-online.target |
|
| 6 | + | ||
| 7 | + | [Service] |
|
| 8 | + | Type=simple |
|
| 9 | + | ExecStart=/usr/local/bin/gargantua |
|
| 10 | + | ||
| 11 | + | # Listen on all interfaces; change if running behind a reverse proxy. |
|
| 12 | + | # Override any GARGANTUA_* variable from the Configuration section here. |
|
| 13 | + | Environment=GARGANTUA_HOST=0.0.0.0 |
|
| 14 | + | Environment=GARGANTUA_CORPUS=/usr/local/share/gargantua/moby.txt |
|
| 15 | + | ||
| 16 | + | # A tarpit holds many simultaneous connections; the default fd limit |
|
| 17 | + | # (often 1024) is the real ceiling on trapped crawlers, so raise it. |
|
| 18 | + | LimitNOFILE=1000000 |
|
| 19 | + | ||
| 20 | + | DynamicUser=yes |
|
| 21 | + | ProtectSystem=strict |
|
| 22 | + | ProtectHome=yes |
|
| 23 | + | NoNewPrivileges=yes |
|
| 24 | + | PrivateTmp=yes |
|
| 25 | + | ||
| 26 | + | Restart=on-failure |
|
| 27 | + | RestartSec=2s |
|
| 28 | + | ||
| 29 | + | [Install] |
|
| 30 | + | WantedBy=multi-user.target |
| 1 | + | services: |
|
| 2 | + | gargantua: |
|
| 3 | + | build: . |
|
| 4 | + | image: gargantua |
|
| 5 | + | restart: unless-stopped |
|
| 6 | + | ports: |
|
| 7 | + | - "8090:8090" |
|
| 8 | + | environment: |
|
| 9 | + | GARGANTUA_HOST: "0.0.0.0" |
|
| 10 | + | GARGANTUA_PORT: "8090" |
|
| 11 | + | GARGANTUA_DELAY_MIN_MS: "150" |
|
| 12 | + | GARGANTUA_DELAY_MAX_MS: "250" |
|
| 13 | + | GARGANTUA_CHUNK_MAX_BYTES: "45" |
|
| 14 | + | ulimits: |
|
| 15 | + | nofile: |
|
| 16 | + | soft: 1000000 |
|
| 17 | + | hard: 1000000 |
|
| 18 | + | # If netfilter conntrack is loaded on the host, this can cap held |
|
| 19 | + | # connections below the fd limit; raise it on the host via sysctl if needed: |
|
| 20 | + | # sysctl -w net.netfilter.nf_conntrack_max=1000000 |