swarm-otel, swarm-grafana: a delivery unit fails on no value yet
The collector's and Grafana's OIDC delivery units exited 0 when the store held no value, so systemd did not retry them. On a fresh swarm authelia's mint writes the secret about 30 s after the first read, and only the refresh timer, ten minutes on, read it again. Both units now exit 75, and the store retry they already carry asks every 30 s until the mint lands. Closes #6790
This commit is contained in:
parent
480855dfaf
commit
dad288d555
8 changed files with 88 additions and 22 deletions
|
|
@ -65,8 +65,9 @@ the client it reads for unconditionally: authelia refuses a
|
||||||
bearer-authz client with no audience, and every host publishes at least
|
bearer-authz client with no audience, and every host publishes at least
|
||||||
forgejo's `/metrics` as a scrape target, so the audience is never empty.
|
forgejo's `/metrics` as a scrape target, so the audience is never empty.
|
||||||
|
|
||||||
Until the store answers, the collector's secret file is empty: tmpfiles creates
|
Until the store has the value, the collector's secret file is empty: tmpfiles
|
||||||
it so `LoadCredential` has a source. The collector's unit starts through a
|
creates it so `LoadCredential` has a source. The unit fails and asks again
|
||||||
|
every 30 seconds while the store holds none, the same as Grafana's. The collector's unit starts through a
|
||||||
wrapper that checks that file. On an empty one it loads the config without the
|
wrapper that checks that file. On an empty one it loads the config without the
|
||||||
`publishedScrapeTargets` jobs, so it still receives and still scrapes its own
|
`publishedScrapeTargets` jobs, so it still receives and still scrapes its own
|
||||||
loopback targets, but asks authelia for no token. The prometheus receiver reads
|
loopback targets, but asks authelia for no token. The prometheus receiver reads
|
||||||
|
|
@ -126,7 +127,11 @@ one delivery route: `swarm-bao-grafana-oidc.service` reads
|
||||||
`swarm/services/<client-id>/oidc/client` out of the store, on **every** host
|
`swarm/services/<client-id>/oidc/client` out of the store, on **every** host
|
||||||
that runs Grafana. Where authelia is doesn't enter into it — the mint in
|
that runs Grafana. Where authelia is doesn't enter into it — the mint in
|
||||||
authelia's container writes that path whether the reader is a network away or in the
|
authelia's container writes that path whether the reader is a network away or in the
|
||||||
container next door.
|
container next door. On a fresh swarm the mint writes it a moment after the
|
||||||
|
reader's first attempt, so a read that finds no value yet fails and the unit
|
||||||
|
asks again every 30 seconds until the value is there, as the forge's and the
|
||||||
|
homeserver's do. A unit that finished there would wait for its refresh timer,
|
||||||
|
about ten minutes on.
|
||||||
|
|
||||||
That's a deliberate refusal of the shortcut. Copying the plaintext
|
That's a deliberate refusal of the shortcut. Copying the plaintext
|
||||||
straight out of authelia's tree when the two happen to share a host is one
|
straight out of authelia's tree when the two happen to share a host is one
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,9 @@ in
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if ! value="$(store_bao kv get -field=value ${lib.escapeShellArg "secret/swarm/hives/${hiveController.hiveName}/squid-selfcheck"} 2>"$STORE_ERR")"; then
|
if ! value="$(store_bao kv get -field=value ${lib.escapeShellArg "secret/swarm/hives/${hiveController.hiveName}/squid-selfcheck"} 2>"$STORE_ERR")"; then
|
||||||
|
# Done, not retried: a hive with no minted credential is a supported
|
||||||
|
# state (the self-check reports `credential=absent`), so there is
|
||||||
|
# nothing to wait for. The refresh timer reads the path again.
|
||||||
if grep -qi 'no value found' "$STORE_ERR"; then
|
if grep -qi 'no value found' "$STORE_ERR"; then
|
||||||
echo "the swarm has not minted this hive's squid self-check credential yet; ${credentialFile} stays as it is."
|
echo "the swarm has not minted this hive's squid self-check credential yet; ${credentialFile} stays as it is."
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,9 @@
|
||||||
token=""
|
token=""
|
||||||
fetch public-key key
|
fetch public-key key
|
||||||
fetch pull-token token
|
fetch pull-token token
|
||||||
|
# Done, not retried: a swarm with no cache has no facts to give, so a hive
|
||||||
|
# without them is a supported state and not a wait. The refresh timer reads
|
||||||
|
# the leaves again.
|
||||||
if [ "$missing" = 1 ]; then
|
if [ "$missing" = 1 ]; then
|
||||||
echo "the swarm has not given this hive its cache facts yet; $dir stays as it is."
|
echo "the swarm has not given this hive its cache facts yet; $dir stays as it is."
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
||||||
|
|
@ -749,21 +749,21 @@ in
|
||||||
#
|
#
|
||||||
# It is a store reader, and this is what the store's readers do: a cert
|
# It is a store reader, and this is what the store's readers do: a cert
|
||||||
# login that fails LOUDLY, since every state it fails on is one a retry
|
# login that fails LOUDLY, since every state it fails on is one a retry
|
||||||
# fixes, then a read that degrades QUIETLY, since no retry turns "no value
|
# fixes, then a read that fails the same way when the value is not there
|
||||||
# there" into a value.
|
# yet.
|
||||||
#
|
#
|
||||||
# ⚠️ An ABSENT secret is "not published yet", not a fault of this host's.
|
# ⚠️ An ABSENT secret is "not published yet", not a fault of this host's.
|
||||||
# The mint runs in authelia's container and authelia mints on its
|
# The mint runs in authelia's container and authelia mints on its
|
||||||
# first boot, so early in a swarm's life there is legitimately nothing to
|
# first boot, so early in a swarm's life there is legitimately nothing to
|
||||||
# read.
|
# read, and a retry finds it a moment later. A unit that exited 0 on it
|
||||||
|
# would not run again until the refresh timer, about ten minutes on.
|
||||||
# Nothing here writes a stand-in: there is no such thing as a locally valid
|
# Nothing here writes a stand-in: there is no such thing as a locally valid
|
||||||
# OIDC client secret, and a placeholder would turn a Grafana that cannot
|
# OIDC client secret, and a placeholder would turn a Grafana that cannot
|
||||||
# log anyone in into one whose token exchange is refused.
|
# log anyone in into one whose token exchange is refused.
|
||||||
#
|
#
|
||||||
# ⇒ So the absence surfaces at Grafana rather than here, and this unit's job
|
# ⇒ So the unit fails, and leaves the journal line that says which of the
|
||||||
# is to leave the journal line that says which of the three it was: the
|
# three it was: a secret that does not arrive is a Grafana nobody can log
|
||||||
# secret not arriving is a Grafana nobody can log into, and a named cause is
|
# into, and a named cause is the only thing separating that from a mystery.
|
||||||
# the only thing separating that from a mystery.
|
|
||||||
systemd.services.swarm-bao-grafana-oidc = {
|
systemd.services.swarm-bao-grafana-oidc = {
|
||||||
description = "fetch Grafana's OIDC client secret from the swarm secret store";
|
description = "fetch Grafana's OIDC client secret from the swarm secret store";
|
||||||
# Ordered after the store where it runs here
|
# Ordered after the store where it runs here
|
||||||
|
|
@ -812,9 +812,9 @@ in
|
||||||
${ensureSecretDir}
|
${ensureSecretDir}
|
||||||
|
|
||||||
# `bao`'s own message is the only thing separating a missing value from
|
# `bao`'s own message is the only thing separating a missing value from
|
||||||
# a refused identity from an unreachable host. This unit's degraded
|
# a refused identity from an unreachable host. Retrying is right for
|
||||||
# mode is correct for all three, so it reports which one rather than
|
# all three, so this unit reports which one rather than asserting all
|
||||||
# asserting all three in a sentence of ours.
|
# three in a sentence of ours.
|
||||||
err="$(mktemp)"
|
err="$(mktemp)"
|
||||||
trap 'rm -f "$err"' EXIT
|
trap 'rm -f "$err"' EXIT
|
||||||
|
|
||||||
|
|
@ -834,6 +834,9 @@ in
|
||||||
fi
|
fi
|
||||||
export BAO_TOKEN
|
export BAO_TOKEN
|
||||||
|
|
||||||
|
# 75 is EX_TEMPFAIL: not there yet, ask again. `Restart=on-failure`
|
||||||
|
# (./lib/store-retry.nix) asks every 30 s until the mint has written it,
|
||||||
|
# and the status line says "no value" rather than "no login" (1).
|
||||||
if ! secret="$(bao kv get -field=value ${lib.escapeShellArg storeSecretPath} 2>"$err")"; then
|
if ! secret="$(bao kv get -field=value ${lib.escapeShellArg storeSecretPath} 2>"$err")"; then
|
||||||
echo "swarm-bao did not return ${storeSecretPath}; Grafana has no OIDC client secret yet." >&2
|
echo "swarm-bao did not return ${storeSecretPath}; Grafana has no OIDC client secret yet." >&2
|
||||||
if [ -s "$err" ]; then
|
if [ -s "$err" ]; then
|
||||||
|
|
@ -841,12 +844,12 @@ in
|
||||||
else
|
else
|
||||||
echo "bao failed without writing a diagnostic." >&2
|
echo "bao failed without writing a diagnostic." >&2
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 75
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$secret" ]; then
|
if [ -z "$secret" ]; then
|
||||||
echo "swarm-bao returned an empty ${storeSecretPath}; leaving the file as it is." >&2
|
echo "swarm-bao returned an empty ${storeSecretPath}; leaving the file as it is." >&2
|
||||||
exit 0
|
exit 75
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Written with a shell builtin, never handed to a program: `printf` is
|
# Written with a shell builtin, never handed to a program: `printf` is
|
||||||
|
|
|
||||||
|
|
@ -677,8 +677,10 @@ in
|
||||||
#
|
#
|
||||||
# Shaped after ./swarm-grafana.nix's store reader: a cert login that fails
|
# Shaped after ./swarm-grafana.nix's store reader: a cert login that fails
|
||||||
# LOUDLY, since every state it fails on is one a retry fixes, then a read
|
# LOUDLY, since every state it fails on is one a retry fixes, then a read
|
||||||
# that degrades QUIETLY, since no retry turns "no value there" into a
|
# that fails the same way when the value is not there yet. Authelia's mint
|
||||||
# value.
|
# writes it a moment after a fresh swarm's first boot, so a retry does turn
|
||||||
|
# "no value there" into a value, and a unit that exited 0 on it would not
|
||||||
|
# run again until the refresh timer, about ten minutes on.
|
||||||
#
|
#
|
||||||
# ⚠️ Renders only where `haveClientIdentity` holds, unlike
|
# ⚠️ Renders only where `haveClientIdentity` holds, unlike
|
||||||
# ./swarm-grafana.nix's equivalent unit. That module refuses any host that
|
# ./swarm-grafana.nix's equivalent unit. That module refuses any host that
|
||||||
|
|
@ -740,9 +742,9 @@ in
|
||||||
install -d -m 0700 ${lib.escapeShellArg collectorSecretDir}
|
install -d -m 0700 ${lib.escapeShellArg collectorSecretDir}
|
||||||
|
|
||||||
# `bao`'s own message is the only thing separating a missing value
|
# `bao`'s own message is the only thing separating a missing value
|
||||||
# from a refused identity from an unreachable host. This unit's
|
# from a refused identity from an unreachable host. Retrying is right
|
||||||
# degraded mode is correct for all three, so it reports which one
|
# for all three, so this unit reports which one rather than asserting
|
||||||
# rather than asserting all three in a sentence of ours.
|
# all three in a sentence of ours.
|
||||||
err="$(mktemp)"
|
err="$(mktemp)"
|
||||||
trap 'rm -f "$err"' EXIT
|
trap 'rm -f "$err"' EXIT
|
||||||
|
|
||||||
|
|
@ -762,6 +764,9 @@ in
|
||||||
fi
|
fi
|
||||||
export BAO_TOKEN
|
export BAO_TOKEN
|
||||||
|
|
||||||
|
# 75 is EX_TEMPFAIL: not there yet, ask again. `Restart=on-failure`
|
||||||
|
# (./lib/store-retry.nix) asks every 30 s until the mint has written it,
|
||||||
|
# and the status line says "no value" rather than "no login" (1).
|
||||||
if ! secret="$(bao kv get -field=value ${lib.escapeShellArg storeSecretPath} 2>"$err")"; then
|
if ! secret="$(bao kv get -field=value ${lib.escapeShellArg storeSecretPath} 2>"$err")"; then
|
||||||
echo "swarm-bao did not return ${storeSecretPath}; the collector has no OIDC client secret yet." >&2
|
echo "swarm-bao did not return ${storeSecretPath}; the collector has no OIDC client secret yet." >&2
|
||||||
if [ -s "$err" ]; then
|
if [ -s "$err" ]; then
|
||||||
|
|
@ -769,12 +774,12 @@ in
|
||||||
else
|
else
|
||||||
echo "bao failed without writing a diagnostic." >&2
|
echo "bao failed without writing a diagnostic." >&2
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 75
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$secret" ]; then
|
if [ -z "$secret" ]; then
|
||||||
echo "swarm-bao returned an empty ${storeSecretPath}; leaving the file as it is." >&2
|
echo "swarm-bao returned an empty ${storeSecretPath}; leaving the file as it is." >&2
|
||||||
exit 0
|
exit 75
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# root-owned 0400, written with a shell builtin and never handed to a
|
# root-owned 0400, written with a shell builtin and never handed to a
|
||||||
|
|
|
||||||
|
|
@ -351,6 +351,24 @@ let
|
||||||
lib.hasInfix "secret/swarm/services/swarm-grafana/oidc/client" s
|
lib.hasInfix "secret/swarm/services/swarm-grafana/oidc/client" s
|
||||||
&& !(lib.hasInfix "secret/swarm/hives/" s);
|
&& !(lib.hasInfix "secret/swarm/hives/" s);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
# Authelia's mint writes the secret a moment after a fresh swarm's first
|
||||||
|
# boot, so a read that finds nothing yet has to fail and be asked again.
|
||||||
|
# A unit that exits 0 there is done until the refresh timer, ten minutes
|
||||||
|
# on, and Grafana has no login in the meantime.
|
||||||
|
name = "grafana's OIDC delivery unit fails on no value yet, so the store retry asks again";
|
||||||
|
ok =
|
||||||
|
let
|
||||||
|
u = grafanaRemoteAuthelia.systemd.services.swarm-bao-grafana-oidc;
|
||||||
|
afterRead = lib.last (lib.splitString "bao kv get" u.script);
|
||||||
|
beforeWrite = lib.head (lib.splitString "atomic_write_secret" afterRead);
|
||||||
|
in
|
||||||
|
# Both arms: the read that returns nothing and the one that returns an
|
||||||
|
# empty value.
|
||||||
|
lib.length (lib.splitString "exit 75" beforeWrite) == 3
|
||||||
|
&& !(lib.hasInfix "exit 0" beforeWrite)
|
||||||
|
&& u.serviceConfig.Restart == "on-failure";
|
||||||
|
}
|
||||||
{
|
{
|
||||||
# A copy on persistent disk outlives the secret's rotation and lands in
|
# A copy on persistent disk outlives the secret's rotation and lands in
|
||||||
# backups of the container's root.
|
# backups of the container's root.
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,24 @@ let
|
||||||
lib.hasInfix "secret/swarm/services/swarm-collector/oidc/client" s
|
lib.hasInfix "secret/swarm/services/swarm-collector/oidc/client" s
|
||||||
&& !(lib.hasInfix "secret/swarm/hives/" s);
|
&& !(lib.hasInfix "secret/swarm/hives/" s);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
# Authelia's mint writes the secret a moment after a fresh swarm's first
|
||||||
|
# boot, so a read that finds nothing yet has to fail and be asked again.
|
||||||
|
# A unit that exits 0 there is done until the refresh timer, ten minutes
|
||||||
|
# on, and the collector runs on an empty secret in the meantime.
|
||||||
|
name = "the collector's delivery unit fails on no value yet, so the store retry asks again";
|
||||||
|
ok =
|
||||||
|
let
|
||||||
|
u = otelBaoRemoteAuthelia.systemd.services.swarm-bao-otel-oidc;
|
||||||
|
afterRead = lib.last (lib.splitString "bao kv get" u.script);
|
||||||
|
beforeWrite = lib.head (lib.splitString "atomic_write_secret" afterRead);
|
||||||
|
in
|
||||||
|
# Both arms: the read that returns nothing and the one that returns an
|
||||||
|
# empty value.
|
||||||
|
lib.length (lib.splitString "exit 75" beforeWrite) == 3
|
||||||
|
&& !(lib.hasInfix "exit 0" beforeWrite)
|
||||||
|
&& u.serviceConfig.Restart == "on-failure";
|
||||||
|
}
|
||||||
{
|
{
|
||||||
# A copy on persistent disk outlives the secret's rotation and lands in
|
# A copy on persistent disk outlives the secret's rotation and lands in
|
||||||
# backups of the container's root.
|
# backups of the container's root.
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,17 @@ with subtest("authelia's mint has published the clients' secrets"):
|
||||||
"swarm-bao-operator-viewer-policy",
|
"swarm-bao-operator-viewer-policy",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with subtest("the swarm collector's client secret reaches the host"):
|
||||||
|
# `swarm-bao-otel-oidc` reads the mint's path once the store answers, and the mint writes
|
||||||
|
# it a moment after that first read on a fresh swarm. The unit has to fail on "no value yet"
|
||||||
|
# and ask again every 30 s. One that finished would wait for its refresh timer, ten minutes
|
||||||
|
# on, so the wait is shorter than that.
|
||||||
|
settle(
|
||||||
|
"[ -s /run/swarm-otel-oidc/swarm-collector.secret ]",
|
||||||
|
300,
|
||||||
|
"swarm-bao-otel-oidc",
|
||||||
|
)
|
||||||
|
|
||||||
with subtest("step 2: swarmctl user add"):
|
with subtest("step 2: swarmctl user add"):
|
||||||
machine.wait_until_succeeds(
|
machine.wait_until_succeeds(
|
||||||
"swarmctl user add mara --display-name Mara --email mara@example.com --group admins "
|
"swarmctl user add mara --display-name Mara --email mara@example.com --group admins "
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue