Watch
0
0
Fork
You've already forked hyperhive
0

fetch the secrets unit's store leaves concurrently and log how long each phase takes

This commit is contained in:
atlas 2026-11-04 17:04:35 +01:00
commit 197caa1e52

View file

@ -526,12 +526,14 @@ let
# cannot be read fails the run too, after the files are rendered from the
# digests (`STORE_UNREADABLE`, checked at the end of the unit's script), so
# the unit retries until the store answers and authelia has started from the
# digests meanwhile.
# digests meanwhile. Runs after `storeKeysScript`, which defines
# `phase_done` and has already fetched these leaves.
storeMintScript = ''
${oidcClientSecrets}
${lib.concatMapStrings (c: ''
mint_client_secret ${lib.escapeShellArg c.id} ${lib.escapeShellArg (clientLeaf c.id)} || { rc=$?; [ "$rc" = 2 ] || exit "$rc"; STORE_UNREADABLE=1; }
'') secretClients}
phase_done clients
'';
# The OIDC half of the first-boot generator, kept out of the script
@ -624,6 +626,12 @@ let
done
'';
# Every leaf the unit reads, for `store_prefetch`: the keys and the client
# secrets. The reads that follow are answered from what it fetched.
storeLeaves =
map keyLeaf (randomKeys ++ lib.optional oidcEnabled "oidc-issuer")
++ lib.optionals oidcEnabled (map (c: clientLeaf c.id) secretClients);
# The same keys from the store, at the same paths. The store's value wins,
# then the file's, which seeds the store when it holds none, so a key never
# changes value by moving; a new one is minted only where neither exists.
@ -632,8 +640,21 @@ let
storeKeysScript = ''
${storeSeededSecret}
${refreshConsumer}
# <name>. One line: how long the phase that ends here took, so a slow store
# shows where the time went. Not `SECONDS`, which counts whole seconds.
PHASE_AT="$EPOCHREALTIME"
phase_done() {
local now="$EPOCHREALTIME"
echo "phase $1: $(( (''${now//[.,]/} - ''${PHASE_AT//[.,]/}) / 1000 )) ms"
PHASE_AT="$now"
}
store_init
store_login
phase_done login
store_prefetch ${lib.concatMapStringsSep " " lib.escapeShellArg storeLeaves}
phase_done reads
mint_hex() {
head -c 64 /dev/urandom | od -An -tx1 | tr -d ' \n'
@ -661,6 +682,7 @@ let
keep_key "$f" mint_hex
done
${lib.optionalString oidcEnabled "keep_key oidc-issuer mint_issuer"}
phase_done keys
'';
# A netns of its own on the hive bridge: the container dials the store, the
@ -1197,6 +1219,10 @@ in
# accepts a connection and never answers: this unit is in the
# boot wait of a container with a one-minute start limit.
# What a killed run left is picked up by the next one.
#
# The run's store reads are concurrent (`store_prefetch`): its
# length is the login, a few rounds of reads and the writes,
# not one round trip per leaf. Raising this raises that wait.
TimeoutStartSec = 30;
RestartSec = 15;
RestartSteps = 3;