grafana: serve it on the bare WireGuard IP (drop HTTPRoute hostnames)
A phone cannot edit /etc/hosts, so it sends Host: 10.10.0.2:8081, matches no .lab.internal route and gets a 404 from Envoy. With no hostnames on the route any Host on the internal listener matches, so http://10.10.0.2:8081/ serves Grafana and the named URL keeps working. Port 8081 stays Grafana-only; docs now state the bare-IP rule and the phone-path tests.
This commit is contained in:
parent
7ca85669b2
commit
8939cbdd78
2 changed files with 50 additions and 23 deletions
|
|
@ -31,8 +31,16 @@ only". Consequences:
|
|||
`192.168.1.179:8081` and the public interface the moment it is Programmed.
|
||||
- The Gateway object cannot enforce the network boundary. **The host firewall
|
||||
is the enforcement point.** That is the whole trick.
|
||||
- Routing on the internal listener is hostname-based, so the service is reached
|
||||
as `http://<name>.lab.internal:8081` with an `/etc/hosts` entry on the client.
|
||||
- The service is reached as **`http://10.10.0.2:<port>/`** — no `/etc/hosts`
|
||||
entry, no `Host` header. The HTTPRoute must therefore carry **no
|
||||
`hostnames`**, or a phone (which cannot edit a hosts file) sends
|
||||
`Host: 10.10.0.2:8081`, matches no `.lab.internal` route, and Envoy answers
|
||||
**404**. A hostname-less route matches any `Host` on its listener, so the
|
||||
named `http://<name>.lab.internal:8081` URL keeps working for laptops that
|
||||
do have the hosts line.
|
||||
- **One service per listener port.** Two hostname-less routes on one listener
|
||||
make precedence ambiguous, so the next internal service takes a new port
|
||||
(and its own firewall rules, §5) instead of sharing 8081.
|
||||
|
||||
Public traffic has no path here: the only public ingress is the cloudflared
|
||||
tunnel, whose ingress list is an explicit allow-list of hostnames pointing at
|
||||
|
|
@ -55,25 +63,31 @@ address (and the other node answers 503, which still proves a listener exists).
|
|||
|
||||
## 3. Current internal services
|
||||
|
||||
| Service | URL (over WireGuard) | Client `/etc/hosts` line | Route |
|
||||
| Service | URL (over WireGuard) | Optional client `/etc/hosts` line | Route |
|
||||
|---|---|---|---|
|
||||
| Grafana | `http://grafana.lab.internal:8081/` | `10.10.0.2 grafana.lab.internal` | `monitoring/grafana` |
|
||||
| Grafana | **`http://10.10.0.2:8081/`** (also `http://grafana.lab.internal:8081/`) | `10.10.0.2 grafana.lab.internal` | `monitoring/grafana` |
|
||||
|
||||
Always use **siriussec's** address (`10.10.0.2`) in the hosts file, not the
|
||||
Pi's: Envoy on a node that does not run the backend pods completes the TCP
|
||||
handshake and then hangs (SYN-ACK back, no ACK — see the co-location pitfall in
|
||||
the `home-k8s` skill). The backends are pinned to siriussec, so 10.10.0.2 is
|
||||
the only origin that works.
|
||||
**The rule: every internal service must be reachable as
|
||||
`http://10.10.0.2:<port>/` with no `Host` header and no hosts-file entry**,
|
||||
because phones cannot edit `/etc/hosts`. The bare-IP URL is the one to hand
|
||||
out; the named URL is a convenience for machines that already have the line.
|
||||
|
||||
Always use **siriussec's** address (`10.10.0.2`), not the Pi's: Envoy on a node
|
||||
that does not run the backend pods completes the TCP handshake and then hangs
|
||||
(SYN-ACK back, no ACK — see the co-location pitfall in the `home-k8s` skill).
|
||||
The backends are pinned to siriussec, so 10.10.0.2 is the only origin that
|
||||
works.
|
||||
|
||||
## 4. Add the next internal service
|
||||
|
||||
1. **Confirm the port is firewalled.** `:8081` is closed to the LAN already; a
|
||||
new listener port needs its own rules (see §5). Reuse 8081 unless two
|
||||
services must be distinguished by port.
|
||||
new listener port needs its own rules (see §5). **Do not reuse 8081** — one
|
||||
listener port carries exactly one internal service, so a second
|
||||
hostname-less route can never compete with Grafana's.
|
||||
2. **Deploy the workload** in its own namespace, pinned with
|
||||
`nodeSelector: {kubernetes.io/hostname: siriussec}` (amd64 + local-path; the
|
||||
Pi is arm64 and its listener only serves pods scheduled on the Pi).
|
||||
3. **Add the route** next to the workload:
|
||||
3. **Add the route** next to the workload — **without `hostnames`**:
|
||||
|
||||
```yaml
|
||||
apiVersion: gateway.networking.k8s.io/v1
|
||||
|
|
@ -85,9 +99,7 @@ the only origin that works.
|
|||
parentRefs:
|
||||
- name: internal
|
||||
namespace: internal
|
||||
sectionName: http-internal
|
||||
hostnames:
|
||||
- <name>.lab.internal
|
||||
sectionName: http-internal-<port> # its own listener on its own port
|
||||
rules:
|
||||
- matches:
|
||||
- path: {type: PathPrefix, value: /}
|
||||
|
|
@ -99,11 +111,12 @@ the only origin that works.
|
|||
A `ReferenceGrant` is only needed for cross-namespace *backends*; the route
|
||||
itself is allowed by `allowedRoutes: All` on the listener.
|
||||
4. Commit, push, reconcile (repo → `gitrepository`, then the app's
|
||||
`kustomization`), then **prove it from the mesh**:
|
||||
`kustomization`), then **prove it from the mesh** — bare IP first, because
|
||||
that is the phone path:
|
||||
|
||||
```bash
|
||||
curl -sS -o /dev/null -w '%{http_code}\n' \
|
||||
-H 'Host: <name>.lab.internal' http://10.10.0.2:8081/
|
||||
curl -sS -o /dev/null -w '%{http_code}\n' http://10.10.0.2:<port>/ # -> 200/302, never 404
|
||||
curl -sSL -m 6 http://10.10.0.2:<port>/login | head -c 200 # -> HTML, no absolute redirect
|
||||
```
|
||||
5. Add the row to the table in §3.
|
||||
|
||||
|
|
@ -132,12 +145,19 @@ ufw insert 2 allow from 10.244.0.0/16 to any port <port> proto tcp comment 'inte
|
|||
## 6. Negative tests (run these after every change)
|
||||
|
||||
```bash
|
||||
# 0. From a mesh host: the BARE-IP phone path, and the login page via it.
|
||||
# Grafana must not hard-redirect to a .internal name (no root_url/domain set).
|
||||
curl -sS -m 6 -o /dev/null -w '%{http_code}\n' http://10.10.0.2:8081/ # -> 302 (login), never 404
|
||||
curl -sSL -m 6 -o /dev/null -w '%{http_code} redirects=%{num_redirects}\n' \
|
||||
http://10.10.0.2:8081/login # -> 200, no absolute Location
|
||||
curl -sS -m 6 -D- -o /dev/null http://10.10.0.2:8081/ | grep -i '^location:' # -> /login (relative)
|
||||
|
||||
# 1. From a LAN host (Legion on 192.168.1.0/24, or rpi toward siriussec):
|
||||
# DROP = timeout, not connection-refused and never 200.
|
||||
curl -m 3 -sS -o /dev/null -w '%{http_code}\n' http://192.168.1.179:8081/ # -> 000 (timed out)
|
||||
curl -m 3 -sS -o /dev/null -w '%{http_code}\n' http://192.168.1.125:8081/ # -> 000 (timed out)
|
||||
|
||||
# 2. From a mesh host, the listener must still work:
|
||||
# 2. From a mesh host, the named URL must still work:
|
||||
curl -sS -o /dev/null -w '%{http_code}\n' -H 'Host: grafana.lab.internal' http://10.10.0.2:8081/ # -> 302 (login)
|
||||
|
||||
# 3. Not in the public tunnel's ingress list (run on rpi):
|
||||
|
|
|
|||
|
|
@ -2,8 +2,17 @@
|
|||
# one, fed by the Cloudflare tunnel). There is no Cloudflare ingress entry for
|
||||
# this hostname and there must never be one.
|
||||
#
|
||||
# Reachable at http://grafana.lab.internal:8081 over WireGuard:
|
||||
# Legion /etc/hosts: 10.10.0.2 grafana.lab.internal
|
||||
# Reachable over WireGuard, and deliberately WITHOUT a Host header mapping:
|
||||
# phones: http://10.10.0.2:8081/
|
||||
# laptops: http://grafana.lab.internal:8081/ (10.10.0.2 grafana.lab.internal)
|
||||
#
|
||||
# `hostnames` is intentionally ABSENT: a phone sends `Host: 10.10.0.2:8081`,
|
||||
# which matches no `.lab.internal` hostname, and Envoy answers 404. A route
|
||||
# with no hostnames matches any Host on the listener, so both URLs work.
|
||||
# Port 8081 is Grafana's alone — do not attach a second hostname-less route to
|
||||
# `http-internal`: two bare routes on one listener make precedence ambiguous,
|
||||
# so any future internal service gets its own listener port.
|
||||
#
|
||||
# The listener answers only on 10.10.0.0/24 + the pod CIDR — the host firewall
|
||||
# (see docs/internal-wireguard-services.md) drops :8081 everywhere else.
|
||||
apiVersion: gateway.networking.k8s.io/v1
|
||||
|
|
@ -16,8 +25,6 @@ spec:
|
|||
- name: internal
|
||||
namespace: internal
|
||||
sectionName: http-internal
|
||||
hostnames:
|
||||
- grafana.lab.internal
|
||||
rules:
|
||||
- matches:
|
||||
- path:
|
||||
|
|
|
|||
Loading…
Reference in a new issue