Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

dotenv sops config variables do not maintain a specific order after editing #565

Closed
Jdban opened this issue Nov 5, 2019 · 1 comment · Fixed by #1101
Closed

dotenv sops config variables do not maintain a specific order after editing #565

Jdban opened this issue Nov 5, 2019 · 1 comment · Fixed by #1101

Comments

@Jdban
Copy link
Contributor

Jdban commented Nov 5, 2019

After modifying a dotenv file, the order of the sops config variables changes almost every time.

To replicate:
Encrypt a file:

$ sops test.env
# Write anything to this file and then save

File contents:

test=ENC[AES256_GCM,data:f8ibOw==,iv:/g2z6X6XcEwdxlZ5+HtgoP+wOaU9LTgoh9CM0avgk2c=,tag:ml0DeSfTOj51KSLJlumf3w==,type:str]
sops_gcp_kms__list_0__map_enc=CiQABebv2SYGzUmZgUmntqdHK6Fj5izjHlOxtQoJTM5GIqT4CdMSSAD88dFLDQcNkP5HkVpDlIdoTdpqV+A8MV2T3sGYEODtzKVONicytUo3MGoiUCe0kcbBrb2xnhM7Igr53dNQ+fyuxj8kEQEsbA==
sops_gcp_kms__list_0__map_resource_id=projects/asdassad/locations/global/keyRings/test/cryptoKeys/test
sops_mac=ENC[AES256_GCM,data:oo0NvabZUttruSC3HpVS3LJGmQoc9wQbK7EKZ2AhDgqT4jZbOBthHN9JAElEBndlu6Wo2V7kXPjMkFEa30sI5T1LRHhNV8rYAvtYzd7MeaVJCgdePRu/FD2z1J6JkX9/3xWMDCclHTWBjYuzPU6zf5edInLl8WVFKoJxIoBzJAs=,iv:Qdy4EofXViYGw6fIeM4GKAtaSWSvKi2xAQqOofGF9ck=,tag:3iG8CqYYf0yNtQqKBa0+Pg==,type:str]
sops_gcp_kms__list_0__map_created_at=2019-11-05T23:49:57Z
sops_unencrypted_suffix=_unencrypted
sops_version=3.4.0
sops_lastmodified=2019-11-05T23:50:09Z

Modify the file to something else and save.
File contents:

test=ENC[AES256_GCM,data:0m7DUFs=,iv:yQUpGKEReCirChGR0U2GY/RQMqoIECBRHEHH0Wr1q5c=,tag:tivZbpEQhO7OHlAHHFJryw==,type:str]
sops_mac=ENC[AES256_GCM,data:ztm2S6ZFWSxpyxRZ1bg9W7X1xArG+VkxRKrJ5cIgwT370sRpnYPX2xYh3RaoC74T49pd2VLgNs7EvlawObfRa7MtnH6nozHLp5hGxy1tOkphVRV4u3nRZudFt8c0ul7EU+N9irsZlEjFWw0qpqOBay20nhYi9Nj5c1zzkX1LpfE=,iv:Xm+N2fEaWdxV2ejc3b1OfK/eYab+NlQ+hTgjKp0qg70=,tag:x6d7Pfvkq/GUCvdVOr1hDQ==,type:str]
sops_gcp_kms__list_0__map_created_at=2019-11-05T23:49:57Z
sops_lastmodified=2019-11-05T23:51:31Z
sops_gcp_kms__list_0__map_enc=CiQABebv2SYGzUmZgUmntqdHK6Fj5izjHlOxtQoJTM5GIqT4CdMSSAD88dFLDQcNkP5HkVpDlIdoTdpqV+A8MV2T3sGYEODtzKVONicytUo3MGoiUCe0kcbBrb2xnhM7Igr53dNQ+fyuxj8kEQEsbA==
sops_gcp_kms__list_0__map_resource_id=projects/asdassad/locations/global/keyRings/test/cryptoKeys/test
sops_unencrypted_suffix=_unencrypted
sops_version=3.4.0

Notice that the sops config is not in the same order after modifying. They should be in the same order no matter how many times you modify and save the file.

Screenshot of diff:
image

I get that order doesn't matter in a dotenv file, but this is extremely annoying for diffs and defeats some of the purpose of sops.

@autrilla
Copy link
Contributor

autrilla commented Nov 6, 2019

I get that order doesn't matter in a dotenv file, but this is extremely annoying for diffs and defeats some of the purpose of sops.

I agree!

The cause is somewhat obvious:

https://github.com/mozilla/sops/blob/14a22d7a7060a0fba06c5dd716898d47728f0fce/stores/dotenv/store.go#L97

Maps are unsorted in Go. They could just be sorted alphabetically before and this issue should disappear.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
2 participants