-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Secret generator keys for SOPS format hint #636
Merged
stefanprodan
merged 3 commits into
fluxcd:main
from
seh:revise-sops-format-detection-for-generated-secrets
Apr 27, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -695,7 +695,7 @@ func TestKustomizeDecryptor_DecryptResource(t *testing.T) { | |
}, | ||
} | ||
|
||
t.Run("SOPS encrypted resource", func(t *testing.T) { | ||
t.Run("SOPS-encrypted Secret resource", func(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
kus := kustomization.DeepCopy() | ||
|
@@ -736,7 +736,7 @@ func TestKustomizeDecryptor_DecryptResource(t *testing.T) { | |
g.Expect(got.MarshalJSON()).To(Equal(secretData)) | ||
}) | ||
|
||
t.Run("SOPS encrypted binary Secret data field", func(t *testing.T) { | ||
t.Run("SOPS-encrypted binary-format Secret data field", func(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
kus := kustomization.DeepCopy() | ||
|
@@ -771,7 +771,7 @@ func TestKustomizeDecryptor_DecryptResource(t *testing.T) { | |
g.Expect(got.GetDataMap()).To(HaveKeyWithValue("file.ini", base64.StdEncoding.EncodeToString(plainData))) | ||
}) | ||
|
||
t.Run("SOPS encrypted YAML Secret data field", func(t *testing.T) { | ||
t.Run("SOPS-encrypted YAML-format Secret data field", func(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
kus := kustomization.DeepCopy() | ||
|
@@ -849,12 +849,14 @@ func TestKustomizeDecryptor_DecryptResource(t *testing.T) { | |
|
||
func TestKustomizeDecryptor_decryptKustomizationEnvSources(t *testing.T) { | ||
type file struct { | ||
name string | ||
symlink string | ||
data []byte | ||
encrypt bool | ||
expectData bool | ||
name string | ||
symlink string | ||
data []byte | ||
originalFormat *formats.Format | ||
encrypt bool | ||
expectData bool | ||
} | ||
binaryFormat := formats.Binary | ||
tests := []struct { | ||
name string | ||
wordirSuffix string | ||
|
@@ -869,6 +871,9 @@ func TestKustomizeDecryptor_decryptKustomizationEnvSources(t *testing.T) { | |
path: "subdir", | ||
files: []file{ | ||
{name: "subdir/app.env", data: []byte("var1=value1\n"), encrypt: true, expectData: true}, | ||
// NB: Despite the file extension representing the SOPS-encrypted JSON output | ||
// format, the original data is plain text, or "binary." | ||
{name: "subdir/combination.json", data: []byte("The safe combination is ..."), originalFormat: &binaryFormat, encrypt: true, expectData: true}, | ||
{name: "subdir/file.txt", data: []byte("file"), encrypt: true, expectData: true}, | ||
{name: "secret.env", data: []byte("var2=value2\n"), encrypt: true, expectData: true}, | ||
}, | ||
|
@@ -877,13 +882,13 @@ func TestKustomizeDecryptor_decryptKustomizationEnvSources(t *testing.T) { | |
GeneratorArgs: kustypes.GeneratorArgs{ | ||
Name: "envSecret", | ||
KvPairSources: kustypes.KvPairSources{ | ||
FileSources: []string{"file.txt"}, | ||
EnvSources: []string{"app.env", "key=../secret.env"}, | ||
FileSources: []string{"file.txt", "combo=combination.json"}, | ||
EnvSources: []string{"app.env", "../secret.env"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectVisited: []string{"subdir/app.env", "subdir/file.txt", "secret.env"}, | ||
expectVisited: []string{"subdir/app.env", "subdir/combination.json", "subdir/file.txt", "secret.env"}, | ||
}, | ||
{ | ||
name: "decryption error", | ||
|
@@ -987,7 +992,12 @@ func TestKustomizeDecryptor_decryptKustomizationEnvSources(t *testing.T) { | |
} | ||
data := f.data | ||
if f.encrypt { | ||
format := formats.FormatForPath(f.name) | ||
var format formats.Format | ||
if f.originalFormat != nil { | ||
format = *f.originalFormat | ||
} else { | ||
format = formats.FormatForPath(f.name) | ||
} | ||
data, err = d.sopsEncryptWithFormat(sops.Metadata{ | ||
KeyGroups: []sops.KeyGroup{ | ||
{&sopsage.MasterKey{Recipient: id.Recipient().String()}}, | ||
|
@@ -1159,7 +1169,7 @@ func TestKustomizeDecryptor_decryptSopsFile(t *testing.T) { | |
|
||
b, err := os.ReadFile(filepath.Join(tmpDir, f.name)) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(bytes.Compare(f.data, b) == 0).To(Equal(f.expectData)) | ||
g.Expect(bytes.Equal(f.data, b)).To(Equal(f.expectData)) | ||
Comment on lines
-1162
to
+1172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. staticcheck suggested this change. |
||
} | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,6 @@ import ( | |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
kuberecorder "k8s.io/client-go/tools/record" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest" | ||
|
@@ -68,7 +67,6 @@ var ( | |
k8sClient client.Client | ||
testEnv *testenv.Environment | ||
testServer *testserver.ArtifactServer | ||
testEventsH kuberecorder.EventRecorder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. staticcheck suggested that I remove this. |
||
testMetricsH controller.Metrics | ||
ctx = ctrl.SetupSignalHandler() | ||
kubeConfig []byte | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that kustomize doesn't split the "EnvSources" field's values on an equals sign; it assumes that the whole value is always a file path.