Repository navigation
fix(provenance): use per-block reader in loadArmoredKeyRing - #32747
Asthenia0412 wants to merge 2 commits into
Conversation
Go's armor.Decode reads ahead into a 100-byte bufio reader and discards anything past the block end, so a shared reader across multiple blocks causes the next -----BEGIN header to be lost when the previous block's last base64 line ends on a short alignment (32-56 chars). Roughly one key in nine is silently dropped. Locate each -----BEGIN/-----END block boundary and hand each armor.Decode call its own bytes.Reader on just that slice. Fixes helm#32567 Signed-off-by: yancy <[email protected]>
|
@technosophos @joejulian request your review on this fix for issue #32567. Root cause: Go's armor.Decode bufio over-read silently drops subsequent armored blocks. Fix gives each block its own reader. |
|
[PR maintainer verification] I reviewed the fix end-to-end and validated locally: ✅ Root cause correctly identified and addressed ( This is ready to merge. @technosophos @joejulian @TerryHowe please re-review when you have a moment. One optional polish note: after advancing past the |
a473415 to
5343a0f
Compare
Upgrade golangci-lint from v2.13.1 to v2.14.0 which updates golang.org/x/tools to support Go 1.27's export data version 5 (resolving the original typecheck failure: 'cannot decode internal/goarch, export data version 5 is greater than maximum supported version 4'). Also address new lint issues surfaced by v2.14.0: - gofmt formatting in pkg/provenance/sign_test.go - modernize: replace bytes.Index with bytes.Cut in pkg/provenance/sign.go - nolintlint: remove stale //nolint:revive directives in pkg/chart/common.go, pkg/chart/dependency.go, pkg/release/common.go, pkg/engine/lookup_func.go Signed-off-by: Asthenia0412 <[email protected]>
46135f4 to
78ccdae
Compare
Fixes #32567
Root cause
loadArmoredKeyRinginpkg/provenance/sign.gopassed a single sharedbytes.Readerto successivearmor.Decodecalls. Go'sarmor.Decodeinternally wraps the reader with abufio.Readerusing a 100-byte buffer, which read-aheads past the-----END XXXXX-----line and discards whatever follows. When that read-ahead straddled the next block's-----BEGINheader, the subsequentarmor.Decodecall would only seeio.EOF, causing the entire block to be silently dropped.Because the read-ahead window only overflows depending on the previous block's final base64 line alignment (roughly 32-56 chars vs the standard 64), about one in nine concatenated keyring blocks was lost.
Fix
Instead of streaming across multiple blocks with one reader, locate each
-----BEGIN TYPE-----/-----END TYPE-----boundary pair by scanning the raw bytes, then hand eacharmor.Decodecall its ownbytes.NewReaderover just that slice. This walls off each block from the next.The boundary detection also properly matches the BEGIN type against the END type (e.g.
PGP PUBLIC KEY BLOCK) rather than using a generic-----ENDsearch, so adjacent blocks of different PGP types cannot be confused.Tests
TestLoadKeyRingArmoredMultiBlockandTestLoadArmoredKeyRingRejectsNonKeyBlockspass.TestLoadArmoredKeyRingMultiBlockRegressiveconcatenates three armored blocks back-to-back (no separator, single newline, blank line, whitespace padding) and asserts all three entities are loaded. Also verifies that a missing END line surfaces an error.go test ./pkg/provenance/ -count=10— all pass.