observability: run prometheus/loki/grafana as 1000:1000 (rootless uid mapping)

Container root maps to a subuid that owns nothing under /opt, so the
data-dir writes fail. Container uid 1000 is the invoking user in
rootless podman.
This commit is contained in:
Frank committed 2026-08-22 03:19:18 -07:00
1 parent 765fd2902a
commit 3c3f90e4c5
2 files changed
+24

No files matched your search

+9
View File
@@ -103,6 +103,9 @@ services:
image: docker.io/prom/prometheus:latest image: docker.io/prom/prometheus:latest
container_name: prometheus container_name: prometheus
restart: unless-stopped restart: unless-stopped
# Rootless: container uid 1000 maps to the invoking user, so the
# container can write its /opt/prometheus/data bind mount.
user: "1000:1000"
command: command:
- --config.file=/etc/prometheus/prometheus.yml - --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.path=/prometheus - --storage.tsdb.path=/prometheus
@@ -123,6 +126,9 @@ services:
image: docker.io/grafana/grafana:latest image: docker.io/grafana/grafana:latest
container_name: grafana container_name: grafana
restart: unless-stopped restart: unless-stopped
# Rootless: container uid 1000 maps to the invoking user, so the
# container can write its /opt/grafana/data bind mount.
user: "1000:1000"
environment: environment:
GF_SERVER_ROOT_URL: "https://grafana.franksdank.cloud" GF_SERVER_ROOT_URL: "https://grafana.franksdank.cloud"
GF_SECURITY_ADMIN_USER: "${GRAFANA_ADMIN_USER}" GF_SECURITY_ADMIN_USER: "${GRAFANA_ADMIN_USER}"
@@ -144,6 +150,9 @@ services:
image: docker.io/grafana/loki:latest image: docker.io/grafana/loki:latest
container_name: loki container_name: loki
restart: unless-stopped restart: unless-stopped
# Rootless: container uid 1000 maps to the invoking user, so the
# container can write its /opt/loki/data bind mount.
user: "1000:1000"
command: ["-config.file=/etc/loki/loki-config.yaml"] command: ["-config.file=/etc/loki/loki-config.yaml"]
ports: ports:
- "3100:3100" - "3100:3100"
+15
View File
@@ -118,3 +118,18 @@ CADDYFILE="$REPO_ROOT/dankclaw/Caddyfile"
@test "prometheus targets are host:port (no URL schemes)" { @test "prometheus targets are host:port (no URL schemes)" {
! grep -nE '^\s*-\s*"?http' "$REPO_ROOT/shared/prometheus/prometheus.yml" ! grep -nE '^\s*-\s*"?http' "$REPO_ROOT/shared/prometheus/prometheus.yml"
} }
@test "observability containers run as the host user (rootless uid mapping)" {
# Rootless podman maps container uid 1000 to the invoking user, so
# 1000:1000 lets these containers write their /opt data dirs. Container
# root would map to a subuid that owns nothing under /opt.
local compose="$REPO_ROOT/dankclaw/compose.yaml"
local svc
for svc in prometheus loki grafana; do
local block
block=$(awk "/^ $svc:$/,/^ [a-z]/" "$compose" | grep -v "^ $svc:")
echo "$block" | grep -q 'user: "1000:1000"' || {
echo "service $svc does not run as user 1000:1000"; return 1;
}
done
}