2020-02-14 14:11:52 +01:00
|
|
|
#! /bin/bash
|
2020-03-17 10:30:25 +01:00
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "No argument supplied set days to 365"
|
|
|
|
DAYS=365
|
|
|
|
else
|
|
|
|
echo "No argument supplied set days to $1"
|
|
|
|
DAYS=$1
|
|
|
|
fi
|
2020-02-14 14:11:52 +01:00
|
|
|
|
2020-03-18 04:25:04 +01:00
|
|
|
CA_KEY="harbor_internal_ca.key"
|
|
|
|
CA_CRT="harbor_internal_ca.crt"
|
|
|
|
|
2020-02-14 14:11:52 +01:00
|
|
|
# CA key and certificate
|
2020-03-18 04:25:04 +01:00
|
|
|
if [[ ! -f $CA_KEY && ! -f $CA_CRT ]]; then
|
2020-03-17 10:30:25 +01:00
|
|
|
openssl req -x509 -nodes -days $DAYS -newkey rsa:4096 \
|
2020-03-18 04:25:04 +01:00
|
|
|
-keyout $CA_KEY -out $CA_CRT \
|
2020-02-14 14:11:52 +01:00
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware"
|
2020-03-18 04:25:04 +01:00
|
|
|
else
|
|
|
|
echo "$CA_KEY and $CA_CRT exist, use them to generate certs"
|
|
|
|
fi
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
# generate proxy key and csr
|
|
|
|
openssl req -new -newkey rsa:4096 -nodes -sha256 \
|
|
|
|
-keyout proxy.key \
|
|
|
|
-out proxy.csr \
|
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=proxy"
|
|
|
|
|
|
|
|
# Sign proxy
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:proxy > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in proxy.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out proxy.crt
|
2020-02-14 14:11:52 +01:00
|
|
|
|
2020-04-28 07:17:24 +02:00
|
|
|
# generate portal key and csr
|
|
|
|
openssl req -new -newkey rsa:4096 -nodes -sha256 \
|
|
|
|
-keyout portal.key \
|
|
|
|
-out portal.csr \
|
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=portal"
|
|
|
|
|
|
|
|
# Sign portal
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:portal > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in portal.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out portal.crt
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
# generate core key and csr
|
|
|
|
openssl req -new \
|
|
|
|
-newkey rsa:4096 -nodes -sha256 -keyout core.key \
|
|
|
|
-out core.csr \
|
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=core"
|
|
|
|
|
|
|
|
# Sign core csr with CA certificate and key
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:core > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in core.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out core.crt
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
# job_service key
|
|
|
|
openssl req -new \
|
|
|
|
-newkey rsa:4096 -nodes -sha256 -keyout job_service.key \
|
|
|
|
-out job_service.csr \
|
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=jobservice"
|
|
|
|
|
|
|
|
# sign job_service csr with CA certificate and key
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:jobservice > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in job_service.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out job_service.crt
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
# generate registry key
|
|
|
|
openssl req -new \
|
|
|
|
-newkey rsa:4096 -nodes -sha256 -keyout registry.key \
|
|
|
|
-out registry.csr \
|
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=registry"
|
|
|
|
|
|
|
|
# sign registry csr with CA certificate and key
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:registry > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in registry.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out registry.crt
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
# generate registryctl key
|
|
|
|
openssl req -new \
|
|
|
|
-newkey rsa:4096 -nodes -sha256 -keyout registryctl.key \
|
|
|
|
-out registryctl.csr \
|
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=registryctl"
|
|
|
|
|
|
|
|
# sign registryctl csr with CA certificate and key
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:registryctl > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in registryctl.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out registryctl.crt
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
|
2020-03-17 10:30:25 +01:00
|
|
|
# generate trivy_adapter key
|
|
|
|
openssl req -new \
|
|
|
|
-newkey rsa:4096 -nodes -sha256 -keyout trivy_adapter.key \
|
|
|
|
-out trivy_adapter.csr \
|
2020-03-18 04:25:04 +01:00
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=trivy-adapter"
|
2020-03-17 10:30:25 +01:00
|
|
|
|
|
|
|
# sign trivy_adapter csr with CA certificate and key
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:trivy-adapter > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in trivy_adapter.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out trivy_adapter.crt
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
# generate notary_signer key
|
|
|
|
openssl req -new \
|
|
|
|
-newkey rsa:4096 -nodes -sha256 -keyout notary_signer.key \
|
|
|
|
-out notary_signer.csr \
|
2020-04-02 20:04:51 +02:00
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=notary-signer"
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
# sign notary_signer csr with CA certificate and key
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:notary-signer > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in notary_signer.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out notary_signer.crt
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
# generate notary_server key
|
|
|
|
openssl req -new \
|
|
|
|
-newkey rsa:4096 -nodes -sha256 -keyout notary_server.key \
|
|
|
|
-out notary_server.csr \
|
2020-04-02 20:04:51 +02:00
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=notary-server"
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
# sign notary_server csr with CA certificate and key
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:notary-server > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in notary_server.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out notary_server.crt
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
# generate chartmuseum key
|
|
|
|
openssl req -new \
|
|
|
|
-newkey rsa:4096 -nodes -sha256 -keyout chartmuseum.key \
|
|
|
|
-out chartmuseum.csr \
|
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=chartmuseum"
|
|
|
|
|
|
|
|
# sign chartmuseum csr with CA certificate and key
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:chartmuseum > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in chartmuseum.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out chartmuseum.crt
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
# generate harbor_db key
|
|
|
|
openssl req -new \
|
|
|
|
-newkey rsa:4096 -nodes -sha256 -keyout harbor_db.key \
|
|
|
|
-out harbor_db.csr \
|
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=VMware/CN=harbor_db"
|
|
|
|
|
|
|
|
# sign harbor_db csr with CA certificate and key
|
2020-12-21 08:23:11 +01:00
|
|
|
echo subjectAltName = DNS.1:harbor_db > extfile.cnf
|
|
|
|
openssl x509 -req -days $DAYS -sha256 -in harbor_db.csr -CA harbor_internal_ca.crt -CAkey harbor_internal_ca.key -CAcreateserial -extfile extfile.cnf -out harbor_db.crt
|