Skip to content

Commit 29080cb

Browse files
authored
Merge pull request #1283 from vlasov-y/main
Enable decryption of secrets generated by Kustomize components
2 parents d7bad03 + 681573b commit 29080cb

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

internal/controller/kustomization_decryptor_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ func TestKustomizationReconciler_Decryptor(t *testing.T) {
200200
g.Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: "sops-year2", Namespace: id}, &year2Secret)).To(Succeed())
201201
g.Expect(string(year2Secret.Data["year"])).To(Equal("year2"))
202202

203+
var year3Secret corev1.Secret
204+
g.Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: "sops-year3", Namespace: id}, &year3Secret)).To(Succeed())
205+
g.Expect(string(year3Secret.Data["year"])).To(Equal("year3"))
206+
203207
var encodedSecret corev1.Secret
204208
g.Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: "sops-month", Namespace: id}, &encodedSecret)).To(Succeed())
205209
g.Expect(string(encodedSecret.Data["month.yaml"])).To(Equal("month: May\n"))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kustomize.config.k8s.io/v1alpha1
2+
kind: Component
3+
secretGenerator:
4+
- name: sops-year3
5+
envs:
6+
- year3.env
7+
generatorOptions:
8+
disableNameSuffixHash: true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
year=ENC[AES256_GCM,data:c+S7GjA=,iv:bcYeALfyGDWlXi5UqOFVC2tCdex5MXaJKxn6awDIfAI=,tag:UQepDih41dSSUiebFYNxiw==,type:str]
2+
sops_age__list_0__map_enc=-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA4L01FcTR6dVpPR1JpNldW\nSURuaHBEZ3RrY1hpS1Mxam10VEhVSE85RG5NClFTZHEvQzBnbjVHK3VydEIxVkZE\ncEI0a1hVMmtVSXZjNU5VQXBVV2RIS0UKLS0tIEZlUndyWEVZZUl1bHI0a3JwS2M1\nQnNNcFZxaTNzWlZoSFRpdWd2QUJjNGcKzEaQDRjvnFPkwCXL6K5s5guI5xP0urcD\nfeYHuyAS9Td0l/5fTyDlLv6jFJ09QS1ob0OL0GAvknwjbRlbaWjrAA==\n-----END AGE ENCRYPTED FILE-----\n
3+
sops_age__list_0__map_recipient=age1l44xcng8dqj32nlv6d930qvvrny05hglzcv9qpc7kxjc6902ma4qufys29
4+
sops_lastmodified=2024-11-10T18:49:59Z
5+
sops_mac=ENC[AES256_GCM,data:jeyF+D6Y5tGtcaxWfK65PlbjZLicI1lFi0uEcEq2fLVv9vPCpSO/iAfGGOqQiMPbndAV7FdqeFCSXC4gmf27gysR3FvHnYrbLZDO+fZm5K6Fk2IReSCZIHLxVGUlC9E5z1NFfPjJdD3fMM5I6sT7Cpn6xCg/rHavmfOEwW2dU94=,iv:kgxhX2NhFEmgfbOD7FpiXI+WXXZrpzf7R8r1RMSPPjs=,tag:aHge+qF1wsAszeTL25HtBw==,type:str]
6+
sops_unencrypted_suffix=_unencrypted
7+
sops_version=3.9.0

internal/controller/testdata/test-dotenv/overlays/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ secretGenerator:
88
- year1.env
99
generatorOptions:
1010
disableNameSuffixHash: true
11+
components:
12+
- component

internal/decryptor/decryptor.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,13 @@ func recurseKustomizationFiles(root, path string, visit visitKustomization, visi
697697
return err
698698
}
699699

700+
// Components may contain resources as well, ...
701+
// ...so we have to process both .resources and .components values
702+
resources := append(kus.Resources, kus.Components...)
703+
700704
// Recurse over other resources in Kustomization,
701705
// repeating the above logic per item
702-
for _, res := range kus.Resources {
706+
for _, res := range resources {
703707
if !filepath.IsAbs(res) {
704708
res = filepath.Join(path, res)
705709
}

0 commit comments

Comments
 (0)