Repository navigation
Is it possible to check the MAC of an encrypted file without being able to decrypt it? #2275
|
Hi y'all! I recently botched up one of my files by changing an unencrypted value. I keep these values unencrypted, since it can be helpful to our 24/7 teams to be able to understand e.g. which component is talking to which other component and which hostname is used precisely. Since I already do an automatic integrity check of great portions of the other repo content before commit (as part of the pre-commit hook) I was wondering if there is a way to verify the MAC without decrypting the file. The caveat of "without being able to decrypt the file" comes from the point, that the 24/7 team is allowed to make trivial changes (to the rest of the repo), but are not allowed to know all the secrets stored in the file. So the pre-commit hook runs a verification so errors are caught before actually committing them, but for maybe 30% of the changes there is no secret around that would allow decryption. Best regards, PS: I'm aware that my particular problem could have been prevented by omitting cleartext values from the MAC, but I would like to prevent accidental changes in unencrypted values as well (we store certificates in plaintext and only encrypt the private key, so if someone would generate a new cert and write it to the file, they would be unable to update the private key, and might simply skip this step - causing the keypair to mismatch. In this case the MAC failure would prevent them from making any change.) |
Replies: 1 comment 1 reply
|
No—not cryptographically with current SOPS. The component verifying the MAC must be able to recover the file's data key, which also gives it the capability to decrypt the secrets.
Because
For an actual integrity check, run normal decryption in a tightly scoped CI job that has the key and discard the output: if ! sops decrypt "$file" >/dev/null; then
echo "SOPS decryption/integrity check failed: $file" >&2
exit 1
fiDo not pass For machines that intentionally have no key, the safe pre-commit rule is policy rather than verification. If those operators should only edit the rest of the repository, reject a staged change to the SOPS file: if ! git diff --cached --quiet -- path/to/secrets.enc.yaml; then
echo "secrets.enc.yaml must be changed via the key-bearing SOPS workflow" >&2
exit 1
fiThat catches this accidental If no-key users must legitimately edit the cleartext fields, the choices are the trade-off you already identified— This matches the project's earlier guidance for the same constraint: the whole-file MAC is an intentional integrity boundary, so editing protected cleartext without access to update/verify it requires changing the document or trust boundary, not another SOPS flag. |
No—not cryptographically with current SOPS. The component verifying the MAC must be able to recover the file's data key, which also gives it the capability to decrypt the secrets.
sops.macis not a public-key signature. The verification path is:sops.macwith that data key;Because
mac_only_encryptedis false in your intended setup, the cleartext hostname/certificate values are included in that hash too. That is why the rawvimedit becomes a MAC mismatch—but detecting that mismatch requires the key.sops filestatusdoes not help here: it on…