fix(decrypt): ensure decrypted file ends with newline to prevent last multiline value truncation#730
Conversation
… multiline value truncation Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
|
I would like to have this covered by an test. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #730 +/- ##
==========================================
+ Coverage 87.00% 87.03% +0.03%
==========================================
Files 22 22
Lines 862 864 +2
==========================================
+ Hits 750 752 +2
Misses 112 112 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ne branch Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
|
Added a bats test in commit 830b9ad ( |
…case indentation Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
|
Hi @jkroepke 👋 — just a gentle ping on this PR. All checks are passing, there are no conflicts with |
|
I tries this PR and I'm the same issue as I had in #715. All tests are green, which looks great. However, if I remove your code from decrypt.sh, all tests are still green, including the new one. Basicly, I'm looking for a test case which fails without adding new code and is green with new code fragment. |
Adds a new BATS test "decrypt: inline decrypt appends trailing newline when backend omits it" that uses helm-secrets' custom backend API to inject a mock backend. The mock's _custom_backend_decrypt_file writes content without a trailing newline, precisely simulating the sops --output stripping bug. Without the printf '\n' fix in decrypt_helper, this test fails (red). With the fix it passes (green). This addresses jkroepke's request for a proper red/green test. Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
|
Hi @jkroepke — you're right, the previous test didn't fail without the fix. I've addressed this in commit 00cddab with a new test:
The key insight: the existing fixture ( _custom_backend_decrypt_file() {
# Intentionally omit the trailing newline — simulating the sops --output bug
printf 'global_secret: value_without_trailing_newline' > "${3}"
}This mock is sourced by run sh -c "tail -c1 '${mock_file}' | wc -l | tr -d ' '"
assert_output "1"Without the Happy to adjust anything — thanks for the thorough review! |
|
Hey @jkroepke — just a friendly ping! The branch is up to date and the red/green test has been updated to use a mock backend that deterministically reproduces the missing-newline bug. Would love your review when you have a moment. Thanks! 🙏 |
Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
|
Hi @jkroepke — just a gentle follow-up. The red/green test you flagged on Apr 1 was addressed in commit 00cddab: the new test uses a mock backend that deterministically omits the trailing newline, so it fails without the fix and passes with it. All 21 CI checks are green. Could you take another look when you have a moment? Happy to adjust anything if needed! |
|
Hi @jkroepke — just a gentle weekly ping! CI is green and there are no conflicts. Happy to make any adjustments if you have further feedback. 🙏 |
Fixes #714
Root cause
When
HELM_SECRETS_WRAPPER_ENABLED=truethe wrapper path callsdecrypt_helperwithout the"stdout"argument, sobackend_decrypt_fileinvokes sops with--output <file>. In certain sops versions, when the last YAML value is a block scalar (multi-line string), the trailing newline is omitted from the--outputfile path but is correctly preserved when writing to stdout.The
secrets://downloader path is unaffected because it callsdecrypt_helper ... "stdout", which pipes sops output directly to stdout (preserving the newline).The missing newline causes YAML parsers to see the last multiline value as truncated — stripping the final newline that was present in the original secret — producing a different value than the
secrets://path returns.Fix
After
backend_decrypt_filewrites the decrypted file, check whether it ends with a newline using the POSIX-portabletail -c1 | wc -lidiom (returns 0 when the last byte is not\n), and append\nif needed. The guard is:printf '\n'instead ofechofor POSIX portabilityTesting
Reproduce with a YAML secret file whose last value is a block scalar:
Encrypt it with sops, then decrypt via the wrapper path (
helm secrets template ...) and verify the last line ofmy-certis not truncated.