|
|
@@ -50,23 +50,37 @@ Verify:
|
|
|
dig +short eks-relay.easyklima.com # Cloudflare anycast IPs
|
|
|
```
|
|
|
|
|
|
-### Cloudflare and automated POSTs
|
|
|
+### Cloudflare WAF — two rules are required
|
|
|
|
|
|
-Cloudflare's managed challenge can block server-to-server POSTs from Chatwoot
|
|
|
-and Flowise. If that happens, add a **narrow** WAF skip rule — scoped to this
|
|
|
-hostname and these paths only, never a zone-wide bypass:
|
|
|
+Cloudflare's managed challenge blocks server-to-server calls in **both**
|
|
|
+directions. Two narrow skip rules are in place; neither is a zone-wide bypass,
|
|
|
+and both endpoints keep their own bearer authentication.
|
|
|
+
|
|
|
+**1. Inbound — zone `easyklima.com`** (Chatwoot and Flowise reaching the relay).
|
|
|
+Without it every request to the relay gets a `403` challenge page:
|
|
|
|
|
|
```
|
|
|
-Expression:
|
|
|
(http.host eq "eks-relay.easyklima.com" and
|
|
|
(starts_with(http.request.uri.path, "/webhooks/") or
|
|
|
- starts_with(http.request.uri.path, "/tools/")))
|
|
|
+ starts_with(http.request.uri.path, "/tools/") or
|
|
|
+ http.request.uri.path eq "/health" or
|
|
|
+ http.request.uri.path eq "/ready"))
|
|
|
+```
|
|
|
+
|
|
|
+**2. Outbound — zone `easyklima.pl`** (the relay reaching the shop's REST APIs).
|
|
|
+Without it every WooCommerce and `eksrelay/v1` call gets a `403` challenge, so
|
|
|
+every shop-backed tool fails:
|
|
|
|
|
|
-Action: Skip → Managed Rules, Bot Fight Mode, Rate limiting
|
|
|
```
|
|
|
+(ip.src eq 18.168.156.244 and starts_with(http.request.uri.path, "/wp-json/"))
|
|
|
+```
|
|
|
+
|
|
|
+Both use `action: skip` over phases `http_ratelimit`,
|
|
|
+`http_request_firewall_managed`, `http_request_sbfm` and products
|
|
|
+`uaBlock, bic, hot, securityLevel, rateLimit, waf` — matching the convention of
|
|
|
+the pre-existing rules in these zones.
|
|
|
|
|
|
-The endpoints stay protected by their own bearer secrets; the skip rule only
|
|
|
-removes Cloudflare's browser-oriented challenges.
|
|
|
+If the relay ever moves to another host, rule 2's source IP must move with it.
|
|
|
|
|
|
## 2. Server checkout
|
|
|
|
|
|
@@ -78,7 +92,27 @@ git config user.name "Maciek"
|
|
|
git config user.email "maciek@aiac.local"
|
|
|
```
|
|
|
|
|
|
-It is a normal checkout, so `git pull` and `git push` both work on the server.
|
|
|
+It is a normal checkout, so `git pull` and `git push` both work on the server
|
|
|
+(push verified by tagging the deployed commit `deployed-acmycar-20260820`).
|
|
|
+
|
|
|
+Anonymous read works, so `clone` and `pull` need no credentials. `push` does;
|
|
|
+supply them through a temporary `GIT_ASKPASS` helper and delete it afterwards —
|
|
|
+never store credentials on the server or put them in the remote URL:
|
|
|
+
|
|
|
+```bash
|
|
|
+umask 077
|
|
|
+cat > /tmp/.ap.sh <<'EOF'
|
|
|
+#!/bin/sh
|
|
|
+case "$1" in
|
|
|
+ *Username*) printf "%s" "$GIT_USER" ;;
|
|
|
+ *Password*) printf "%s" "$GIT_PASS" ;;
|
|
|
+esac
|
|
|
+EOF
|
|
|
+chmod 700 /tmp/.ap.sh
|
|
|
+GIT_USER=... GIT_PASS=... GIT_ASKPASS=/tmp/.ap.sh GIT_TERMINAL_PROMPT=0 \
|
|
|
+ git push origin master
|
|
|
+rm -f /tmp/.ap.sh
|
|
|
+```
|
|
|
|
|
|
## 3. Environment
|
|
|
|
|
|
@@ -131,6 +165,19 @@ only when `package-lock.json` changed, regenerates the Prisma client only when
|
|
|
|
|
|
Rebuild (`--build`) only when the Dockerfile or its base image changes.
|
|
|
|
|
|
+> **`restart` does not re-read `.env`.** Docker Compose bakes `env_file` values
|
|
|
+> into the container at create time, so after editing `.env` you need
|
|
|
+> `sudo docker compose up -d` (which recreates the container), not `restart`.
|
|
|
+> For code-only changes `restart` is the faster path.
|
|
|
+
|
|
|
+### Live-reload while debugging
|
|
|
+
|
|
|
+Set `RELAY_MODE=dev` in `.env` and run `sudo docker compose up -d`. The
|
|
|
+container then runs `tsx watch`, so saving a file reloads the process in place —
|
|
|
+no restart and no rebuild. Set it back to `prod` and `up -d` again when done;
|
|
|
+prod mode compiles once and runs `dist/`, which is what should serve real
|
|
|
+traffic.
|
|
|
+
|
|
|
## Database
|
|
|
|
|
|
SQLite at `/home/ubuntu/eks_relay/data/eks_relay.db`, bind-mounted into the
|