| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 1 | ####################################################################################### |
| 2 | # Copyright ETSI Contributors and Others. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 13 | # implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | ####################################################################################### |
| 17 | |
| 18 | set -e -o pipefail |
| 19 | |
| 20 | export HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")") |
| 21 | source "${HERE}/library/functions.sh" |
| 22 | source "${HERE}/library/trap.sh" |
| 23 | |
| 24 | |
| 25 | AGE_KEY_NAME="$1" |
| 26 | CLUSTER_DIR="$2" |
| 27 | |
| 28 | # Load the contents of both keys |
| 29 | export PRIVATE_KEY=$(<"${CREDENTIALS_DIR}/${AGE_KEY_NAME}.key") |
| 30 | export PUBLIC_KEY=$(<"${CREDENTIALS_DIR}/${AGE_KEY_NAME}.pub") |
| 31 | |
| 32 | # Add the `age` private key to the cluster as secret: |
| 33 | kubectl delete secret sops-age --namespace=flux-system 2> /dev/null || true |
| 34 | # cat "${CREDENTIALS_DIR}/${AGE_KEY_NAME}.key" | |
| 35 | echo "${PRIVATE_KEY}" | |
| 36 | kubectl create secret generic sops-age \ |
| 37 | --namespace=flux-system \ |
| 38 | --from-file=age.agekey=/dev/stdin |
| 39 | |
| 40 | # Create SOPS configuration at the root folder of the management cluster: |
| 41 | cat <<EOF > "${CLUSTER_DIR}/.sops.yaml" |
| 42 | creation_rules: |
| 43 | - encrypted_regex: ^(data|stringData)$ |
| 44 | age: ${PUBLIC_KEY} |
| 45 | # - path_regex: .*.yaml |
| 46 | # encrypted_regex: ^(data|stringData)$ |
| 47 | # age: ${PUBLIC_KEY} |
| 48 | EOF |
| 49 | |
| 50 | # Add also the public key to the repository so that others who clone the repo can encrypt new files: |
| 51 | cp "${CREDENTIALS_DIR}/${AGE_KEY_NAME}.pub" "${CLUSTER_DIR}/.sops.pub.asc" |