k8s: a pod's public CA files come from a ConfigMap, not a Secret
This commit is contained in:
parent
15eccc1f3b
commit
485da0c3c7
1 changed files with 104 additions and 22 deletions
|
|
@ -13,7 +13,8 @@
|
|||
#
|
||||
# Secrets are referenced by name and credential id only. The output lands in
|
||||
# the world-readable nix store, so it never holds a credential's host path or
|
||||
# contents.
|
||||
# contents. A credential that is a public CA file comes from the CA ConfigMap,
|
||||
# not a Secret.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
|
|
@ -26,6 +27,12 @@ let
|
|||
baoDeployCfg = deployCfg.bao;
|
||||
podAuth = import ../lib/bao-pod-auth.nix;
|
||||
|
||||
# The ConfigMap that holds the public CA files the pods trust, and its keys.
|
||||
# A CA certificate is public, so it travels as a ConfigMap, never a Secret.
|
||||
caConfigMap = "hyperhive-ca-trust";
|
||||
trustBundleKey = "trust-bundle.pem";
|
||||
baoServerCaKey = "bao-server-ca.pem";
|
||||
|
||||
# `serviceUser` is the user every image runs its daemon as. Mounted files are
|
||||
# group-owned by its group through `fsGroup`.
|
||||
inherit (import ../../images { inherit pkgs lib; }) mkServiceImage serviceUser;
|
||||
|
|
@ -52,7 +59,8 @@ let
|
|||
# systemd unit the host runs today; nothing reads it unless `enable` holds.
|
||||
# `healthEnv` names the variable that binds the daemon's /healthz and
|
||||
# /readyz listener; the controller serves /readyz on its unix socket only,
|
||||
# which the kubelet cannot probe.
|
||||
# which the kubelet cannot probe. `publicCredentials` maps the ids of the
|
||||
# credentials that hold a public CA file to their key in the CA ConfigMap.
|
||||
services = {
|
||||
swarm-controller = {
|
||||
inherit (deployCfg.swarm-controller) enable package;
|
||||
|
|
@ -60,6 +68,7 @@ let
|
|||
kind = "Deployment";
|
||||
healthEnv = null;
|
||||
etcFiles = [ "hyperhive/swarm-controller.json" ];
|
||||
publicCredentials = { };
|
||||
};
|
||||
swarm-notify-router = {
|
||||
inherit (deployCfg.notify-router) enable package;
|
||||
|
|
@ -67,6 +76,7 @@ let
|
|||
kind = "Deployment";
|
||||
healthEnv = "SWARM_NOTIFY_ROUTER_HEALTH_ADDR";
|
||||
etcFiles = [ ];
|
||||
publicCredentials.notify-router-bao-server-ca = baoServerCaKey;
|
||||
};
|
||||
swarm-ci-metrics = {
|
||||
inherit (deployCfg.ci-metrics) enable package;
|
||||
|
|
@ -75,6 +85,7 @@ let
|
|||
kind = "CronJob";
|
||||
healthEnv = null;
|
||||
etcFiles = [ ];
|
||||
publicCredentials = { };
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -176,7 +187,7 @@ let
|
|||
# plus the hive CA, assembled at runtime, so the cluster holds the one
|
||||
# bundle as a ConfigMap and each path the unit names mounts it.
|
||||
caFiles = lib.unique (
|
||||
lib.filter (v: lib.hasPrefix "/" v && baseNameOf v == "trust-bundle.pem") (lib.attrValues unitEnv)
|
||||
lib.filter (v: lib.hasPrefix "/" v && baseNameOf v == trustBundleKey) (lib.attrValues unitEnv)
|
||||
);
|
||||
|
||||
env =
|
||||
|
|
@ -226,20 +237,57 @@ let
|
|||
execWords = lib.filter (w: w != "") (lib.splitString " " (toString sc.ExecStart));
|
||||
entrypoint = "${svc.package}/bin/${name}";
|
||||
|
||||
volumes =
|
||||
lib.optional (credIds != [ ]) {
|
||||
name = "credentials";
|
||||
secret = {
|
||||
secretName = "${name}-credentials";
|
||||
# 0440: the pod's group reads them, as `LoadCredential` lets the
|
||||
# unit's user read them.
|
||||
defaultMode = 288;
|
||||
items = map (id: {
|
||||
key = id;
|
||||
path = id;
|
||||
}) credIds;
|
||||
# The credentials that are public CA files come from the CA ConfigMap, the
|
||||
# rest from the service's Secret. A volume holding both is a projected
|
||||
# one, which merges them into the one directory the unit's credentials
|
||||
# are in.
|
||||
publicIds = lib.filter (id: svc.publicCredentials ? ${id}) credIds;
|
||||
secretIds = lib.subtractLists publicIds credIds;
|
||||
# 0440: the pod's group reads them, as `LoadCredential` lets the unit's
|
||||
# user read them.
|
||||
credentialsMode = 288;
|
||||
credentialItems = map (id: {
|
||||
key = id;
|
||||
path = id;
|
||||
});
|
||||
credentialsVolume =
|
||||
if publicIds == [ ] then
|
||||
{
|
||||
name = "credentials";
|
||||
secret = {
|
||||
secretName = "${name}-credentials";
|
||||
defaultMode = credentialsMode;
|
||||
items = credentialItems credIds;
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
name = "credentials";
|
||||
projected = {
|
||||
defaultMode = credentialsMode;
|
||||
sources =
|
||||
lib.optional (secretIds != [ ]) {
|
||||
secret = {
|
||||
name = "${name}-credentials";
|
||||
items = credentialItems secretIds;
|
||||
};
|
||||
}
|
||||
++ [
|
||||
{
|
||||
configMap = {
|
||||
name = caConfigMap;
|
||||
items = map (id: {
|
||||
key = svc.publicCredentials.${id};
|
||||
path = id;
|
||||
}) publicIds;
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
volumes =
|
||||
lib.optional (credIds != [ ]) credentialsVolume
|
||||
++ lib.optional baoLogin {
|
||||
name = "bao-token";
|
||||
projected = {
|
||||
|
|
@ -260,7 +308,7 @@ let
|
|||
}
|
||||
++ lib.optional (caFiles != [ ]) {
|
||||
name = "ca-trust";
|
||||
configMap.name = "hyperhive-ca-trust";
|
||||
configMap.name = caConfigMap;
|
||||
}
|
||||
++ lib.optional (runtimeDir != null) {
|
||||
name = "runtime";
|
||||
|
|
@ -297,7 +345,7 @@ let
|
|||
++ map (f: {
|
||||
name = "ca-trust";
|
||||
mountPath = f;
|
||||
subPath = "trust-bundle.pem";
|
||||
subPath = trustBundleKey;
|
||||
readOnly = true;
|
||||
}) caFiles
|
||||
++ lib.optional (runtimeDir != null) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue