4 SITE_NAMESPACE="${SITE_NAMESPACE:-metal3}"
7 gpg --with-colons --list-secret-keys $1 | awk -F: '/fpr/ {print $10;exit}'
10 function create_gpg_key {
13 # Create an rsa4096 key that does not expire
14 gpg --batch --full-generate-key <<EOF
21 Name-Real: ${key_name}
25 function export_gpg_private_key {
26 gpg --export-secret-keys --armor "$(_gpg_key_fp $1)"
29 function sops_encrypt {
33 local -r yaml_dir=$(dirname ${yaml})
34 local -r key_fp=$(_gpg_key_fp ${key_name})
36 # Commit the public key to the repository so that team members who
37 # clone the repo can encrypt new files
38 echo "Creating ${yaml_dir}/sops.pub.asc with public key used to encrypt secrets"
39 gpg --export --armor "${key_fp}" >${yaml_dir}/sops.pub.asc
41 # Add .sops.yaml so users won't have to worry about specifying the
42 # proper key for the target cluster or namespace
43 echo "Creating ${yaml_dir}/.sops.yaml SOPS configuration file"
44 cat <<EOF > ${yaml_dir}/.sops.yaml
47 encrypted_regex: ^(bmcPassword|decryptionSecret|hashedPassword|emcoPassword|rootPassword)$
51 sops --encrypt --in-place --config=${yaml_dir}/.sops.yaml ${yaml}
54 function sops_decrypt {
57 local -r yaml_dir=$(dirname ${yaml})
58 sops --decrypt --in-place --config=${yaml_dir}/.sops.yaml ${yaml}
61 function flux_site_source_name {
64 echo $(basename ${url})-${branch}
67 function flux_site_kustomization_name {
71 echo $(flux_site_source_name ${url} ${branch})-site-$(basename ${path})
74 function flux_create_site {
80 local -r source_name=$(flux_site_source_name ${url} ${branch})
81 local -r kustomization_name=$(flux_site_kustomization_name ${url} ${branch} ${path})
82 local -r key_fp=$(gpg --with-colons --list-secret-keys ${key_name} | awk -F: '/fpr/ {print $10;exit}')
83 local -r secret_name="${key_name}-sops-gpg"
85 flux create source git ${source_name} --url=${url} --branch=${branch}
86 gpg --export-secret-keys --armor "$(_gpg_key_fp ${key_name})" |
87 kubectl -n flux-system create secret generic ${secret_name} --from-file=sops.asc=/dev/stdin --dry-run=client -o yaml |
89 kubectl create namespace ${SITE_NAMESPACE} --dry-run=client -o yaml | kubectl apply -f -
90 flux create kustomization ${kustomization_name} --target-namespace=${SITE_NAMESPACE} --path=${path} --source=GitRepository/${source_name} --prune=true \
91 --decryption-provider=sops --decryption-secret=${secret_name}