X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=deploy%2Fsite%2Fsite.sh;h=aea8c86d2e0e3236b20a848764de8fc8fb3d1d20;hb=HEAD;hp=ca117cbba51cb1db9cdce4c937f4e54035e69938;hpb=878ea0c739ece152793328a795780c734e4ac9b2;p=icn.git diff --git a/deploy/site/site.sh b/deploy/site/site.sh index ca117cb..aea8c86 100755 --- a/deploy/site/site.sh +++ b/deploy/site/site.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -eu -o pipefail +set -eux -o pipefail SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))" LIBDIR="$(dirname $(dirname ${SCRIPTDIR}))/env/lib" @@ -7,19 +7,122 @@ LIBDIR="$(dirname $(dirname ${SCRIPTDIR}))/env/lib" source $LIBDIR/common.sh source $SCRIPTDIR/common.sh +# !!!NOTE!!! THE KEYS USED BELOW ARE FOR TEST PURPOSES ONLY. DO NOT +# USE THESE OUTSIDE OF THIS ICN VIRTUAL TEST ENVIRONMENT. + +function build_istio_root_certs { + # Create root CA certs for use by Istio in each cluster + clone_istio_repository + local -r certs_dir=${SCRIPTDIR}/secrets/certs + rm -rf ${certs_dir} + mkdir -p ${certs_dir} + certs=${ISTIOPATH}/tools/certs + make -C ${certs} -f Makefile.selfsigned.mk ROOT_CN="EMCO Root CA" ROOTCA_ORG=project-emco.io root-ca + find ${certs}/root-* -exec cp '{}' ${certs_dir} ';' +} + +function build_site_source { + local -r site_dir=$1 + local -r reuse_credentials=${2:-false} + + # First decrypt the existing site YAML, otherwise we'll be + # attempting to encrypt it twice below + if [[ -f ${FLUX_SOPS_PRIVATE_KEY} ]]; then + gpg --import ${FLUX_SOPS_PRIVATE_KEY} + for yaml in ${site_dir}/cluster/*/*.yaml ${site_dir}/deployment/*.yaml; do + sops_decrypt ${yaml} ${site_dir} + done + fi + + if ! ${reuse_credentials}; then + # Generate user password and authorized key in site YAML + # To login to guest, ssh -i ${site_dir}/id_rsa + HASHED_PASSWORD=$(mkpasswd --method=SHA-512 --rounds 10000 "mypasswd") + ssh-keygen -t rsa -N "" -f ${site_dir}/id_rsa <<${site_dir}/cluster/${name}/istio-cacerts.yaml + fi + done + + # Encrypt the site YAML + for yaml in ${site_dir}/cluster/*/*.yaml ${site_dir}/deployment/*.yaml; do + sops_encrypt ${yaml} ${FLUX_SOPS_KEY_NAME} ${site_dir} + done +} + +function create_gpg_key { + local -r key_name=$1 + + # Create an rsa4096 key that does not expire + gpg --batch --full-generate-key <${FLUX_SOPS_PRIVATE_KEY} + + build_istio_root_certs + + build_site_source ${SCRIPTDIR}/vm-mc + build_site_source ${SCRIPTDIR}/vm + build_site_source ${SCRIPTDIR}/pod11 true # re-use existing credentials in site +} + case $1 in "create-gpg-key") create_gpg_key $2 ;; "sops-encrypt-site") sops_encrypt $2 $3 ;; - "sops-decrypt-site") sops_decrypt $2 ;; + "sops-decrypt-site") + if [[ $# -eq 2 ]]; then + sops_decrypt $2 + else + sops_decrypt $2 $3 + fi + ;; "flux-create-site") flux_create_site $2 $3 $4 $5;; + "build-source") build_source ;; *) cat <