-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_certificates.sh
72 lines (64 loc) · 1.58 KB
/
generate_certificates.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
namespace="${1:-}"
if [[ -z "$namespace" ]] ; then
echo "Syntax: $0 <namespace>"
exit 1
fi
echo "Using namespace: $namespace"
tmpdir="$(mktemp -d)"
cfssl_image=cfssl/cfssl:latest
# docker pull "$cfssl_image"
echo "Generating TLS certs"
mkdir "$tmpdir/output"
openssl req -x509 -sha256 -new -nodes -days 365 -newkey rsa:2048 -keyout "$tmpdir/metrics-ca.key" -out "$tmpdir/metrics-ca.crt" -subj "/CN=ca"
cat >"$tmpdir/metrics-ca-config.json" <<EOF
{
"signing": {
"default": {
"expiry": "43800h",
"usages": ["signing", "key encipherment", "metrics"]
}
}
}
EOF
cat >"$tmpdir/crt-config.json" <<EOF
{
"CN": "custom-metrics-apiserver",
"hosts": [
"custom-metrics-apiserver",
"custom-metrics-apiserver.$namespace",
"custom-metrics-apiserver.$namespace.svc"
],
"key": {"algo": "rsa", "size": 2048}
}
EOF
usergroup="$(id -u):$(id -g)"
docker run --rm -i \
-v "$tmpdir:/workdir" \
-w /workdir \
--user "$usergroup" \
"$cfssl_image" \
gencert \
-ca=metrics-ca.crt \
-ca-key=metrics-ca.key \
-config=metrics-ca-config.json \
- \
<"$tmpdir/crt-config.json" \
| docker run --rm -i \
--entrypoint=cfssljson \
-v "$tmpdir:/workdir" \
-w /workdir \
--user "$usergroup" \
"$cfssl_image" \
-bare ./output/apiserver
echo "--- 8< --- Add the following to values-custom-secret.yaml --- 8< ---"
cat <<EOF
---
# namespace: $namespace
customMetrics:
apiService:
caBundle: '$(base64 -w 0 "$tmpdir/metrics-ca.crt")'
servingCert: '$(base64 -w 0 "$tmpdir/output/apiserver.pem")'
servingKey: '$(base64 -w 0 "$tmpdir/output/apiserver-key.pem")'
EOF
rm -rf "$tmpdir"