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

Sort masterkeys according to decryption-order #1345

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

bkreitch
Copy link
Contributor

@bkreitch bkreitch commented Nov 7, 2023

This is more generic way to address #305. As suggested in #305 (comment) and #305 (comment) it supports --decryption-order and SOPS_DECRYPTION_ORDER to specify the order in which decryption method are tried. Default order is age,pgp, so it covers functionality of #1121 too.

Couple of additional thoughts:

  • Sorting just indices as suggested in Sort masterkeys to try offline decrypt methods first #1121 (comment) together with priorities makes code a bit cryptic. Maybe using copy() to clone the group slice and sort the cloned slice could be acceptable alternative (since we don't modify the elements, but only the order)?
  • Passing DecryptionOrder through number of options and function calls is a bit cumbersome. Would it make sense to include DecryptionOrder and KeyServices together in a struct since they seem to be used mostly together?

@bkreitch bkreitch force-pushed the sort-decrypt-methods branch 9 times, most recently from cba9b72 to 0860e9d Compare November 8, 2023 08:45
@bkreitch bkreitch marked this pull request as ready for review November 8, 2023 09:12
cmd/sops/main.go Outdated Show resolved Hide resolved
Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Looks good on a very first glance!

sops_test.go Outdated Show resolved Hide resolved
@bkreitch bkreitch force-pushed the sort-decrypt-methods branch 2 times, most recently from 6e216ff to 896113e Compare November 13, 2023 07:09
@felixfontein
Copy link
Contributor

The failing sanity test will get fixed by #1350.

It's probably best to remove the changes from go.mod and go.sum to avoid conflicts.

@bkreitch
Copy link
Contributor Author

It's probably best to remove the changes from go.mod and go.sum to avoid conflicts.

@felixfontein Ok, sure, removed.

@bkreitch
Copy link
Contributor Author

It's probably best to remove the changes from go.mod and go.sum to avoid conflicts.

@felixfontein Looks like tests won't pass without committed changes to go.mod and go.sum

Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

I think this looks good! @getsops/maintainers what do you think?

cmd/sops/codes/codes.go Outdated Show resolved Hide resolved
@felixfontein
Copy link
Contributor

It's probably best to remove the changes from go.mod and go.sum to avoid conflicts.

@felixfontein Looks like tests won't pass without committed changes to go.mod and go.sum

I'm really confused why these are needed. 😕

@bkreitch
Copy link
Contributor Author

It's probably best to remove the changes from go.mod and go.sum to avoid conflicts.

@felixfontein Looks like tests won't pass without committed changes to go.mod and go.sum

I'm really confused why these are needed. 😕

@felixfontein For now I've just added a small function instead of importing "golang.org/x/exp/slices". Later with Go 1.21 it could be replaced with build-in "slices" package.

Copy link
Contributor

@Ph0tonic Ph0tonic left a comment

Choose a reason for hiding this comment

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

Juste a small misspell

README.rst Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
age/keysource.go Outdated Show resolved Hide resolved
age/keysource.go Outdated Show resolved Hide resolved
azkv/keysource.go Outdated Show resolved Hide resolved
cmd/sops/common/common.go Show resolved Hide resolved
gcpkms/keysource.go Outdated Show resolved Hide resolved
hcvault/keysource.go Outdated Show resolved Hide resolved
kms/keysource.go Outdated Show resolved Hide resolved
pgp/keysource.go Outdated Show resolved Hide resolved
sops.go Outdated
Comment on lines 62 to 66
var (
MasterKeyTypes = []string{"pgp", "gcp_kms", "hc_vault", "kms", "azure_kv", "age"}
SopsDecryptionOrderDefault = []string{"age", "pgp"}
)
Copy link
Member

Choose a reason for hiding this comment

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

Am really on the fence about this implementation detail. The problem I have with this introduction is that it worsens the scattering of string identifiers throughout the code base, and can easily be forgotten to be updated when a new key source is introduced.

The first solution to mitigate this that comes to mind would be to start making use of the identifier constants exposed in the key source implementation (as I suggested above), but this would cause the abstraction to further leak details as we would now have to import every key implementation within this module. Which isn't a great solution either.

Which makes me think we should either:

  1. Factor this out (but I have no suggestion on how to do this yet...).
  2. As a short-term solution, not maintain a list of all key types, but rather only sort based on what's provided (which means we can either rely on our own defaults with a limited set of identifiers, or rely on the user their input).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hiddeco I agree, this list is a bit problematic. I've updated the sort to rely only on provided list.

@bkreitch bkreitch force-pushed the sort-decrypt-methods branch 2 times, most recently from ec6de65 to 791ebe2 Compare December 16, 2023 12:02
@felixfontein
Copy link
Contributor

I think everything's good now (as good as it can get without solving the big issues @hiddeco mentioned, but these are out of scope for this PR). Except that now there's a conflict since I merged another PR. Sorry for that :( Should be pretty easy to resolve though...

cmd/sops/main.go Outdated Show resolved Hide resolved
gcpkms/keysource.go Outdated Show resolved Hide resolved
Co-authored-by: Gabriel Martinez <19713226+GMartinez-Sisti@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Bastien Wermeille <bastien.wermeille@gmail.com>
Co-authored-by: Hidde Beydals <hiddeco@users.noreply.github.com>
Signed-off-by: Boris Kreitchman <bkreitch@gmail.com>
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.

Thank you very much for your contribution @bkreitch. Made some small changes after looking at it for a 4th time, please let me know if you agree with them and I will merge 🙇

@bkreitch
Copy link
Contributor Author

Thank you very much for your contribution @bkreitch. Made some small changes after looking at it for a 4th time, please let me know if you agree with them and I will merge 🙇

@hiddeco Yep, sure, thanks :)

@hiddeco hiddeco merged commit a785bc9 into getsops:main Dec 18, 2023
10 checks passed
@bkreitch bkreitch deleted the sort-decrypt-methods branch December 18, 2023 09:29
@felixfontein
Copy link
Contributor

Thanks to everyone involved getting this ready and merged :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants