2021-04-05 22:01:17 +00:00
|
|
|
#! Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
|
2020-11-17 17:24:38 +00:00
|
|
|
#! SPDX-License-Identifier: Apache-2.0
|
2021-06-03 18:24:26 +00:00
|
|
|
|
|
|
|
#@ load("@ytt:data", "data")
|
|
|
|
|
2020-11-17 17:24:38 +00:00
|
|
|
---
|
|
|
|
apiVersion: v1
|
|
|
|
kind: ServiceAccount
|
|
|
|
metadata:
|
|
|
|
name: cert-issuer
|
2021-04-05 22:01:17 +00:00
|
|
|
namespace: tools
|
2020-11-17 17:24:38 +00:00
|
|
|
labels:
|
|
|
|
app: cert-issuer
|
|
|
|
---
|
|
|
|
apiVersion: rbac.authorization.k8s.io/v1
|
|
|
|
kind: Role
|
|
|
|
metadata:
|
|
|
|
name: cert-issuer
|
2021-04-05 22:01:17 +00:00
|
|
|
namespace: tools
|
2020-11-17 17:24:38 +00:00
|
|
|
labels:
|
|
|
|
app: cert-issuer
|
|
|
|
rules:
|
|
|
|
- apiGroups: [""]
|
|
|
|
resources: [secrets]
|
|
|
|
verbs: [create, get, patch, update, watch, delete]
|
|
|
|
---
|
|
|
|
kind: RoleBinding
|
|
|
|
apiVersion: rbac.authorization.k8s.io/v1
|
|
|
|
metadata:
|
|
|
|
name: cert-issuer
|
2021-04-05 22:01:17 +00:00
|
|
|
namespace: tools
|
2020-11-17 17:24:38 +00:00
|
|
|
labels:
|
|
|
|
app: cert-issuer
|
|
|
|
subjects:
|
|
|
|
- kind: ServiceAccount
|
|
|
|
name: cert-issuer
|
2021-04-05 22:01:17 +00:00
|
|
|
namespace: tools
|
2020-11-17 17:24:38 +00:00
|
|
|
roleRef:
|
|
|
|
kind: Role
|
|
|
|
name: cert-issuer
|
|
|
|
apiGroup: rbac.authorization.k8s.io
|
|
|
|
---
|
|
|
|
apiVersion: batch/v1
|
|
|
|
kind: Job
|
|
|
|
metadata:
|
|
|
|
name: cert-issuer
|
2021-04-05 22:01:17 +00:00
|
|
|
namespace: tools
|
2020-11-17 17:24:38 +00:00
|
|
|
labels:
|
|
|
|
app: cert-issuer
|
|
|
|
spec:
|
|
|
|
template:
|
|
|
|
spec:
|
|
|
|
serviceAccountName: cert-issuer
|
|
|
|
initContainers:
|
|
|
|
- name: generate-certs
|
2021-06-03 18:24:26 +00:00
|
|
|
image: #@ data.values.cfssl_image
|
2020-11-17 17:24:38 +00:00
|
|
|
command: ["/bin/bash"]
|
|
|
|
args:
|
|
|
|
- -c
|
|
|
|
- |
|
|
|
|
cd /var/certs
|
|
|
|
cfssl print-defaults config > /tmp/cfssl-default.json
|
|
|
|
echo '{"CN": "Pinniped Test","hosts": [],"key": {"algo": "ecdsa","size": 256},"names": [{}]}' > /tmp/csr.json
|
|
|
|
|
|
|
|
echo "generating CA key..."
|
|
|
|
cfssl genkey \
|
|
|
|
-config /tmp/cfssl-default.json \
|
|
|
|
-initca /tmp/csr.json \
|
|
|
|
| cfssljson -bare ca
|
|
|
|
|
|
|
|
echo "generating Dex server certificate..."
|
|
|
|
cfssl gencert \
|
|
|
|
-ca ca.pem -ca-key ca-key.pem \
|
|
|
|
-config /tmp/cfssl-default.json \
|
|
|
|
-profile www \
|
2021-04-05 22:01:17 +00:00
|
|
|
-cn "dex.tools.svc.cluster.local" \
|
|
|
|
-hostname "dex.tools.svc.cluster.local" \
|
2020-11-17 17:24:38 +00:00
|
|
|
/tmp/csr.json \
|
|
|
|
| cfssljson -bare dex
|
|
|
|
|
2021-04-15 00:49:40 +00:00
|
|
|
# Cheat and add 127.0.0.1 as an IP SAN so we can use the ldaps port through port forwarding.
|
2021-05-18 23:38:12 +00:00
|
|
|
# Also allow the server to be accessed by multiple Service names to different Services
|
|
|
|
# can provide/hide different ports.
|
2021-04-05 22:01:17 +00:00
|
|
|
echo "generating LDAP server certificate..."
|
|
|
|
cfssl gencert \
|
|
|
|
-ca ca.pem -ca-key ca-key.pem \
|
|
|
|
-config /tmp/cfssl-default.json \
|
|
|
|
-profile www \
|
|
|
|
-cn "ldap.tools.svc.cluster.local" \
|
2021-05-18 23:38:12 +00:00
|
|
|
-hostname "ldap.tools.svc.cluster.local,ldaps.tools.svc.cluster.local,ldapstarttls.tools.svc.cluster.local,127.0.0.1" \
|
2021-04-05 22:01:17 +00:00
|
|
|
/tmp/csr.json \
|
|
|
|
| cfssljson -bare ldap
|
|
|
|
|
2020-11-17 17:24:38 +00:00
|
|
|
chmod -R 777 /var/certs
|
|
|
|
|
2021-04-15 00:49:40 +00:00
|
|
|
echo
|
2020-11-17 17:24:38 +00:00
|
|
|
echo "generated certificates:"
|
|
|
|
ls -l /var/certs
|
2021-04-15 00:49:40 +00:00
|
|
|
echo
|
|
|
|
echo "CA cert..."
|
|
|
|
cat ca.pem | openssl x509 -text
|
|
|
|
echo
|
|
|
|
echo "Dex cert..."
|
|
|
|
cat dex.pem | openssl x509 -text
|
|
|
|
echo
|
|
|
|
echo "LDAP cert..."
|
|
|
|
cat ldap.pem | openssl x509 -text
|
2020-11-17 17:24:38 +00:00
|
|
|
volumeMounts:
|
|
|
|
- name: certs
|
|
|
|
mountPath: /var/certs
|
|
|
|
containers:
|
|
|
|
- name: save-certs
|
2021-06-03 18:24:26 +00:00
|
|
|
image: #@ data.values.kubectl_image
|
2020-11-17 17:24:38 +00:00
|
|
|
command: ["/bin/bash"]
|
|
|
|
args:
|
|
|
|
- -c
|
|
|
|
- |
|
2021-04-15 00:49:40 +00:00
|
|
|
kubectl create secret generic -n tools certs --from-file=/var/certs \
|
|
|
|
--dry-run=client --output yaml | kubectl apply -f -
|
2020-11-17 17:24:38 +00:00
|
|
|
volumeMounts:
|
|
|
|
- name: certs
|
|
|
|
mountPath: /var/certs
|
|
|
|
volumes:
|
|
|
|
- name: certs
|
|
|
|
emptyDir: {}
|
2021-04-05 22:01:17 +00:00
|
|
|
restartPolicy: Never
|