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
4 changed files with 88 additions and 22 deletions
|
|
@ -85,6 +85,9 @@ in
|
|||
exit 1
|
||||
fi
|
||||
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
|
||||
echo "the swarm has not minted this hive's squid self-check credential yet; ${credentialFile} stays as it is."
|
||||
exit 0
|
||||
|
|
|
|||
|
|
@ -98,6 +98,9 @@
|
|||
token=""
|
||||
fetch public-key key
|
||||
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
|
||||
echo "the swarm has not given this hive its cache facts yet; $dir stays as it is."
|
||||
exit 0
|
||||
|
|
|
|||
|
|
@ -749,21 +749,21 @@ in
|
|||
#
|
||||
# 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
|
||||
# fixes, then a read that degrades QUIETLY, since no retry turns "no value
|
||||
# there" into a value.
|
||||
# fixes, then a read that fails the same way when the value is not there
|
||||
# yet.
|
||||
#
|
||||
# ⚠️ 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
|
||||
# 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
|
||||
# OIDC client secret, and a placeholder would turn a Grafana that cannot
|
||||
# log anyone in into one whose token exchange is refused.
|
||||
#
|
||||
# ⇒ So the absence surfaces at Grafana rather than here, and this unit's job
|
||||
# is to leave the journal line that says which of the three it was: the
|
||||
# secret not arriving is a Grafana nobody can log into, and a named cause is
|
||||
# the only thing separating that from a mystery.
|
||||
# ⇒ So the unit fails, and leaves the journal line that says which of the
|
||||
# three it was: a secret that does not arrive is a Grafana nobody can log
|
||||
# into, and a named cause is the only thing separating that from a mystery.
|
||||
systemd.services.swarm-bao-grafana-oidc = {
|
||||
description = "fetch Grafana's OIDC client secret from the swarm secret store";
|
||||
# Ordered after the store where it runs here
|
||||
|
|
@ -812,9 +812,9 @@ in
|
|||
${ensureSecretDir}
|
||||
|
||||
# `bao`'s own message is the only thing separating a missing value from
|
||||
# a refused identity from an unreachable host. This unit's degraded
|
||||
# mode is correct for all three, so it reports which one rather than
|
||||
# asserting all three in a sentence of ours.
|
||||
# a refused identity from an unreachable host. Retrying is right for
|
||||
# all three, so this unit reports which one rather than asserting all
|
||||
# three in a sentence of ours.
|
||||
err="$(mktemp)"
|
||||
trap 'rm -f "$err"' EXIT
|
||||
|
||||
|
|
@ -834,6 +834,9 @@ in
|
|||
fi
|
||||
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
|
||||
echo "swarm-bao did not return ${storeSecretPath}; Grafana has no OIDC client secret yet." >&2
|
||||
if [ -s "$err" ]; then
|
||||
|
|
@ -841,12 +844,12 @@ in
|
|||
else
|
||||
echo "bao failed without writing a diagnostic." >&2
|
||||
fi
|
||||
exit 0
|
||||
exit 75
|
||||
fi
|
||||
|
||||
if [ -z "$secret" ]; then
|
||||
echo "swarm-bao returned an empty ${storeSecretPath}; leaving the file as it is." >&2
|
||||
exit 0
|
||||
exit 75
|
||||
fi
|
||||
|
||||
# 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
|
||||
# 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
|
||||
# value.
|
||||
# that fails the same way when the value is not there yet. Authelia's mint
|
||||
# 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
|
||||
# ./swarm-grafana.nix's equivalent unit. That module refuses any host that
|
||||
|
|
@ -740,9 +742,9 @@ in
|
|||
install -d -m 0700 ${lib.escapeShellArg collectorSecretDir}
|
||||
|
||||
# `bao`'s own message is the only thing separating a missing value
|
||||
# from a refused identity from an unreachable host. This unit's
|
||||
# degraded mode is correct for all three, so it reports which one
|
||||
# rather than asserting all three in a sentence of ours.
|
||||
# from a refused identity from an unreachable host. Retrying is right
|
||||
# for all three, so this unit reports which one rather than asserting
|
||||
# all three in a sentence of ours.
|
||||
err="$(mktemp)"
|
||||
trap 'rm -f "$err"' EXIT
|
||||
|
||||
|
|
@ -762,6 +764,9 @@ in
|
|||
fi
|
||||
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
|
||||
echo "swarm-bao did not return ${storeSecretPath}; the collector has no OIDC client secret yet." >&2
|
||||
if [ -s "$err" ]; then
|
||||
|
|
@ -769,12 +774,12 @@ in
|
|||
else
|
||||
echo "bao failed without writing a diagnostic." >&2
|
||||
fi
|
||||
exit 0
|
||||
exit 75
|
||||
fi
|
||||
|
||||
if [ -z "$secret" ]; then
|
||||
echo "swarm-bao returned an empty ${storeSecretPath}; leaving the file as it is." >&2
|
||||
exit 0
|
||||
exit 75
|
||||
fi
|
||||
|
||||
# root-owned 0400, written with a shell builtin and never handed to a
|
||||
|
|
|
|||
Loading…
Reference in a new issue