-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathssl-script.sh
72 lines (58 loc) · 1.98 KB
/
ssl-script.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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -o errexit
set -o nounset
set -o pipefail
# Define the script root and temporary directory for certificates
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
TMP_DIR="/tmp/vpa-certs"
# Create the temporary directory for certificates
mkdir -p ${TMP_DIR}
# Create the OpenSSL configuration file for CA
cat > ${TMP_DIR}/vpa-openssl.cnf <<EOF
[ req ]
default_bits = 2048
distinguished_name = req_distinguished_name
x509_extensions = v3_ca
prompt = no
[ req_distinguished_name ]
C = US
ST = State
L = City
O = Organization
OU = Organizational Unit
CN = vpa_webhook_ca
[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer:always
basicConstraints = CA:true
EOF
# Generate CA certificate
openssl req -x509 -newkey rsa:2048 -keyout ${TMP_DIR}/ca.key -out ${TMP_DIR}/ca.crt -days 365 -nodes -config ${TMP_DIR}/vpa-openssl.cnf
# Create the OpenSSL configuration file for server certificate
cat > ${TMP_DIR}/vpa-server-openssl.cnf <<EOF
[ req ]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no
[ req_distinguished_name ]
C = US
ST = State
L = City
O = Organization
OU = Organizational Unit
CN = vpa_webhook
[ v3_req ]
subjectAltName = @alt_names
[ alt_names ]
DNS.1 = vpa-webhook.kube-system.svc
DNS.2 = vpa-webhook.kube-system
EOF
# Generate server certificate
openssl req -new -newkey rsa:2048 -keyout ${TMP_DIR}/server.key -out ${TMP_DIR}/server.csr -nodes -config ${TMP_DIR}/vpa-server-openssl.cnf
openssl x509 -req -in ${TMP_DIR}/server.csr -CA ${TMP_DIR}/ca.crt -CAkey ${TMP_DIR}/ca.key -CAcreateserial -out ${TMP_DIR}/server.crt -days 365 -extensions v3_req -extfile ${TMP_DIR}/vpa-server-openssl.cnf
# Create Kubernetes secret with the generated certificates
kubectl create secret tls vpa-tls-certs --cert=${TMP_DIR}/server.crt --key=${TMP_DIR}/server.key -n kube-system
# Run the original VPA process YAMLs script
$SCRIPT_ROOT/hack/vpa-up.sh create $*