Skip to content

comment_encryption: decouple comment encryption from value encryption - #2282

Closed
AnuchitO wants to merge 1 commit into
getsops:mainfrom
AnuchitO:feature/comment-encryption
Closed

comment_encryption: decouple comment encryption from value encryption#2282
AnuchitO wants to merge 1 commit into
getsops:mainfrom
AnuchitO:feature/comment-encryption

Conversation

@AnuchitO

Copy link
Copy Markdown

What

opt-in comment_encryption: plaintext|encrypted. controls comment encryption independent of value encryption. today comment encryption is always tied to whichever of the 6 existing selectors is active — no way to keep comments (e.g. inline docs like # required | default: db) readable while the value under them is encrypted, or vice versa.

How

  • Metadata.CommentEncryption + one guard in shouldBeEncrypted, comment nodes only, when set. value-node logic and the unset/default case untouched (backward compat)
  • combinable w/ the 4 value-only selectors (encrypted_regex/unencrypted_regex/encrypted_suffix/unencrypted_suffix); rejected w/ encrypted_comment_regex/unencrypted_comment_regex (both already decide comment encryption — combining is ambiguous). existing 6-selector mutual exclusion untouched
  • wired: config.go (.sops.yaml), stores.go (persisted in the file's own sops metadata, for correct decrypt/rotate), cmd/sops (--comment-encryption flag, ignored w/ warning on single-value stores like binary)
  • shared validation in sops.ValidateCommentEncryption, used by all 3 call sites instead of triplicating it

Tests

  • all 4 value/comment combinations, backward-compat guard (unset ⇒ byte-identical to today), config + file-metadata round-trip/validation, full 6-selector compatibility matrix
  • e2e verified w/ real age keys across dotenv/YAML/INI/JSON/binary

Note

found an unrelated pre-existing bug while testing (MAC mismatch decrypting a YAML/JSON sequence when encrypted_comment_regex actually encrypts a sequence comment — reproduces on main w/ zero involvement of this PR). filed separately as #2281, not touched here — flagging for visibility since it's in the same area of sops.go.

comment_encryption naming/values open to feedback.

opt-in creation_rule/CLI setting: comment_encryption: plaintext|encrypted. before: comment encryption always tied to whatever selector governed values, no way to keep comments readable while encrypting the value under them.

- shouldBeEncrypted: one guard, comment nodes only, when set. value logic + unset case untouched
- compatible w/ 4 value selectors; rejected w/ encrypted/unencrypted_comment_regex (both already control comments). 6-selector exclusion untouched
- wired: config.go (.sops.yaml), stores.go (persisted, for correct decrypt/rotate), cmd/sops (--comment-encryption flag, warn+ignore on binary)
- shared validation in sops.ValidateCommentEncryption, no triplication
- tests: all 4 value/comment combos, backward compat, config+store round-trip/validation, full 6-selector compat matrix
- verified e2e w/ real age keys: dotenv/yaml/ini/json/binary

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: AnuchitO <3372362+AnuchitO@users.noreply.github.com>
@AnuchitO

Copy link
Copy Markdown
Author

Closing to review before this goes to maintainers — will reopen or resubmit once I've gone through it myself.

@AnuchitO AnuchitO closed this Aug 24, 2026
@AnuchitO
AnuchitO deleted the feature/comment-encryption branch August 24, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants