keep the container's secret key through the pod's first start
Grafana wraps the data keys of its database with secret_key, and a different key makes them undecryptable, which grafana cli's re-encrypt cannot repair (it decrypts with the current key first). So the init container takes the store's key, else the file the container generated, else a new key, and a new key only over a database that holds no data_keys row; otherwise it exits non-zero naming the leaf. The file reaches it read-only through a claim on a static local volume, because the namespace refuses a hostPath.
This commit is contained in:
parent
9f62e71dae
commit
bd0cff47f9
1 changed files with 429 additions and 91 deletions
|
|
@ -2890,6 +2890,42 @@ let
|
|||
&& hasInfix "auth/jwt-k8s/role/swarm-grafana-oidc" script
|
||||
&& hasInfix "bound_subject=system:serviceaccount:hyperhive:swarm-grafana" script
|
||||
&& lib.elem "swarm-grafana-oidc" withNode.services.hyperhive.deploy.bao.k8sPrincipals
|
||||
# The earlier container's key file and the carried database reach the init
|
||||
# container alone, read-only: the file through a claim on a static local
|
||||
# volume (a `hostPath` is refused at this namespace's Pod Security
|
||||
# level), the database through the data volume's own mount. The init
|
||||
# container runs as the uid that owns them and as non-root.
|
||||
&&
|
||||
(lib.findFirst (m: m.name == "legacy-key") null init.volumeMounts) == {
|
||||
name = "legacy-key";
|
||||
mountPath = "/legacy-secret-key";
|
||||
readOnly = true;
|
||||
}
|
||||
&& (lib.findFirst (m: m.name == "state") null init.volumeMounts).readOnly
|
||||
&& !(lib.elem "legacy-key" (mountsOf main))
|
||||
&& !(lib.elem "legacy-key" (mountsOf side))
|
||||
&& !((lib.findFirst (m: m.name == "state") null side.volumeMounts) != null)
|
||||
&&
|
||||
(lib.findFirst (v: v.name == "legacy-key") null spec.volumes) == {
|
||||
name = "legacy-key";
|
||||
persistentVolumeClaim = {
|
||||
claimName = "swarm-grafana-legacy-key";
|
||||
readOnly = true;
|
||||
};
|
||||
}
|
||||
&& !(lib.any (v: v ? hostPath) spec.volumes)
|
||||
&&
|
||||
objects."swarm-grafana-legacy-key/persistentvolume".spec.local.path
|
||||
== "/var/lib/nixos-containers/swarm-grafana/var/lib/grafana-secret"
|
||||
&&
|
||||
objects."swarm-grafana-legacy-key/persistentvolume".spec.nodeAffinity.required.nodeSelectorTerms
|
||||
!= [ ]
|
||||
&&
|
||||
objects."swarm-grafana-legacy-key/persistentvolumeclaim".spec.volumeName
|
||||
== "swarm-grafana-legacy-key"
|
||||
&& init.securityContext.runAsUser == 196
|
||||
&& init.securityContext.runAsNonRoot
|
||||
&& !(side.securityContext ? runAsUser)
|
||||
# The listener credential comes from the Secret the host publishes.
|
||||
&& lib.any (s: (s.secret.name or null) == "swarm-grafana-credentials") credentials.projected.sources
|
||||
# The Service and the policy: only the node in, and out to DNS, the
|
||||
|
|
|
|||
Loading…
Reference in a new issue