Watch
0
0
Fork
You've already forked hyperhive
0

Compare commits

...
3 changed files with 72 additions and 33 deletions

View file

@ -52,6 +52,16 @@ let
# `nix/module-eval/grafana.nix` pins it against the shipped dashboard file. # `nix/module-eval/grafana.nix` pins it against the shipped dashboard file.
collectorServiceName = "bao"; collectorServiceName = "bao";
# OpenBao's start job limit inside the container, and the container's own,
# which is the same plus a margin: the container is `Type=notify`, so its
# start job spans OpenBao's and must outlast it, or the container's limit
# kills a start the unit would still finish.
openbaoStartSec = 240;
containerStartSec = openbaoStartSec + 60;
# systemd's default stop limit, which bounds the stop half of a restart.
openbaoStopSec = 90;
# Upstream's own default, kept so its documentation matches. The raft data # Upstream's own default, kept so its documentation matches. The raft data
# lives INSIDE the container on `ephemeral = false`, the same way # lives INSIDE the container on `ephemeral = false`, the same way
# ./swarm-grafana.nix keeps its sqlite database — no sibling service binds # ./swarm-grafana.nix keeps its sqlite database — no sibling service binds
@ -3943,9 +3953,10 @@ in
Restart = "on-failure"; Restart = "on-failure";
RestartSec = 30; RestartSec = 30;
# An attempt may generate a 4096-bit RSA root and then wait on a # An attempt may generate a 4096-bit RSA root and then wait on a
# blocking restart of openbao: its stop and its start, 90s each by # blocking restart of openbao: its stop (`openbaoStopSec`) and its
# systemd's defaults. # start (`openbaoStartSec`), plus 120s for the key generation and
TimeoutStartSec = "5min"; # the calls around it. 90 + 240 + 120 = 450s.
TimeoutStartSec = "${toString (openbaoStopSec + openbaoStartSec + 120)}s";
}; };
script = '' script = ''
set -euo pipefail set -euo pipefail
@ -4138,7 +4149,7 @@ in
# The container is `Type=notify`, so its start job waits for OpenBao, # The container is `Type=notify`, so its start job waits for OpenBao,
# whose first start after a restart takes 60-144 s opening the raft # whose first start after a restart takes 60-144 s opening the raft
# storage. The 1min default kills it mid-open and every retry is cold. # storage. The 1min default kills it mid-open and every retry is cold.
timeoutStartSec = "5min"; timeoutStartSec = "${toString containerStartSec}s";
inherit privateNetwork; inherit privateNetwork;
@ -4395,31 +4406,36 @@ in
# attrset literal and does not parse. Module merging happens across # attrset literal and does not parse. Module merging happens across
# `config` blocks, not within a literal — so the seal's half joins # `config` blocks, not within a literal — so the seal's half joins
# with `optionalAttrs`. # with `optionalAttrs`.
systemd.services.openbao.serviceConfig = systemd.services.openbao.serviceConfig = {
lib.optionalAttrs haveServerTls { # Upstream sets no start limit, so the 90 s default cut off
LoadCredential = [ "${serverKeyCredential}:${serverKeyPath}" ]; # the 60-144 s raft open; `Restart=on-failure` upstream then
} # restarts it cold.
# The PIN reaches openbao as an environment variable read from a TimeoutStartSec = openbaoStartSec;
# 0400 file the provisioning unit wrote — never as a value in this }
# expression, which would render it world-readable into the store. // lib.optionalAttrs haveServerTls {
# `TPM2_PKCS11_STORE` is required because the store is not at the LoadCredential = [ "${serverKeyCredential}:${serverKeyPath}" ];
# library's default location. }
// lib.optionalAttrs (baoDeploy.seal == "pkcs11") { # The PIN reaches openbao as an environment variable read from a
EnvironmentFile = pinEnvFile; # 0400 file the provisioning unit wrote — never as a value in this
Environment = [ "TPM2_PKCS11_STORE=${tokenStoreDir}" ]; # expression, which would render it world-readable into the store.
# `DynamicUser` implies `ProtectSystem=strict`, which leaves the # `TPM2_PKCS11_STORE` is required because the store is not at the
# bind mount read-only to this unit however it is owned, and the # library's default location.
# pkcs11 library opens its sqlite store read-write. // lib.optionalAttrs (baoDeploy.seal == "pkcs11") {
ReadWritePaths = [ tokenStoreDir ]; EnvironmentFile = pinEnvFile;
# Two groups, two different jobs: the store's sqlite file, and Environment = [ "TPM2_PKCS11_STORE=${tokenStoreDir}" ];
# the TPM device the seal opens through it. `CapabilityBounding # `DynamicUser` implies `ProtectSystem=strict`, which leaves the
# Set=` is empty upstream, so there is no `CAP_DAC_OVERRIDE` to # bind mount read-only to this unit however it is owned, and the
# fall back on — group membership is the only way in. # pkcs11 library opens its sqlite store read-write.
SupplementaryGroups = [ ReadWritePaths = [ tokenStoreDir ];
tokenGroup # Two groups, two different jobs: the store's sqlite file, and
tpmGroup # the TPM device the seal opens through it. `CapabilityBounding
]; # Set=` is empty upstream, so there is no `CAP_DAC_OVERRIDE` to
}; # fall back on — group membership is the only way in.
SupplementaryGroups = [
tokenGroup
tpmGroup
];
};
# ⚠️ Upstream sets `restartIfChanged = false` on this unit: a restart # ⚠️ Upstream sets `restartIfChanged = false` on this unit: a restart
# SEALS the store and disconnects every client. The container around # SEALS the store and disconnects every client. The container around

View file

@ -255,6 +255,20 @@ let
&& !(lib.hasInfix "certificate=@${tlsDir}/listener-client-ca.pem" scripts) && !(lib.hasInfix "certificate=@${tlsDir}/listener-client-ca.pem" scripts)
&& !(lib.hasInfix "certificate=@${tlsDir}/agent-ca.pem" scripts); && !(lib.hasInfix "certificate=@${tlsDir}/agent-ca.pem" scripts);
} }
{
# The unit's blocking `systemctl restart openbao.service` stops (90 s)
# then starts openbao (240 s), so its own limit must exceed both or a
# slow cold open kills the job mid-restart. Control: openbao's own limit
# is read from the same container, so a wrong path fails the 240 arm.
name = "the agent CA unit's start limit outlasts the restart of openbao it waits on";
ok =
let
limit = lib.toInt (
lib.removeSuffix "s" baoPkcs11.systemd.services.swarm-bao-agent-pki.serviceConfig.TimeoutStartSec
);
in
(baoUnits baoPkcs11).openbao.serviceConfig.TimeoutStartSec == 240 && limit >= 90 + 240 + 60;
}
{ {
# Both writers compose the bundle through one function, which refuses # Both writers compose the bundle through one function, which refuses
# a result that does not begin with the store CA and replaces the file # a result that does not begin with the store CA and replaces the file

View file

@ -853,10 +853,19 @@ let
) names; ) names;
} }
{ {
# The container is `Type=notify`: its start job lasts as long as # The container is `Type=notify`: its start job spans OpenBao's first
# OpenBao's first start, which a 1min limit cuts off mid-open. # start, so OpenBao's own limit is raised too and sits a minute below
name = "the store's container is given five minutes to start"; # the container's. `Restart=` comes from upstream, so it shows the
ok = lib.hasInfix "TimeoutStartSec=5min" allLocal.systemd.units."container@swarm-bao.service".text; # lookup reaches the real unit.
name = "openbao's start limit is raised and stays below its container's";
ok =
let
inner = allLocal.containers.swarm-bao.config.systemd.services.openbao.serviceConfig;
unit = allLocal.systemd.units."container@swarm-bao.service".text;
in
inner.Restart == "on-failure"
&& inner.TimeoutStartSec == 240
&& lib.hasInfix "TimeoutStartSec=300s" unit;
} }
{ {
name = "hive-priv is told the cache's address by the host's configuration"; name = "hive-priv is told the cache's address by the host's configuration";