Skip to content
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

Conversation

seh
Copy link
Contributor

@seh seh commented Apr 26, 2022

Rather than inspecting the source file name supplied to kustomize's Secret generator to determine the format of the SOPS-encrypted file content, instead inspect the Secret key—when supplied separately from the source file name—as a more reliable heuristic.

Doing so allows kustomization authors to name their SOPS-encrypted output files with a ".json" extension accurately reflecting the format in which SOPS writes its encrypted output, even if the encrypted content itself is not in JSON format.

See preceding discussion in the "flux" channel of the CNCF Slack workspace for the circuitous path I took to diagnose this change in behavior, with @hiddeco's help in pointing me to his recent #619 and suggesting the idea for the fix.

@@ -68,7 +67,6 @@ var (
k8sClient client.Client
testEnv *testenv.Environment
testServer *testserver.ArtifactServer
testEventsH kuberecorder.EventRecorder
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

staticcheck suggested that I remove this.

Comment on lines -1162 to +1172
g.Expect(bytes.Compare(f.data, b) == 0).To(Equal(f.expectData))
g.Expect(bytes.Equal(f.data, b)).To(Equal(f.expectData))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

staticcheck suggested this change.

@@ -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"},
Copy link
Contributor Author

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.

@seh seh force-pushed the revise-sops-format-detection-for-generated-secrets branch from 27d6f00 to b78b26e Compare April 26, 2022 14:58
seh added 3 commits April 26, 2022 11:07
Rather than inspecting the source file name supplied to kustomize's
Secret generator to determine the format of the SOPS-encrypted file
content, instead inspect the Secret key (when supplied separately from
the source file name) as a more reliable heuristic.

Doing so allows kustomization authors to name their SOPS-encrypted
output files with a ".json" extension accurately reflecting the format
in which SOPS writes its encrypted output, even if the encrypted
content itself is not in JSON format.

Signed-off-by: Steven E. Harris <seh@panix.com>
Signed-off-by: Steven E. Harris <seh@panix.com>
Signed-off-by: Steven E. Harris <seh@panix.com>
@seh seh force-pushed the revise-sops-format-detection-for-generated-secrets branch from b78b26e to e6beca1 Compare April 26, 2022 15:08
@hiddeco hiddeco added enhancement New feature or request area/sops SOPS related issues and pull requests labels Apr 26, 2022
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flawless execution of my instructions, and a big 💯 for the additional nit fixes. Thanks a lot @seh 🙇 🥇

@hiddeco hiddeco requested a review from stefanprodan April 27, 2022 08:29
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @seh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sops SOPS related issues and pull requests enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants