-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-key.sh
executable file
·56 lines (47 loc) · 1.42 KB
/
generate-key.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /bin/bash
export KEY_NAME="ik42p.kubasobon.com"
export KEY_COMMENT="Testing SOPS for ista"
echo "Generating GPG key..."
gpg --batch --full-generate-key <<EOF
%no-protection
Key-Type: 1
Key-Length: 4096
Subkey-Type: 1
Subkey-Length: 4096
Expire-Date: 0
Name-Comment: ${KEY_COMMENT}
Name-Real: ${KEY_NAME}
EOF
export KEY_FP=$(gpg --list-secret-keys "${KEY_NAME}" | head -n2 | tail -n 1 | awk '{print $1}')
echo "Generated key $KEY_NAME ($KEY_FP)"
echo "Creating k8s secret..."
gpg --export-secret-keys --armor "${KEY_FP}" |
kubectl create secret generic sops-gpg \
--namespace=flux-app \
--from-file=sops.asc=/dev/stdin
echo "Exporting keys..."
gpg --export-secret-keys --armor "${KEY_FP}" > private.key
gpg --export --armor "${KEY_FP}" > public.key
gpg --export --armor "${KEY_FP}" > ./encrypted-data/.sops.pub.asc
echo "Creating encrypted-data/.sops.yaml rules..."
cat <<EOF > ./encrypted-data/.sops.yaml
creation_rules:
- path_regex: .*.yaml
encrypted_regex: ^(data|stringData)$
pgp: "${KEY_FP}"
EOF
cat <<EOF > ./encrypted-data-before-sops/.sops.yaml
creation_rules:
- path_regex: .*.yaml
encrypted_regex: ^(data|stringData)$
pgp: "${KEY_FP}"
EOF
echo "Encrypting sample.yaml..."
cd ./encrypted-data-before-sops
sops --encrypt \
--pgp "${KEY_FP}" \
sample.yaml \
> ../encrypted-data/sample.yaml
echo "Done!"
# If you want to delete the keys from your keychain
# gpg --delete-secret-keys "${KEY_FP}"