Skip to content

Commit 65c2ab7

Browse files
committed
Aded setup_ksops role
1 parent b92aca6 commit 65c2ab7

File tree

2 files changed

+160
-0
lines changed

2 files changed

+160
-0
lines changed

roles/acm/setup_ksops/README.md

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# setup_ksops
2+
3+
Installs and sets up the KSOPS Kustomize plugin on the OpenShift GitOps Operator.
4+
5+
## Variables
6+
7+
| Variable | Default | Required | Description
8+
| ---------------- | ------- | -------- | -----------
9+
| sk_age_key | | yes | A literal age generated (age-keygen) key. If kept in a version control service, it's recommeneded to vault-encrypt it.
10+
11+
## Example of age key
12+
13+
```
14+
# created: 2025-04-16T11:28:48Z
15+
# public key: age1j24rsa89nhv86dstnl696pfhxlngktjl5gcvya6y6ykg8t5jkqgsv0ua36
16+
AGE-SECRET-KEY-16NSYF9LSS3QZKLXFEYS5K36FPQC62QLZPNA02H7YWV0SFFVXF2PQNRZPNQ
17+
```
18+
19+
## Usage examples
20+
21+
```
22+
- name: Setup the KSOPS Kustomize plugin
23+
ansible.builtin.include_role:
24+
name: redhatci.ocp.acm.setup_ksops
25+
vars:
26+
sk_age_key: |
27+
# created: 2025-04-16T11:28:48Z
28+
# public key: age1j24rsa89nhv86dstnl696pfhxlngktjl5gcvya6y6ykg8t5jkqgsv0ua36
29+
AGE-SECRET-KEY-16NSYF9LSS3QZKLXFEYS5K36FPQC62QLZPNA02H7YWV0SFFVXF2PQNRZPNQ
30+
```
31+
32+
## How to encrypt the gitops data
33+
34+
Install first the required binaries (age and [sops](https://github.com/getsops/sops/releases)):
35+
36+
```
37+
dnf install age
38+
39+
# Download the sops binary
40+
curl -LO https://github.com/getsops/sops/releases/download/v3.10.2/sops-v3.10.2.linux.amd64
41+
42+
# Move the binary in to your PATH
43+
mv sops-v3.10.2.linux.amd64 /usr/local/bin/sops
44+
45+
# Make the binary executable
46+
chmod +x /usr/local/bin/sops
47+
48+
```
49+
50+
Create a working directory:
51+
52+
```
53+
mkdir sops
54+
cd sops
55+
```
56+
57+
Create an age key:
58+
59+
```
60+
age-keygen -o age.key
61+
```
62+
63+
Define the SOPS creation rules. The age public key is available in the age.key file:
64+
65+
```
66+
cat <<EOF > .sops.yaml
67+
creation_rules:
68+
- encrypted_regex: "^(data|stringData)$"
69+
age: age1...< your age public key>
70+
EOF
71+
```
72+
73+
Encrypt your secret files in your local copy of the GitOps repository:
74+
75+
```
76+
sops --encrypt --in-place /path/to/gitops/secret.yaml
77+
```
78+
79+
Add a KSOPS generator to your repository:
80+
81+
```
82+
cat <<EOF > secret-generator.yaml
83+
apiVersion: viaduct.ai/v1
84+
kind: ksops
85+
metadata:
86+
# Specify a name
87+
name: secret-generator
88+
files:
89+
- ./secret.yaml
90+
EOF
91+
```
92+
93+
Include the KSOPS generator in your kustomization file:
94+
95+
```
96+
cat <<EOF > kustomization.yaml
97+
generators:
98+
- ./secret-generator.yaml
99+
EOF
100+
```
101+
102+
Add the new files to your git repository and commit the changes.

roles/acm/setup_ksops/tasks/main.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
- name: Verify SOPS age key is set
2+
ansible.builtin.assert:
3+
that:
4+
- sk_age_key is defined
5+
6+
- name: Load the SOPS age key into the cluster
7+
kubernetes.core.k8s:
8+
definition:
9+
apiVersion: v1
10+
kind: Secret
11+
type: Opaque
12+
metadata:
13+
name: sops-age
14+
namespace: openshift-gitops
15+
data:
16+
keys.txt: "{{ sk_age_key | b64encode }}"
17+
18+
- name: Patch the OpenShift GitOps ArgoCD resource
19+
kubernetes.core.k8s:
20+
definition:
21+
apiVersion: argoproj.io/v1beta1
22+
kind: ArgoCD
23+
metadata:
24+
name: openshift-gitops
25+
namespace: openshift-gitops
26+
spec:
27+
kustomizeBuildOptions: --enable-alpha-plugins --enable-exec
28+
repo:
29+
env:
30+
- name: XDG_CONFIG_HOME
31+
value: /.config
32+
- name: SOPS_AGE_KEY_FILE
33+
value: /.config/sops/age/keys.txt
34+
volumes:
35+
- name: custom-tools
36+
emptyDir: {}
37+
- name: sops-age
38+
secret:
39+
secretName: sops-age
40+
initContainers:
41+
- name: install-ksops
42+
image: quay.io/viaductoss/ksops:v4.3.3
43+
command: ["/bin/sh", "-c"]
44+
args:
45+
- 'echo "Installing KSOPS..."; cp ksops /custom-tools/; cp $GOPATH/bin/kustomize /custom-tools/; echo "Done.";'
46+
volumeMounts:
47+
- mountPath: /custom-tools
48+
name: custom-tools
49+
volumeMounts:
50+
- mountPath: /usr/local/bin/kustomize
51+
name: custom-tools
52+
subPath: kustomize
53+
- mountPath: /.config/kustomize/plugin/viaduct.ai/v1/ksops/ksops
54+
name: custom-tools
55+
subPath: ksops
56+
- mountPath: /.config/sops/age/keys.txt
57+
name: sops-age
58+
subPath: keys.txt

0 commit comments

Comments
 (0)