Skip to content

Commit a6e3e44

Browse files
committed
Fixing remote patches decryption
1 parent a8c7cc1 commit a6e3e44

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

internal/decryptor/decryptor.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"errors"
2424
"fmt"
2525
"io/fs"
26+
"net/url"
2627
"os"
2728
"path/filepath"
2829
"strings"
@@ -571,10 +572,20 @@ func (d *Decryptor) decryptKustomizationSources(visited map[string]struct{}) vis
571572
if patch.Path == "" {
572573
continue
573574
}
575+
576+
u, err := url.Parse(patch.Path)
577+
if err != nil {
578+
return err
579+
}
580+
581+
if u.IsAbs() {
582+
continue
583+
}
584+
574585
// Determine the format for the patch, defaulting to YAML if not specified.
575586
format := formatForPath(patch.Path)
576587
// Visit the patch reference and attempt to decrypt it.
577-
if err := visitRef(patch.Path, format); err != nil {
588+
if err = visitRef(patch.Path, format); err != nil {
578589
return err
579590
}
580591
}

internal/decryptor/decryptor_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ func TestDecryptor_decryptKustomizationSources(t *testing.T) {
818818
wordirSuffix string
819819
path string
820820
files []file
821+
patch []kustypes.Patch
821822
secretGenerator []kustypes.SecretArgs
822823
expectVisited []string
823824
wantErr error
@@ -922,6 +923,34 @@ func TestDecryptor_decryptKustomizationSources(t *testing.T) {
922923
wantErr: &fs.PathError{Op: "lstat", Path: "data.env", Err: fmt.Errorf("")},
923924
expectVisited: []string{},
924925
},
926+
{
927+
name: "ignore remote patches",
928+
path: "subdir",
929+
files: []file{
930+
{name: "subdir/file.txt", data: []byte("file"), encrypt: true, expectData: true},
931+
{name: "subdir/patch.yaml", data: []byte("op: add\n"), encrypt: true, expectData: true},
932+
},
933+
patch: []kustypes.Patch{
934+
{
935+
Path: "patch.yaml",
936+
},
937+
{
938+
// this patch gets ignored due to being remote
939+
Path: "https:/raw.githubusercontent.com/kubernetes-sigs/kustomize/master/examples/wordpress/patch.yaml",
940+
},
941+
},
942+
secretGenerator: []kustypes.SecretArgs{
943+
{
944+
GeneratorArgs: kustypes.GeneratorArgs{
945+
Name: "envSecret",
946+
KvPairSources: kustypes.KvPairSources{
947+
FileSources: []string{"file.txt"},
948+
},
949+
},
950+
},
951+
},
952+
expectVisited: []string{"subdir/patch.yaml", "subdir/file.txt"},
953+
},
925954
}
926955
for _, tt := range tests {
927956
t.Run(tt.name, func(t *testing.T) {
@@ -967,7 +996,10 @@ func TestDecryptor_decryptKustomizationSources(t *testing.T) {
967996

968997
visited := make(map[string]struct{}, 0)
969998
visit := d.decryptKustomizationSources(visited)
970-
kus := &kustypes.Kustomization{SecretGenerator: tt.secretGenerator}
999+
kus := &kustypes.Kustomization{
1000+
Patches: tt.patch,
1001+
SecretGenerator: tt.secretGenerator,
1002+
}
9711003

9721004
err = visit(root, tt.path, kus)
9731005
if tt.wantErr == nil {

0 commit comments

Comments
 (0)