hive-tls: fail swarm-services-cert when the store identity is absent
A hive fronting no swarm name fetches the store's pki root presenting its reader certificate. When deploy.bao.clientCertFile or clientKeyFile is unset, or either named file is not readable, the unit now exits 1 with a message naming both options and their paths, instead of exiting 0 with the root missing from the trust bundle. The module-eval cases that asserted the quiet skip assert the failure instead, and a new case covers the named-but-absent files.
This commit is contained in:
parent
8c2f81abad
commit
849bf46550
4 changed files with 52 additions and 16 deletions
|
|
@ -797,12 +797,26 @@ in
|
|||
# `ca/pem` takes no token; the TLS client certificate is the
|
||||
# store's listener's demand, not bao's, so this presents the
|
||||
# hive's reader identity and never logs in with it.
|
||||
# A hive with no reader identity has no certificate to present, so it
|
||||
# skips the fetch and the bundle goes without this root.
|
||||
# A hive without a readable reader identity fails here, naming the
|
||||
# options: every hive must hold one.
|
||||
if [ "$want_svc" = 0 ]; then
|
||||
${
|
||||
if haveReaderIdentity then
|
||||
''
|
||||
missing=""
|
||||
for f in ${
|
||||
lib.escapeShellArgs [
|
||||
baoDeploy.clientCertFile
|
||||
baoDeploy.clientKeyFile
|
||||
]
|
||||
}; do
|
||||
[ -r "$f" ] || missing="$missing $f"
|
||||
done
|
||||
if [ -n "$missing" ]; then
|
||||
echo "this hive has no usable store identity: cannot read$missing." >&2
|
||||
echo "place the files named by services.hyperhive.deploy.bao.clientCertFile (${baoDeploy.clientCertFile}) and services.hyperhive.deploy.bao.clientKeyFile (${baoDeploy.clientKeyFile})." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "no swarm service domains configured — fetching only the store's pki root"
|
||||
err="$(mktemp)"
|
||||
raw="$(mktemp "$d/swarm-services-root.XXXXXX")"
|
||||
|
|
@ -838,8 +852,13 @@ in
|
|||
exit 0''
|
||||
else
|
||||
''
|
||||
echo "store pki root not staged: this hive has no store identity (services.hyperhive.deploy.bao.clientCertFile/clientKeyFile)"
|
||||
exit 0''
|
||||
echo "this hive has no store identity, so it cannot fetch the store's ${baoServicesPkiMount} root." >&2
|
||||
echo "set services.hyperhive.deploy.bao.clientCertFile (${
|
||||
if baoDeploy.clientCertFile == null then "unset" else baoDeploy.clientCertFile
|
||||
}) and services.hyperhive.deploy.bao.clientKeyFile (${
|
||||
if baoDeploy.clientKeyFile == null then "unset" else baoDeploy.clientKeyFile
|
||||
}) and place both files." >&2
|
||||
exit 1''
|
||||
}
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -50,11 +50,12 @@ let
|
|||
noIdentity = hive { };
|
||||
noIdFetch = noIdentity.systemd.services.swarm-services-cert.script;
|
||||
|
||||
# The `want_svc=0` branch of a rendered script, up to its closing `fi`.
|
||||
# The `want_svc=0` branch of a rendered script, up to the `fi` that closes it (the
|
||||
# only one followed by a blank line).
|
||||
noSvcBranch =
|
||||
script:
|
||||
builtins.head (
|
||||
lib.splitString "\nfi\n" (lib.last (lib.splitString ''if [ "$want_svc" = 0 ]; then'' script))
|
||||
lib.splitString "\nfi\n\n" (lib.last (lib.splitString ''if [ "$want_svc" = 0 ]; then'' script))
|
||||
);
|
||||
|
||||
units = allLocal.systemd.services;
|
||||
|
|
@ -159,20 +160,33 @@ let
|
|||
) noSvcFetch;
|
||||
}
|
||||
{
|
||||
# Nothing to present means no fetch to fail: the unit stays green and
|
||||
# says why the root is missing. The control is the same hive with an
|
||||
# identity, whose branch does fetch and can fail.
|
||||
name = "a hive fronting no swarm name with no store identity skips the fetch and cannot fail on it";
|
||||
# No identity to present: the unit fails, naming both options, rather
|
||||
# than leaving the bundle without the root behind a green unit. The
|
||||
# control is the same hive with an identity, whose branch fetches.
|
||||
name = "a hive fronting no swarm name with no store identity fails the unit, naming both options";
|
||||
ok =
|
||||
noIdentity.services.hyperhive.swarm.localServiceDomains == [ ]
|
||||
&& noIdentity.services.hyperhive.deploy.bao.clientCertFile == null
|
||||
&& !(lib.hasInfix "/v1/pki/ca/pem" noIdFetch)
|
||||
&& lib.hasInfix "store pki root not staged" (noSvcBranch noIdFetch)
|
||||
&& lib.hasInfix "deploy.bao.clientCertFile" (noSvcBranch noIdFetch)
|
||||
&& !(lib.hasInfix "exit 1" (noSvcBranch noIdFetch))
|
||||
&& lib.hasInfix "exit 1" (noSvcBranch noSvcFetch)
|
||||
&& lib.hasInfix "services.hyperhive.deploy.bao.clientCertFile" (noSvcBranch noIdFetch)
|
||||
&& lib.hasInfix "services.hyperhive.deploy.bao.clientKeyFile" (noSvcBranch noIdFetch)
|
||||
&& lib.hasSuffix "exit 1" (noSvcBranch noIdFetch)
|
||||
&& !(lib.hasInfix "exit 0" (noSvcBranch noIdFetch))
|
||||
&& !(lib.hasInfix "not staged" noIdFetch)
|
||||
&& lib.hasInfix "/v1/pki/ca/pem" (noSvcBranch noSvcFetch);
|
||||
}
|
||||
{
|
||||
# An identity named but not on disk fails before curl, naming the paths.
|
||||
name = "a hive fronting no swarm name whose identity files are absent fails the unit, naming the paths";
|
||||
ok =
|
||||
lib.hasInfix "for f in /etc/pki/bao-client.pem /etc/pki/bao-client-key.pem; do" (
|
||||
noSvcBranch noSvcFetch
|
||||
)
|
||||
&& lib.hasInfix ''[ -r "$f" ] || missing="$missing $f"'' (noSvcBranch noSvcFetch)
|
||||
&& lib.hasInfix "cannot read$missing" (noSvcBranch noSvcFetch)
|
||||
&& lib.hasInfix "clientCertFile (/etc/pki/bao-client.pem)" (noSvcBranch noSvcFetch)
|
||||
&& lib.hasInfix "clientKeyFile (/etc/pki/bao-client-key.pem)" (noSvcBranch noSvcFetch);
|
||||
}
|
||||
{
|
||||
# The fetch retries against a sealed store; a gateway `Requires=` on it
|
||||
# would go down with each attempt. The control is a host fronting
|
||||
|
|
|
|||
Loading…
Reference in a new issue