Add controller proxy certs.

This commit is contained in:
Tom Alexander
2025-12-14 14:48:53 -05:00
parent b33bb736e6
commit 771ec2e38a
8 changed files with 165 additions and 4 deletions

View File

@@ -0,0 +1,13 @@
{
"signing": {
"default": {
"expiry": "8760h"
},
"profiles": {
"kubernetes": {
"usages": ["signing", "key encipherment", "server auth", "client auth"],
"expiry": "8760h"
}
}
}
}

View File

@@ -0,0 +1,16 @@
{
"CN": "system:node:controller0",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "US",
"L": "Portland",
"O": "system:nodes",
"OU": "Kubernetes The Hard Way",
"ST": "Oregon"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"CN": "system:node:controller1",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "US",
"L": "Portland",
"O": "system:nodes",
"OU": "Kubernetes The Hard Way",
"ST": "Oregon"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"CN": "system:node:controller2",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "US",
"L": "Portland",
"O": "system:nodes",
"OU": "Kubernetes The Hard Way",
"ST": "Oregon"
}
]
}

View File

@@ -0,0 +1,48 @@
# unpackPhase
# patchPhase
# configurePhase
# buildPhase
# checkPhase
# installPhase
# fixupPhase
# installCheckPhase
# distPhase
{
lib,
stdenv,
sqlite,
cfssl,
k8s,
all_hostnames,
controllers,
...
}:
let
get_hostnames = (
hostname: (builtins.concatStringsSep "," ([ hostname ] ++ controllers."${hostname}".internal_ips))
);
install_body = (
lib.concatMapStringsSep "\n" (hostname: ''
cfssl gencert \
-ca=${k8s.requestheader-client-ca}/requestheader-client-ca.pem \
-ca-key=${k8s.requestheader-client-ca}/requestheader-client-ca-key.pem \
-config=${./files/ca-config.json} \
-hostname=${get_hostnames hostname} \
-profile=kubernetes \
${./files}/${hostname}-proxy-csr.json | cfssljson -bare ${hostname}-proxy
'') (builtins.attrNames controllers)
);
in
stdenv.mkDerivation (finalAttrs: {
name = "k8s-controller-proxy";
nativeBuildInputs = [ cfssl ];
buildInputs = [ ];
unpackPhase = "true";
installPhase = ''
mkdir -p "$out"
cd "$out"
''
+ install_body;
})

View File

@@ -10,5 +10,6 @@ symlinkJoin {
k8s.ca
k8s.service_account
k8s.requestheader-client-ca
k8s.controller-proxy
];
}