-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-local-certificates.sh
executable file
·49 lines (39 loc) · 1.45 KB
/
generate-local-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
#!/usr/bin/env sh
CERTS_DIR=~/local/certs
if [ ! -d "${CERTS_DIR}" ] ; then
echo "Creating directory ${CERTS_DIR}"
mkdir -p ${CERTS_DIR}
fi
# Generate certificates for a local certificate authority
if [ ! -f "${CERTS_DIR}/local-ca.key" ] ; then
echo "Creating local CA key : ${CERTS_DIR}/local-ca.key"
openssl genrsa -out ${CERTS_DIR}/local-ca.key 2048
fi
if [ ! -f "${CERTS_DIR}/local-ca.crt" ] ; then
echo "Creating local CA certificate : ${CERTS_DIR}/local-ca.crt"
openssl req -new -x509 -subj "/CN=Local CA" \
-key ${CERTS_DIR}/local-ca.key \
-out ${CERTS_DIR}/local-ca.crt
fi
# Create certificate for Argo CD and Grafana
if [ ! -f "${CERTS_DIR}/argocd-local.key" ] ; then
echo "Creating ArgoCD key and certificate"
openssl req -subj '/CN=argocd.local' \
-new -newkey rsa:2048 -sha256 -noenc -x509 \
-addext "subjectAltName = DNS:argocd.local" \
-CA ${CERTS_DIR}/local-ca.crt \
-CAkey ${CERTS_DIR}/local-ca.key \
-keyout ${CERTS_DIR}/argocd-local.key \
-out ${CERTS_DIR}/argocd-local.crt
fi
if [ ! -f "${CERTS_DIR}/grafana-local.key" ] ; then
openssl req -subj '/CN=grafana.local' \
-new -newkey rsa:2048 -sha256 -noenc -x509 \
-addext "subjectAltName = DNS:grafana.local" \
-CA ${CERTS_DIR}/local-ca.crt \
-CAkey ${CERTS_DIR}/local-ca.key \
-keyout ${CERTS_DIR}/grafana-local.key \
-out ${CERTS_DIR}/grafana-local.crt
fi
echo "Certificates and keys created in ${CERTS_DIR}"
ls -l ${CERTS_DIR}