Skip to content

Commit 7c15eaf

Browse files
committed
k8s expects tls.crt not ssl_crt
1 parent da8b204 commit 7c15eaf

File tree

2 files changed

+51
-38
lines changed

2 files changed

+51
-38
lines changed

generate-certs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export SSL_IP=${SSL_IP}
2626
export K8S_NAME=${K8S_NAME:-"omgwtfssl"}
2727
export K8S_NAMESPACE=${K8S_NAMESPACE:-"default"}
2828
export K8S_SAVE_CA_KEY=${K8S_SAVE_CA_KEY}
29+
export K8S_SAVE_CA_CRT=${K8S_SAVE_CA_CRT}
30+
export K8S_SHOW_SECRET=${K8S_SHOW_SECRET}
2931

3032
export OUTPUT=${OUTPUT:-"yaml"}
3133

@@ -88,15 +90,8 @@ openssl req -new -key ${SSL_KEY} -out ${SSL_CSR} -subj "/CN=${SSL_SUBJECT}" -con
8890
openssl x509 -req -in ${SSL_CSR} -CA ${CA_CERT} -CAkey ${CA_KEY} -CAcreateserial -out ${SSL_CERT} \
8991
-days ${SSL_EXPIRE} -extensions v3_req -extfile ${SSL_CONFIG} > /dev/null || exit 1
9092

91-
if [[ -z $SILENT ]]; then
92-
echo "====> Complete"
93-
echo "keys can be found in volume mapped to $(pwd)"
94-
echo
95-
96-
if [[ ${OUTPUT} == "k8s" ]]; then
97-
echo "====> Output results as base64 k8s secrets"
98-
echo "---"
99-
cat << EOM | tee /certs/secret.yaml
93+
# create k8s secret file
94+
cat << EOM > /certs/secret.yaml
10095
apiVersion: v1
10196
kind: Secret
10297
metadata:
@@ -106,19 +101,31 @@ type: kubernetes.io/tls
106101
data:
107102
EOM
108103
if [[ -n $K8S_SAVE_CA_KEY ]]; then
109-
echo -n " ca_key: " | tee -a /certs/secret.yaml
110-
cat $CA_KEY | base64 | tr '\n' ',' | sed 's/,//g' | tee -a /certs/secret.yaml
111-
echo | tee -a /certs/secret.yaml
104+
echo -n " ca.key: " >> /certs/secret.yaml
105+
cat $CA_KEY | base64 | tr '\n' ',' | sed 's/,//g' >> /certs/secret.yaml
106+
echo >> /certs/secret.yaml
107+
fi
108+
if [[ -n $K8S_SAVE_CA_CRT ]]; then
109+
echo -n " ca.crt: " >> /certs/secret.yaml
110+
cat $CA_CERT | base64 | tr '\n' ',' | sed 's/,//g' >> /certs/secret.yaml
111+
echo >> /certs/secret.yaml
112112
fi
113-
echo -n " ca_crt: " | tee -a /certs/secret.yaml
114-
cat $CA_CERT | base64 | tr '\n' ',' | sed 's/,//g' | tee -a /certs/secret.yaml
115-
echo | tee -a /certs/secret.yaml
116-
echo -n " ssl_key: " | tee -a /certs/secret.yaml
117-
cat $SSL_KEY | base64 | tr '\n' ',' | sed 's/,//g' | tee -a /certs/secret.yaml
118-
echo | tee -a /certs/secret.yaml
119-
echo -n " ssl_crt: " | tee -a /certs/secret.yaml
120-
cat $SSL_CERT | base64 | tr '\n' ',' | sed 's/,//g' | tee -a /certs/secret.yaml
121-
echo | tee -a /certs/secret.yaml
113+
echo -n " tls.key: " >> /certs/secret.yaml
114+
cat $SSL_KEY | base64 | tr '\n' ',' | sed 's/,//g' >> /certs/secret.yaml
115+
echo >> /certs/secret.yaml
116+
echo -n " tls.crt: " >> /certs/secret.yaml
117+
cat $SSL_CERT | base64 | tr '\n' ',' | sed 's/,//g' >> /certs/secret.yaml
118+
echo >> /certs/secret.yaml
119+
120+
if [[ -z $SILENT ]]; then
121+
echo "====> Complete"
122+
echo "keys can be found in volume mapped to $(pwd)"
123+
echo
124+
125+
if [[ ${OUTPUT} == "k8s" ]]; then
126+
echo "====> Output results as base64 k8s secrets"
127+
echo "---"
128+
cat /certs/secret.yaml
122129

123130
else
124131
echo "====> Output results as YAML"

kubernetes/omgwtfssl.yaml

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
kind: ConfigMap
2+
apiVersion: v1
3+
metadata:
4+
name: omgwtfssl
5+
data:
6+
SSL_SUBJECT: "*.192.168.99.100.xip.io"
7+
SSL_IP: "192.168.99.100"
8+
SSL_EXPIRE: "3600"
9+
SILENT: "true"
10+
---
111
apiVersion: batch/v1
212
kind: Job
313
metadata:
@@ -6,26 +16,22 @@ spec:
616
template:
717
spec:
818
restartPolicy: Never
9-
containers:
19+
initContainers:
1020
- name: omgwtfssl
11-
image: paulczar/omgwtfssl
12-
env:
13-
- name: SSL_SUBJECT
14-
value: "*.192.168.99.100.xip.io"
15-
- name: SSL_IP
16-
value: "192.168.99.100"
17-
- name: SSL_EXPIRE
18-
value: "3600"
19-
- name: OUTPUT
20-
value: "k8s"
21+
image: paulczar/omgwtfssl:latest
22+
envFrom:
23+
- configMapRef:
24+
name: omgwtfssl
2125
volumeMounts:
22-
- name: secret-path
23-
mountPath: /k8s
26+
- name: certs-path
27+
mountPath: /certs
28+
containers:
2429
- name: kubectl
25-
image: lachlanevenson/k8s-kubectl:v.1.9.3
30+
image: lachlanevenson/k8s-kubectl:v1.9.3
31+
command: ["kubectl", "apply", "-f", "/certs/secret.yaml"]
2632
volumeMounts:
27-
- name: secret-path
28-
mountPath: /k8s
33+
- name: certs-path
34+
mountPath: /certs
2935
volumes:
30-
- name: secret-path
36+
- name: certs-path
3137
emptyDir: {}

0 commit comments

Comments
 (0)