-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
osbuild: new stage 'cacert' (HMS-4839) #907
Conversation
pkg/manifest/os.go
Outdated
if len(p.CACerts) > 0 { | ||
for _, cc := range p.CACerts { | ||
for _, c := range parseCerts(cc) { | ||
path := filepath.Join("/etc/pki/ca-trust/source/anchors", filepath.Base(c.SerialNumber.Text(16))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the filename extension, will add during review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we break down this PR into multiple commits for easier reviewing and history?
I like to have commits that introduce new things separate from the following ones that use them, so maybe:
- Add
osbuild/..._stage.go
- Add
manifest/os.go
changes. - Add blueprint customization.
- Add config option to
all-customizations.json
.
(though, 2 and 3 can be merged).
pkg/blueprint/customizations.go
Outdated
@@ -32,6 +32,7 @@ type Customizations struct { | |||
Installer *InstallerCustomization `json:"installer,omitempty" toml:"installer,omitempty"` | |||
RPM *RPMCustomization `json:"rpm,omitempty" toml:"rpm,omitempty"` | |||
RHSM *RHSMCustomization `json:"rhsm,omitempty" toml:"rhsm,omitempty"` | |||
CA *CACustomization `json:"ca,omitempty" toml:"ca,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ca
, while an accurate initialism and probably a very common term to refer to what we're doing, is probably not a great name for a configuration key in the soup of top-level blueprint customization names.
CertificateAuthority
(certificate-authority
) is, on the other hand, too long.
Maybe CACerts
(toml:"ca-certs"
) would be a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, in the same struct I see a two-worded JSON field SSHKey as sshkey
so I will stick with this theme and go for cacerts
.
test/configs/all-customizations.json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UrDjSHpxVT2LxFy7ofRrLYIezFDUYfb920VkkV\nSVcxh1YDFROJalfMoE6wdyR/LnK4MJZS9fUpeCJJc/A0J+9FK9CwcyUrHgJ8XbJh\nMKYyQ+cf6O7wzutuBpMyRqSKS+hVM7BQTmSFvv1eAJlo6klGAmmKiYmAEvcQadH1\ndjrujsA3Cn5vX2L+0yuiLB5/zoxqx5cEy97TuKUYB8OqMMujAXNzF4L3HJDUNba2\nAhEkFozMXwYX73TGbGZ0mawPS5D3v3tYTEmJFf6SnVCmUW1fs57g\n-----END CERTIFICATE-----\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't match the customization struct in the code. The way the customization is written now this should be:
"ca": {
"certs": [
"..."
]
}
pkg/osbuild/cacert_stage.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stage is called pki.update-ca-trust
so please name the file accordingly for easier navigation.
pki_update_stage.go
for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we break down this PR into multiple commits for easier reviewing and history?
I like to have commits that introduce new things separate from the following ones that use them, so maybe:
- Add
osbuild/..._stage.go
- Add
manifest/os.go
changes. - Add blueprint customization.
- Add config option to
all-customizations.json
.
(though, 2 and 3 can be merged).
Sure, amended all remarks. If you don’t mind, I am keeping one commit for easier work from my side, multiple commits rebasing is a pain to work with this isn’t a big PR by any means. I will split it after the code is ready. |
This PR is stale because it has been open 30 days with no activity. Remove "Stale" label or comment or this will be closed in 7 days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR! It looks good but I still have some ideas/suggestions inline for your consideration. But I'm happy to help with them if you have no enough time :)
I have extracted the checking code + test into separate package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update, looks very nice now, I made a suggestion inline, hope it's useful.
pkg/manifest/os.go
Outdated
@@ -822,6 +826,25 @@ func (p *OS) serialize() osbuild.Pipeline { | |||
} | |||
} | |||
|
|||
if len(p.CACerts) > 0 { | |||
for _, cc := range p.CACerts { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to see a test for this but I understand this area is really difficult to test so fine to ignore that (but I also can't help to mention it)
Amended the recommended changes, fixed tests. Let me know where and how to add a test for this. REMINDER: For myself - the commit should be split as requested. |
7554a32
to
87a5bef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good now from my PoV, one tiny suggestion about a test.
5aec771
to
f77ce5d
Compare
Rebased, hopefully it passes now. |
Any other comments? I would love to get this in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel too strongly about extracting the two lines into a function but the stage should be moved so that it's before the selinux one.
pkg/manifest/os.go
Outdated
for _, c := range certs { | ||
path := filepath.Join("/etc/pki/ca-trust/source/anchors", filepath.Base(c.SerialNumber.Text(16))+".pem") | ||
f, err := fsnode.NewFile(path, nil, "root", "root", pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: c.Raw})) | ||
if err != nil { | ||
panic(err) | ||
} | ||
pipeline.AddStages(osbuild.GenFileNodesStages([]*fsnode.File{f})...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth extracting this into a helper function, just for easier reading?
pkg/manifest/os.go
Outdated
if len(p.CACerts) > 0 { | ||
for _, cc := range p.CACerts { | ||
certs, err := cert.ParseCerts(cc) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to parse CA certificates: %v", err)) | ||
} | ||
|
||
for _, c := range certs { | ||
path := filepath.Join("/etc/pki/ca-trust/source/anchors", filepath.Base(c.SerialNumber.Text(16))+".pem") | ||
f, err := fsnode.NewFile(path, nil, "root", "root", pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: c.Raw})) | ||
if err != nil { | ||
panic(err) | ||
} | ||
pipeline.AddStages(osbuild.GenFileNodesStages([]*fsnode.File{f})...) | ||
} | ||
} | ||
pipeline.AddStage(osbuild.NewCAStageStage()) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this whole block up before the selinux stage is added (L798), so that any newly created files get labelled correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that is an excellent catch - thank you! Is there any way (not here probably) how we could detect this via tests (assuming we had a bit more test infra for manifest/os.go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, yeah.
I think the MTLS change kicked in and now breaking tests I need to fix this prior this PR:
|
Moved, also I think I have found a good place for the CA file nodes code. |
Thanks, that was helpful. It now generates fine. |
It looks like it works fine:
|
ef85d5b
to
fb83fd4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This looks fine, I have some inline suggestions but no blockers, this seems all fine now. Thanks also for splitting it up.
for _, cc := range p.CACerts { | ||
files, err := osbuild.NewCAFileNodes(cc) | ||
if err != nil { | ||
panic(err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(super nitpick) panic(err)
would also work (and is slightly shorter)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a pattern in the whole file, I would rather not change it in this PR.
@@ -226,6 +226,14 @@ func osCustomizations( | |||
osc.Files = append(osc.Files, imageConfig.Files...) | |||
osc.Directories = append(osc.Directories, imageConfig.Directories...) | |||
|
|||
ca, err := c.GetCACerts() | |||
if err != nil { | |||
panic(fmt.Sprintf("unexpected error checking CA certs: %v", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I am not sure we should panic here, I see we do this a lot in this function whichI find confusing given that we have an error return here and that the certs come from the user so they maybe wrong and panic() seems a bit heavy handed for user inputs. But we can tweak in a followup given the rest of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Forgot to run |
Holidays, all the remarks were solved.
This pull request adds a new stage called 'cacert' to the osbuild package. It also includes file changes to support the CACustomization feature, which allows users to specify a list of certificates for the CA (Certificate Authority). The changes include updates to the Customizations struct, the osCustomizations function, and the OSCustomizations struct. Additionally, a new function called parseCerts is added to parse the certificate strings. The changes also include updates to the serialize and prependKernelCmdlineStage functions in the OS struct. Finally, a new file called ca_stage.go is added to the osbuild package, which contains the implementation of the NewCAStageStage function.
Needs: osbuild/osbuild#1854