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
3 changes: 2 additions & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ Two collection paths, because the estate has two kinds of device:
- **Things that run an agent.** Linux hosts get a Grafana Alloy agent, which
gathers node metrics, cAdvisor container metrics, the systemd journal, syslog
and `auth.log`, then pushes to Loki and remote-writes to Prometheus. The same
`alloy/` directory runs everywhere — `config.alloy` on every host,
`alloy/` directory runs everywhere — `config.alloy` (metrics) on every host,
`logs.alloy` with it except on a metrics-only host like `gandalf` ([ADR-0126](adr/0126-monitor-gandalf-now-that-it-stays-on.md)),
`docker.alloy` where there is a Docker socket, `syslog.alloy` only here — and
`scripts/deploy-agent.sh` ships the right subset, in a container or as the
native package; only the endpoint variables differ.
Expand Down
15 changes: 15 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ docstring gives: it is a record, not a claim about now.
about one every seven seconds by the afternoon: 987 of the 1,000 lines in
the buffer. Nothing saw it, because nothing read the switch's log. Not
fixed here.
- **The agent's log pipeline is its own file, so the range host can ship
metrics and no logs ([#1651](https://github.com/Gerrrt/HomeLab/issues/1651),
[ADR-0126](adr/0126-monitor-gandalf-now-that-it-stays-on.md)).** `config.alloy`
mixed the metrics and log pipelines, and `gandalf`'s journal and auth logs
can carry what happens on the attacker's segment. The log sources, the level
normaliser and `loki.write` move to a new `logs.alloy`, deployed with
`config.alloy` everywhere but a metrics-only host. `deploy-agent.sh` gains
`--metrics-only`: it omits `logs.alloy` (and refuses a docker host, whose
`docker.alloy` needs the log pipeline) and verifies metrics alone. The five
stacks that mount `config.alloy` individually now mount `logs.alloy` beside
it; the observability stack mounts the whole directory, so it picks it up.
`build-the-playground.md` §7 gives `gandalf`'s deploy command. The split was
checked with `alloy validate` on the whole directory and on `config.alloy`
alone (the metrics-only case), both clean, so every cross-file reference
resolves and the metrics-only config has no dangling one.
- **`prometheus` will take SSH keys only, and stays without a host firewall
([ADR-0128](adr/0128-give-prometheus-a-key-only-sshd-and-no-host-firewall.md)).**
The root-only reads that finished the 2026-11-13 audit were taken today.
Expand Down
2 changes: 1 addition & 1 deletion docs/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ equivalent size bound.
## Log level normalisation

Logs arrive spelling severity about twenty different ways — `ERROR`, `err`,
`eror`, `crit`, `fatal`, `panic`, `dbug`. `config.alloy` maps all of them onto
`eror`, `crit`, `fatal`, `panic`, `dbug`. `logs.alloy` maps all of them onto
five canonical values before they reach Loki:

```text
Expand Down
27 changes: 22 additions & 5 deletions docs/runbooks/build-the-playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -1469,11 +1469,28 @@ ADR-0126 does not allow. `range-state` is `gandalf`'s own control file

**Then the agent, metrics only.** `gandalf`'s journal and auth logs can carry
what happens on the attacker's segment, so its agent must not ship them to
Loki. The estate's standard `config.alloy` pushes both metrics and logs, so a
metrics-only variant (no `loki.*`, no `3100`) and a deploy check that requires
only metrics are what [`deploy-agent.sh`](../../scripts/deploy-agent.sh) needs
for this host — **still to build (#1651)**; until it exists, do not deploy the
standard agent here, which would ship the range's logs.
Loki. The log pipeline is its own file, `logs.alloy`, deployed with
`config.alloy` everywhere but here;
[`deploy-agent.sh`](../../scripts/deploy-agent.sh) `--metrics-only` leaves it
off and verifies metrics alone.

**Register `gandalf`'s ingest token first**, or the deploy stops for a missing
token and the proxy answers every push with `401`. Do
[`add-monitored-device.md`](add-monitored-device.md)'s *First, the host's
token*: add `INGEST_TOKEN_gandalf` to `secrets/observability.sops.yaml`, add
its line to the ingest proxy's allowlist and compose environment, and `make up`
so the proxy is recreated with it — exporting the token on Hicks alone does not
register it. Then, from a Hicks workstation:

```bash
scripts/deploy-agent.sh --metrics-only --runtime native root@10.0.30.30
```

`--runtime native` because `gandalf` runs the package, not a container; a
docker host cannot be metrics-only, since `docker.alloy` needs the log
pipeline. The agent then pushes node and collector metrics to
`10.0.99.20:9090` and no logs. This is the one crossing the `morpheus` pass
above carries.

**What it watches.** Once the collectors report, `gandalf` joins the
`PveFirewall*` alerts in `host.rules.yaml`, and
Expand Down
76 changes: 51 additions & 25 deletions scripts/deploy-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# Deploy, or redeploy, the Alloy agent on a monitored host.
#
# ./scripts/deploy-agent.sh [--runtime docker|native] [--monitoring-host IP]
# [--no-verify] <user@host>
# [--no-verify] [--metrics-only] <user@host>
# --metrics-only ships config.alloy without logs.alloy — metrics, no logs,
# for the range host gandalf (#1651); it cannot be a docker host.
#
# One command, two runtimes, same result: the agent on the target runs the
# Alloy version compose.yaml pins, with the hardening compose.yaml applies, on
Expand Down Expand Up @@ -109,20 +111,22 @@ warn() { printf '\033[0;33m!\033[0m %s\n' "$*" >&2; }
die() { printf '\033[0;31m✗\033[0m %s\n' "$*" >&2; exit 1; }

usage() {
sed -n '3,6p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//' >&2
sed -n '3,7p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//' >&2
exit "${1:-1}"
}

RUNTIME=""
MON="10.0.99.20"
VERIFY=1
METRICS_ONLY=0
TARGET=""

while (($#)); do
case "$1" in
--runtime) RUNTIME="${2:-}"; shift 2 ;;
--monitoring-host) MON="${2:-}"; shift 2 ;;
--no-verify) VERIFY=0; shift ;;
--metrics-only) METRICS_ONLY=1; shift ;;
-h|--help) usage 0 ;;
-*) die "unknown flag: $1" ;;
*) [[ -z "$TARGET" ]] || die "one target only (got '$TARGET' and '$1')"
Expand Down Expand Up @@ -190,9 +194,18 @@ if [[ -z "$RUNTIME" ]]; then
info "runtime not given; ${HOST} has $([[ $RUNTIME == docker ]] && echo "a Docker socket" || echo "no docker binary") → ${RUNTIME}"
fi

# Which files this host gets. Never syslog.alloy — see the header.
# Which files this host gets. config.alloy is the metrics pipeline; logs.alloy
# is the log pipeline (#1651), deployed with it everywhere EXCEPT a
# --metrics-only host, which ships metrics and no logs. docker.alloy's
# components forward to logs.alloy's log_processor and loki.write, so it cannot
# ride a metrics-only deploy. Never syslog.alloy — see the header.
FILES=(config.alloy)
[[ "$RUNTIME" == docker ]] && FILES+=(docker.alloy)
if ((METRICS_ONLY)); then
[[ "$RUNTIME" != docker ]] || die "--metrics-only cannot ship docker.alloy, whose log components need the logs.alloy pipeline this mode leaves off"
else
FILES+=(logs.alloy)
[[ "$RUNTIME" == docker ]] && FILES+=(docker.alloy)
fi
# The estate's CA, at the path the agent will read it from: /etc/alloy is the
# config directory on both runtimes, and Alloy loads only *.alloy from it
# (measured on the pinned image with a .pem beside the config).
Expand Down Expand Up @@ -636,17 +649,26 @@ if ((VERIFY)); then
# The marker. logger(1) is util-linux, present on every target this ships
# to, and needs no root. If it is missing anyway, fall back to asking for
# any line newer than the deploy, and say that a quiet host can fail that.
# A --metrics-only host ships no logs (#1651), so there is nothing to look
# for in Loki: in_loki starts satisfied and no marker is sent.
loki_query="${marker_logql}"; loki_since=$((ARRIVED_AFTER - 600)); loki_what="the deploy's marker line"
loki_until=$((ARRIVED_AFTER + 180 + 600)) # the 3-minute wait, plus the skew allowance
marker_sent=1
if ! "${SSH[@]}" "logger -t homelab-deploy-check '${MARKER}'" 2>/dev/null; then
warn "could not run logger on ${HOST}; looking for any line newer than the deploy instead, which an idle host can fail"
loki_query="${logql}"; loki_since="${ARRIVED_AFTER}"; loki_what="a line newer than the deploy"
marker_sent=0
marker_sent=0
in_loki=0
if ((METRICS_ONLY)); then
in_loki=1
info "waiting for metrics newer than the deploy from ${HOST} in Prometheus at ${MON} (up to 3 min); metrics only, no logs"
else
marker_sent=1
if ! "${SSH[@]}" "logger -t homelab-deploy-check '${MARKER}'" 2>/dev/null; then
warn "could not run logger on ${HOST}; looking for any line newer than the deploy instead, which an idle host can fail"
loki_query="${logql}"; loki_since="${ARRIVED_AFTER}"; loki_what="a line newer than the deploy"
marker_sent=0
fi
info "waiting for data newer than the deploy from ${HOST} in Prometheus, and ${loki_what} in Loki, at ${MON} (up to 3 min)"
fi
info "waiting for data newer than the deploy from ${HOST} in Prometheus, and ${loki_what} in Loki, at ${MON} (up to 3 min)"
fresh_promql="count by (job) (timestamp(${promql}) > ${ARRIVED_AFTER})"
deadline=$((SECONDS + 180)); jobs=0; in_loki=0
deadline=$((SECONDS + 180)); jobs=0
while ((SECONDS < deadline)); do
# `|| true`, and it matters: until the first fresh sample lands, grep
# matches nothing and exits 1, pipefail makes that the pipeline's
Expand All @@ -655,7 +677,7 @@ if ((VERIFY)); then
jobs="$(mon_curl "${MON_URL}:${PROM_PORT}/api/v1/query" --data-urlencode "query=${fresh_promql}" 2>/dev/null \
| grep -o '"job":"[^"]*"' | sort -u | wc -l | tr -d ' ' || true)"
jobs="${jobs:-0}"
if mon_curl -G "${MON_URL}:${LOKI_PORT}/loki/api/v1/query_range" \
if ((!METRICS_ONLY)) && mon_curl -G "${MON_URL}:${LOKI_PORT}/loki/api/v1/query_range" \
--data-urlencode "query=${loki_query}" --data-urlencode "start=${loki_since}000000000" \
--data-urlencode "end=${loki_until}000000000" \
--data-urlencode "limit=1" --data-urlencode "direction=forward" 2>/dev/null \
Expand All @@ -671,22 +693,26 @@ if ((VERIFY)); then
warn "Prometheus has samples newer than the deploy from ${jobs} job(s) for instance=\"${HOST}\" (expected ${expected}). A refused token looks exactly like this: check the agent's log for 401, then ${TOKEN_KEY} in ${TOKEN_FILE} and its line in ${PROXY_FILE}. On another VLAN, check the pass to ${MON}:${PROM_PORT}."
arrival_failed=1
fi
if ((in_loki)); then
pass "Loki has ${loki_what} for host=\"${HOST}\""
if ((METRICS_ONLY)); then
pass "metrics only — no logs expected from ${HOST} (#1651)"
else
if ((marker_sent)); then
warn "Loki has not received ${loki_what} for host=\"${HOST}\". Same suspects as above, on ${MON}:${LOKI_PORT}. The marker was logged on ${HOST} as: ${MARKER}"
if ((in_loki)); then
pass "Loki has ${loki_what} for host=\"${HOST}\""
else
warn "Loki has not received ${loki_what} for host=\"${HOST}\". Same suspects as above, on ${MON}:${LOKI_PORT}."
if ((marker_sent)); then
warn "Loki has not received ${loki_what} for host=\"${HOST}\". Same suspects as above, on ${MON}:${LOKI_PORT}. The marker was logged on ${HOST} as: ${MARKER}"
else
warn "Loki has not received ${loki_what} for host=\"${HOST}\". Same suspects as above, on ${MON}:${LOKI_PORT}."
fi
arrival_failed=1
fi
dropped="$(mon_curl "${MON_URL}:${PROM_PORT}/api/v1/query" \
--data-urlencode "query=sum(increase(loki_write_dropped_entries_total{job=\"${HOST}-alloy\"}[5m]))" 2>/dev/null \
| grep -o '"value":\[[^]]*\]' | grep -o '"[0-9.e+-]*"\]' | tr -d '"]' || true)"
if [[ -n "${dropped}" ]] && awk -v d="${dropped}" 'BEGIN { exit !(d > 0) }'; then
warn "the agent has dropped ~${dropped} log entries in the last 5 min — see LogEntriesDropped; a 401 from the proxy is counted here"
arrival_failed=1
fi
arrival_failed=1
fi
dropped="$(mon_curl "${MON_URL}:${PROM_PORT}/api/v1/query" \
--data-urlencode "query=sum(increase(loki_write_dropped_entries_total{job=\"${HOST}-alloy\"}[5m]))" 2>/dev/null \
| grep -o '"value":\[[^]]*\]' | grep -o '"[0-9.e+-]*"\]' | tr -d '"]' || true)"
if [[ -n "${dropped}" ]] && awk -v d="${dropped}" 'BEGIN { exit !(d > 0) }'; then
warn "the agent has dropped ~${dropped} log entries in the last 5 min — see LogEntriesDropped; a 401 from the proxy is counted here"
arrival_failed=1
fi
fi
fi
Expand Down
1 change: 1 addition & 0 deletions stacks/analyst/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ services:
- /etc/alloy
volumes:
- ../observability/alloy/config.alloy:/etc/alloy/config.alloy:ro
- ../observability/alloy/logs.alloy:/etc/alloy/logs.alloy:ro
- ../observability/alloy/ingest-ca.pem:/etc/alloy/ingest-ca.pem:ro
- ../observability/alloy/docker.alloy:/etc/alloy/docker.alloy:ro
- alloy-data:/var/lib/alloy/data
Expand Down
1 change: 1 addition & 0 deletions stacks/bloodhound/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ services:
- /etc/alloy
volumes:
- ../observability/alloy/config.alloy:/etc/alloy/config.alloy:ro
- ../observability/alloy/logs.alloy:/etc/alloy/logs.alloy:ro
- ../observability/alloy/ingest-ca.pem:/etc/alloy/ingest-ca.pem:ro
- ../observability/alloy/docker.alloy:/etc/alloy/docker.alloy:ro
- ./alloy/bloodhound.alloy:/etc/alloy/bloodhound.alloy:ro
Expand Down
1 change: 1 addition & 0 deletions stacks/lab/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ services:
- /etc/alloy
volumes:
- ../observability/alloy/config.alloy:/etc/alloy/config.alloy:ro
- ../observability/alloy/logs.alloy:/etc/alloy/logs.alloy:ro
- ../observability/alloy/docker.alloy:/etc/alloy/docker.alloy:ro
- alloy-data:/var/lib/alloy/data
- /var/log:/var/log:ro
Expand Down
Loading