blob: 9d5e52b75a7b73f3ce36c57823c9235630a542b8 [file] [log] [blame]
garciadeblas8d8cd992024-05-21 16:04:14 +02001#######################################################################################
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
18set -e -o pipefail
19
20export HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
21source "${HERE}/library/functions.sh"
22source "${HERE}/library/trap.sh"
23
24
25AGE_KEY_NAME="$1"
26CLUSTER_DIR="$2"
27
28# Load the contents of both keys
29export PRIVATE_KEY=$(<"${CREDENTIALS_DIR}/${AGE_KEY_NAME}.key")
30export PUBLIC_KEY=$(<"${CREDENTIALS_DIR}/${AGE_KEY_NAME}.pub")
31
32# Add the `age` private key to the cluster as secret:
33kubectl delete secret sops-age --namespace=flux-system 2> /dev/null || true
34# cat "${CREDENTIALS_DIR}/${AGE_KEY_NAME}.key" |
35echo "${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:
41cat <<EOF > "${CLUSTER_DIR}/.sops.yaml"
42creation_rules:
43 - encrypted_regex: ^(data|stringData)$
44 age: ${PUBLIC_KEY}
45 # - path_regex: .*.yaml
46 # encrypted_regex: ^(data|stringData)$
47 # age: ${PUBLIC_KEY}
48EOF
49
50# Add also the public key to the repository so that others who clone the repo can encrypt new files:
51cp "${CREDENTIALS_DIR}/${AGE_KEY_NAME}.pub" "${CLUSTER_DIR}/.sops.pub.asc"