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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mozilla SOPS is all fun and games until someone has to fix a merge conflict in an encrypted file 馃槀 #1117

Open
m0un10 opened this issue Aug 29, 2022 · 7 comments

Comments

@m0un10
Copy link

m0un10 commented Aug 29, 2022

Any guidelines for handling this...

I can only think of two ways to prevent this...

  1. Do trunk-based dev, so that devs are discouraged from long running branches
  2. Use multiple files where possible to reduce the likelihood that two people will want to change the same file around the same time. e.g. don't have an uber sops file with all secrets in it, break it down to keep things that change for different reasons in different files

Actually fixing the conflict will (presumably) involve decrypting both versions followed by creating a new version that merges both changes. Probably quite a bit of faffing about to do this.

Probably fair to say, it's all an edge case that is only really caused by bad practices but one thing for sure, it is certainly painful fixing merge conflicts in SOPS files.

@renannprado
Copy link

One should rebase and modify the most up to date version before sending PR/merging.

@m0un10
Copy link
Author

m0un10 commented Aug 31, 2022

That's right. They would still need to fix the conflicts on their branch though and I don't think it would be able to be done like a conventional conflict fix. E.g. just editing the changes to select what to keep from theirs and mine will result in a broken file from a sops perspective.

@Enrico204
Copy link
Contributor

Maybe configuring git to show plaintext diff may be a solution? I never tried: https://github.com/mozilla/sops#showing-diffs-in-cleartext-in-git

@renannprado
Copy link

That's right. They would still need to fix the conflicts on their branch though and I don't think it would be able to be done like a conventional conflict fix. E.g. just editing the changes to select what to keep from theirs and mine will result in a broken file from a sops perspective.

There's no conflict when you edit & apply your changes on top of the newest version of the sops file.
It could be that there's a clever way of dealing with this, I'm not sure how much @Enrico204's suggestion helps, but IMHO this just seems more like a git basics question rather than sops question given that you can't modify sops file without the sops binary because it breaks the file.

@sochotnicky
Copy link

I think the problem that @m0un10 was trying to describe (and I've hit as well is following situation:

  • You create a new feature branch to add a new service etc in the process you modify sops file. You put it up for review let's say...
  • In the meantime a colleage is finished with their own change and their sops edits are merged into main branch
  • Now you have to rebase on top of their changes. The rebase fails since the file is encrypted

In those situations what I had to do was to manually reapply all my original changes. Which was a PITA. I had to copy my original edits elsewhere and then copy-paste them back onto the edited file. I suppose that is what the question is about - is there a nicer/recommended workflow for dealing with this situation.

@felixfontein
Copy link
Contributor

Git should already mostly merge the two encrypted files (assuming you didn't modify entries next to each other, then you'll have to fix them up manually, but that's not sops specific). The only problem are the conflicts for lastmodified and mac in the sops metadata. Simply pick one of the two values, decrypt the file with --ignore-mac, and re-encrypt. That should do the trick. That's still not perfect, but a lot better than manually re-applying changes :)

@sochotnicky
Copy link

Git should already mostly merge the two encrypted files (assuming you didn't modify entries next to each other, then you'll have to fix them up manually, but that's not sops specific). The only problem are the conflicts for lastmodified and mac in the sops metadata. Simply pick one of the two values, decrypt the file with --ignore-mac, and re-encrypt. That should do the trick. That's still not perfect, but a lot better than manually re-applying changes :)

Yeah, what you describe is what I meant as "manually reapplying". I suppose you are right that it's mostly just about removing the sops metadata pieces. The trouble was that the first time I encountered it, I didn't know about --ignore-mac switch. So took a bit of time.

I guess it should be possible to have a git hook that would detect this situation and auto-resolve it. Or perhaps better for sops to detect git conflict strings and offer to resolve them in the way you describe.

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

No branches or pull requests

5 participants