fix(initdata): split multi-cert PEM into one extra_root_certificates entry each#48
Merged
Merged
Conversation
…entry each generateCDHToml was putting the entire certPEM string (which may contain multiple PEM-encoded certificates from --cacert <multi-cert> or --capath <dir>) as a single extra_root_certificates array element. The validate command already enforced that each element must contain exactly one certificate. The create path now matches: it decodes the PEM block by block and appends each certificate as its own array entry. Before: extra_root_certificates = ["cert1\ncert2"] (combined, rejected by validate) After: extra_root_certificates = ["cert1", "cert2"] (one per element, accepted) Signed-off-by: Pradipta Banerjee <pradipta.banerjee@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR updates generateCDHToml to split a potentially multi-certificate PEM bundle into multiple cdh.toml image.extra_root_certificates entries (one certificate per array element), aligning initdata generation with what initdata validate enforces.
Changes:
- Decode the
caCertPEM block-by-block and append each block as a separateextra_root_certificatesentry instead of storing the entire PEM bundle as a single element. - Add
encoding/pemimport to support PEM block decoding/encoding duringcdh.tomlgeneration.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+228
to
+233
| // Split the PEM into one entry per certificate so that each element | ||
| // in extra_root_certificates contains exactly one certificate. | ||
| // This matches what initdata validate enforces. | ||
| var entries []string | ||
| rest := []byte(caCert) | ||
| for { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
generateCDHToml was putting the entire certPEM string (which may contain multiple PEM-encoded certificates from --cacert or --capath
) as a single extra_root_certificates array element.The validate command already enforced that each element must contain exactly one certificate. The create path now matches: it decodes the PEM block by block and appends each certificate as its own array entry.
Before: extra_root_certificates = ["cert1\ncert2"] (combined, rejected by validate)
After: extra_root_certificates = ["cert1", "cert2"] (one per element, accepted)