Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -0,0 +1,26 @@
# Cap Standalone env for staging/prod. Copy to `.env` next to the compose file,
# chmod 600, and replace every CHANGE_ME value.
CAP_IMAGE=tiago2/cap:3.1.5
ADMIN_KEY=CHANGE_ME_RANDOM_MIN_32_CHARS
REDIS_URL=redis://valkey:6379
REDIS_PREFIX=hivegrid:cap:
# Serve widget.js and WASM from the self-hosted Cap instance instead of jsDelivr.
ENABLE_ASSETS_SERVER=true
WIDGET_VERSION=0.1.56
WASM_VERSION=0.0.7
# Comma-separated browser origins allowed to generate/redeem challenges.
# Staging example:
# CORS_ORIGIN=https://staging-app.hivegrid.de,https://staging-api.hivegrid.de
# Production example:
# CORS_ORIGIN=https://app.hivegrid.de,https://admin.hivegrid.de,https://api.hivegrid.de
CORS_ORIGIN=
# Cloudflare-proxied hosts should rate-limit by the real visitor IP header.
RATELIMIT_IP_HEADER=cf-connecting-ip
# Optional diagnostics. Keep false in production unless actively debugging.
SHOW_ERRORS=false
DISABLE_ERROR_LOGGING=false
@@ -0,0 +1,7 @@
# Staging Cap on node1. DNS should point captcha-staging.hivegrid.de to node1
# while the record is DNS-only until Caddy has issued the certificate.
captcha-staging.hivegrid.de {
encode zstd gzip
reverse_proxy 127.0.0.1:7300
}
@@ -0,0 +1,136 @@
# Self-hosted Cap
Cap is the replacement candidate for mCaptcha. It keeps the same HiveGrid
principle as mCaptcha: self-hosted, no Google/Cloudflare CAPTCHA dependency,
and no third-party widget CDN. The app loads `/assets/widget.js` and WASM from
the Cap instance itself.
## Domain requirement
Cap needs a public HTTPS URL. The browser calls the Cap instance to generate and
solve challenges, and the app server calls the same instance for `siteverify`.
A raw private IP is not a good production setup because browser TLS, CORS,
Cloudflare proxying, and asset loading all depend on a stable public origin.
Recommended hostnames:
- Staging: `https://captcha-staging.hivegrid.de` on node1 (`176.9.111.179`)
- Production: `https://captcha.hivegrid.de` on `hivegrid-prod-worker`
## Staging on node1
node1 runs Cap as a plain docker-compose stack and exposes it through the
existing Coolify Traefik proxy (`coolify-proxy`). The compose service also
joins the external `coolify` network with the stable alias `cap-staging`, so
Traefik can reach it without publishing Cap directly to the public interface.
1. Create DNS `captcha-staging.hivegrid.de -> 176.9.111.179`, DNS-only until
Traefik has issued the certificate.
2. Copy `docker-compose.node1.yml` and `.env.example` to `/opt/cap/` on node1.
3. Create `/opt/cap/.env` from `.env.example`, set `ADMIN_KEY`, and set:
```env
CORS_ORIGIN=https://staging-app.hivegrid.de,https://staging-api.hivegrid.de,https://staging.hivegrid.de
```
4. Start Cap:
```sh
docker compose -f docker-compose.node1.yml up -d
```
5. Install the Traefik dynamic config on node1, then restart the proxy:
```sh
cp traefik-staging.yaml /data/coolify/proxy/dynamic/cap-staging.yaml
docker restart coolify-proxy
```
6. Open `https://captcha-staging.hivegrid.de`, log in with `ADMIN_KEY`, and
create site keys for `login`, `forms`, and `booking`. Keep each public
sitekey and its matching site secret.
7. Set the staging web app env:
```env
CAPTCHA_PROVIDER=cap
CAP_INSTANCE_URL=https://captcha-staging.hivegrid.de
CAP_SITEKEY_LOGIN=<login sitekey>
CAP_SITE_SECRET_LOGIN=<login secret>
CAP_SITEKEY_FORMS=<forms sitekey>
CAP_SITE_SECRET_FORMS=<forms secret>
CAP_SITEKEY_BOOKING=<booking sitekey>
CAP_SITE_SECRET_BOOKING=<booking secret>
CAPTCHA_FAIL_OPEN=true
```
## Production on worker/services VM
Production should run as a Coolify compose service on `hivegrid-prod-worker`
(`49.13.24.190`, private `10.0.0.5`) with FQDN `captcha.hivegrid.de`.
1. In Coolify, create a Docker Compose service from
`infra/cap/docker-compose.coolify.yml`.
2. Set `SERVICE_FQDN_CAP_3000=captcha.hivegrid.de`.
3. Create the service `.env` from `.env.example` and set:
```env
CORS_ORIGIN=https://app.hivegrid.de,https://admin.hivegrid.de,https://api.hivegrid.de
```
4. Deploy and verify `https://captcha.hivegrid.de` returns the Cap dashboard.
5. Create the same three site keys (`login`, `forms`, `booking`).
6. Set the production web env to the `CAP_*` values and redeploy web.
7. Keep the old `MCAPTCHA_*` values available until the Cap rollout is verified.
Rollback is `CAPTCHA_PROVIDER=mcaptcha` plus a web redeploy.
## App integration contract
The web app reads:
```env
CAPTCHA_PROVIDER=cap
CAP_INSTANCE_URL=https://...
CAP_SITEKEY_LOGIN=...
CAP_SITE_SECRET_LOGIN=...
CAP_SITEKEY_FORMS=...
CAP_SITE_SECRET_FORMS=...
CAP_SITEKEY_BOOKING=...
CAP_SITE_SECRET_BOOKING=...
CAPTCHA_FAIL_OPEN=true
```
When Cap is active, the UI renders:
```html
<cap-widget data-cap-api-endpoint="https://<cap-host>/<sitekey>/"></cap-widget>
```
The widget injects `cap-token` into the enclosing form. Server-side verification
uses:
```http
POST https://<cap-host>/<sitekey>/siteverify
Content-Type: application/json
{ "secret": "<site secret>", "response": "<cap-token>" }
```
The expected valid response is `{ "success": true }`.
`Caddyfile.staging.snippet` is kept as a fallback for a non-Coolify node1
setup. The active staging setup uses `traefik-staging.yaml`.
## Cutover checklist
- Staging Cap dashboard reachable over HTTPS.
- `/assets/widget.js` and `/assets/cap_wasm_bg.wasm` return 200 from the Cap
host.
- Staging web env uses `CAPTCHA_PROVIDER=cap`.
- Register/login captcha path verifies with a real browser.
- Public form with captcha enabled submits successfully once and rejects token
replay.
- Production Cap deploy is healthy behind Cloudflare.
- Production web deploy completed after `CAP_*` env is set.
- mCaptcha rollback env remains available until Cap has run through one live
deploy cycle.
@@ -0,0 +1,35 @@
# Self-hosted Cap Standalone for HiveGrid production.
#
# Intended as a Coolify Docker Compose service on hivegrid-prod-worker
# (worker/services VM). Coolify/Traefik terminates TLS for captcha.hivegrid.de.
name: hivegrid-prod-cap
volumes:
cap-valkey-data:
services:
cap:
image: ${CAP_IMAGE:-tiago2/cap:3.1.5}
restart: unless-stopped
env_file: [.env]
expose:
- "3000"
environment:
# Coolify generates the Traefik route for captcha.hivegrid.de from this.
- SERVICE_FQDN_CAP_3000=${SERVICE_FQDN_CAP_3000:-captcha.hivegrid.de}
depends_on:
valkey:
condition: service_healthy
valkey:
image: valkey/valkey:9-alpine
restart: unless-stopped
volumes:
- cap-valkey-data:/data
command: valkey-server --save 60 1 --loglevel warning --maxmemory-policy noeviction
healthcheck:
test: ["CMD", "valkey-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
@@ -0,0 +1,46 @@
# Self-hosted Cap Standalone for staging/node1.
#
# node1 runs this as a plain docker-compose stack behind the existing
# Coolify Traefik proxy. The Cap container joins the external coolify network
# as cap-staging; the host port is kept on localhost for direct diagnostics.
name: cap
networks:
cap-net:
name: cap-net
coolify:
external: true
volumes:
cap-valkey-data:
name: cap-valkey-data
services:
cap:
image: ${CAP_IMAGE:-tiago2/cap:3.1.5}
restart: unless-stopped
networks:
cap-net:
coolify:
aliases:
- cap-staging
env_file: [.env]
ports:
- "127.0.0.1:7300:3000"
depends_on:
valkey:
condition: service_healthy
valkey:
image: valkey/valkey:9-alpine
restart: unless-stopped
networks: [cap-net]
volumes:
- cap-valkey-data:/data
command: valkey-server --save 60 1 --loglevel warning --maxmemory-policy noeviction
healthcheck:
test: ["CMD", "valkey-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
@@ -0,0 +1,33 @@
http:
routers:
cap-staging-secure:
rule: "Host(`captcha-staging.hivegrid.de`)"
entryPoints:
- https
service: cap-staging
middlewares:
- cap-staging-security-headers
tls:
certResolver: letsencrypt
cap-staging-web:
rule: "Host(`captcha-staging.hivegrid.de`)"
entryPoints:
- http
service: cap-staging
middlewares:
- cap-staging-https
services:
cap-staging:
loadBalancer:
servers:
- url: "http://cap-staging:3000"
middlewares:
cap-staging-https:
redirectScheme:
scheme: https
cap-staging-security-headers:
headers:
customResponseHeaders:
X-Robots-Tag: "noindex, nofollow"
contentTypeNosniff: true
referrerPolicy: "no-referrer"