let the init container's temp file take its umask
fetch-secrets ran under umask 0227 for the files it writes, which made the mktemp file of grafana_secret_key mode 0400: the redirect of bao's stderr into it failed, every bao call in the helper answered 1, and the init container exited 1 before it stored or read the key. The umask now covers only the writes of put(), the helper chmods its own file, the script test runs under that umask, and a pod that does not start prints its init containers' logs.
This commit is contained in:
parent
bd0cff47f9
commit
f8fb71253e
5 changed files with 19 additions and 3 deletions
|
|
@ -31,6 +31,8 @@
|
||||||
shift 3
|
shift 3
|
||||||
GRAFANA_KEY=""
|
GRAFANA_KEY=""
|
||||||
err="$(mktemp)"
|
err="$(mktemp)"
|
||||||
|
# A caller's umask can leave the file unwritable to its owner.
|
||||||
|
chmod u+rw "$err"
|
||||||
|
|
||||||
if ! GRAFANA_KEY="$(bao kv get -field=value "$leaf" 2>"$err")" || [ -z "$GRAFANA_KEY" ]; then
|
if ! GRAFANA_KEY="$(bao kv get -field=value "$leaf" 2>"$err")" || [ -z "$GRAFANA_KEY" ]; then
|
||||||
readerr="$(cat "$err")"
|
readerr="$(cat "$err")"
|
||||||
|
|
|
||||||
|
|
@ -479,13 +479,15 @@ let
|
||||||
fetch = pkgs.writeShellScriptBin "swarm-grafana-fetch" ''
|
fetch = pkgs.writeShellScriptBin "swarm-grafana-fetch" ''
|
||||||
export PATH=${lib.makeBinPath tools}
|
export PATH=${lib.makeBinPath tools}
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
umask 0227
|
|
||||||
${login}
|
${login}
|
||||||
${grafanaSecretKey}
|
${grafanaSecretKey}
|
||||||
d=${lib.escapeShellArg secretDir}
|
d=${lib.escapeShellArg secretDir}
|
||||||
|
|
||||||
put() {
|
put() {
|
||||||
printf '%s' "$2" > "$d/$1.new"
|
# Group-readable (0440): the pod's group is how Grafana reads what the init
|
||||||
|
# container, running as another uid, wrote. Only the writes take the umask:
|
||||||
|
# a temporary file made under it could not be written to again.
|
||||||
|
( umask 0227; printf '%s' "$2" > "$d/$1.new" )
|
||||||
mv -f "$d/$1.new" "$d/$1"
|
mv -f "$d/$1.new" "$d/$1"
|
||||||
}
|
}
|
||||||
stored() {
|
stored() {
|
||||||
|
|
|
||||||
|
|
@ -418,7 +418,9 @@ let
|
||||||
in
|
in
|
||||||
lib.hasInfix "put swarm-grafana.secret \"$oidc\"" init
|
lib.hasInfix "put swarm-grafana.secret \"$oidc\"" init
|
||||||
&& lib.hasInfix "bearer=\"$(seeded secret/swarm/services/swarm-grafana/metrics/bearer)\"\nput metrics-bearer \"Bearer $bearer\"" init
|
&& lib.hasInfix "bearer=\"$(seeded secret/swarm/services/swarm-grafana/metrics/bearer)\"\nput metrics-bearer \"Bearer $bearer\"" init
|
||||||
&& lib.hasInfix "umask 0227" init
|
&& lib.hasInfix "( umask 0227; printf '%s' \"$2\" > \"$d/$1.new\" )" init
|
||||||
|
# Only the writes take it: a temporary file made under it is not writable to its owner.
|
||||||
|
&& !(lib.hasInfix "\numask 0227" init)
|
||||||
&& lib.hasInfix "d=/run/grafana-secrets" init
|
&& lib.hasInfix "d=/run/grafana-secrets" init
|
||||||
&& !(persistent init)
|
&& !(persistent init)
|
||||||
&& !(persistent r.scripts.controllerToken)
|
&& !(persistent r.scripts.controllerToken)
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ expect() {
|
||||||
(
|
(
|
||||||
PATH="$FAKE_BAO_BIN:$PATH"
|
PATH="$FAKE_BAO_BIN:$PATH"
|
||||||
export BAO_TOKEN=s.fake
|
export BAO_TOKEN=s.fake
|
||||||
|
# The init container's umask: the helper's own temporary file must still
|
||||||
|
# be writable to it.
|
||||||
|
umask 0227
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$HELPER"
|
. "$HELPER"
|
||||||
rc=0
|
rc=0
|
||||||
|
|
|
||||||
|
|
@ -865,6 +865,13 @@ pkgs.testers.runNixOSTest {
|
||||||
diagnose(["hyperhive-k8s-ca-trust.service"])
|
diagnose(["hyperhive-k8s-ca-trust.service"])
|
||||||
print(machine.execute(f"kubectl -n {NS} describe pod {name}")[1])
|
print(machine.execute(f"kubectl -n {NS} describe pod {name}")[1])
|
||||||
print(machine.execute(f"kubectl -n {NS} logs {name} --tail=60")[1])
|
print(machine.execute(f"kubectl -n {NS} logs {name} --tail=60")[1])
|
||||||
|
# An init container that fails keeps the pod out of Running, and its
|
||||||
|
# output is the only thing that says why: the default container has
|
||||||
|
# none yet.
|
||||||
|
for init in machine.execute(f"kubectl -n {NS} get pod {name} -o jsonpath='{{.spec.initContainers[*].name}}'")[1].split():
|
||||||
|
for previous in ("", "--previous"):
|
||||||
|
print(f"--- init container {init} {previous}")
|
||||||
|
print(machine.execute(f"kubectl -n {NS} logs {name} -c {init} {previous} --tail=60 2>&1")[1])
|
||||||
raise
|
raise
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue