-
Notifications
You must be signed in to change notification settings - Fork 172
ROX-12967: Replace fake NodeScan with real NodeInventory #3722
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
Changes from all commits
b42b7d4
939023b
f151bdd
09f9a66
cd61b51
99cff75
6047ea8
7d0c7fa
168814d
707eab2
963d4f2
39da733
cb77bec
17897d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package nodeinventorizer | ||
|
|
||
| import ( | ||
| timestamp "github.com/gogo/protobuf/types" | ||
| "github.com/stackrox/rox/generated/storage" | ||
| "github.com/stackrox/scanner/database" | ||
| scannerV1 "github.com/stackrox/scanner/generated/scanner/api/v1" | ||
| "github.com/stackrox/scanner/pkg/analyzer/nodes" | ||
| ) | ||
|
|
||
| // NodeInventorizer is the interface that defines the interface a scanner must implement | ||
| type NodeInventorizer interface { | ||
| Scan(nodeName string) (*storage.NodeInventory, error) | ||
| } | ||
|
|
||
| // NodeInventoryCollector is an implementation of NodeInventorizer | ||
| type NodeInventoryCollector struct { | ||
| } | ||
|
|
||
| // Scan scans the current node and returns the results as storage.NodeInventory object | ||
| func (n *NodeInventoryCollector) Scan(nodeName string) (*storage.NodeInventory, error) { | ||
| log.Info("Started node inventory") | ||
| // uncertifiedRHEL is set to false, as scans are only supported on RHCOS for now, | ||
| // which only exists in certified versions | ||
| componentsHost, err := nodes.Analyze(nodeName, "/host/", false) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also maybe comment why we use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, since we have a log to say when we finish, can we have a log to state when we start?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated the code, added a more detailed comment and update the loglevel |
||
| log.Info("Finished node inventory") | ||
| if err != nil { | ||
| log.Errorf("Error scanning node /host inventory: %v", err) | ||
| return nil, err | ||
| } | ||
| log.Debugf("Components found under /host: %v", componentsHost) | ||
|
|
||
| protoComponents := protoComponentsFromScanComponents(componentsHost) | ||
|
|
||
| m := &storage.NodeInventory{ | ||
| NodeName: nodeName, | ||
| ScanTime: timestamp.TimestampNow(), | ||
| Components: protoComponents, | ||
| } | ||
| return m, nil | ||
| } | ||
|
|
||
| func protoComponentsFromScanComponents(c *nodes.Components) *scannerV1.Components { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we discussed probably moving this inside the Scanner repo, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we did. I have created ROX-14029 to track this change for the future. Thank you for reminding me 👍 |
||
|
|
||
| if c == nil { | ||
| return nil | ||
| } | ||
|
|
||
| // For now, we only care about RHEL components, but this must be extended once we support non-RHCOS | ||
| rhelComponents := convertRHELComponents(c.CertifiedRHELComponents) | ||
|
|
||
| protoComponents := &scannerV1.Components{ | ||
| Namespace: c.OSNamespace.Name, | ||
| OsComponents: nil, | ||
| RhelComponents: rhelComponents, | ||
| LanguageComponents: nil, | ||
| } | ||
| return protoComponents | ||
| } | ||
|
|
||
| func convertRHELComponents(rc *database.RHELv2Components) []*scannerV1.RHELComponent { | ||
| if rc == nil || rc.Packages == nil { | ||
| log.Warn("No RHEL packages found in scan result") | ||
| return nil | ||
| } | ||
| v1rhelc := make([]*scannerV1.RHELComponent, 0, len(rc.Packages)) | ||
| for _, rhelc := range rc.Packages { | ||
| v1rhelc = append(v1rhelc, &scannerV1.RHELComponent{ | ||
| // TODO(ROX-13936): Find out if ID field is needed here | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: We need a unique ID here. For now, use loop index. More information: https://srox.slack.com/archives/C04213W844U/p1667825859123589 |
||
| Name: rhelc.Name, | ||
| Namespace: rc.Dist, | ||
| Version: rhelc.Version, | ||
| Arch: rhelc.Arch, | ||
| Module: rhelc.Module, | ||
| Cpes: rc.CPEs, | ||
| Executables: rhelc.Executables, | ||
| }) | ||
| } | ||
| return v1rhelc | ||
| } | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,8 @@ RUN ln -s entrypoint-wrapper.sh /stackrox/admission-control && \ | |
| microdnf clean all && \ | ||
| rm /tmp/snappy.rpm /tmp/postgres.rpm /tmp/postgres-libs.rpm RPM-GPG-KEY-CentOS-Official && \ | ||
| # (Optional) Remove line below to keep package management utilities | ||
| rpm -e --nodeps $(rpm -qa curl '*rpm*' '*dnf*' '*libsolv*' '*hawkey*' 'yum*') && \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing this here? (I am not sure what this file does, that is why I am asking)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the spot where we remove all package managers from the main image.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, now I recall. We remove it from the removal code, so in fact we are keeping the package. All good
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Due to a lack of a follow-up
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Customers may ask about this (someone asked why Scanner still has it). Perhaps we should consider updating the docs or CHANGELOG? Definitely need to also make sure our default policy which allows Scanner to have RPM also allows our other images have it. Perhaps a followup ticket, find a way to do this without rpm (eh. I wanted to remove it in Scanner, but it's the only official way to get rpmdb data), or perhaps use a separate Dockerfile for Compliance, so we minimize the number images with rpm installed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have created a follow up ticket (ROX-13934) so we don't forget about it and will push this as a TODO comment. |
||
| # TODO(ROX-13934): Potentially add *RPM* to this list again | ||
| rpm -e --nodeps $(rpm -qa curl '*dnf*' '*libsolv*' '*hawkey*' 'yum*') && \ | ||
| rm -rf /var/cache/dnf /var/cache/yum && \ | ||
| # The contents of paths mounted as emptyDir volumes in Kubernetes are saved | ||
| # by the script `save-dir-contents` during the image build. The directory | ||
|
|
||
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.
How come we changed the name from
NodeScanner? I figure if we define aScanfunction,NodeScannermakes sense. I don't thinkInventorizeris a word, so I'm a bit skeptical using it to name this interfaceThere 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 originally planned this as
NodeScanning V2, but later changed it toNodeInventory, to improve separation, because the changes were rather confusing, asNodeScanningis already used in multiple places in the codebase.I decided to reflect these changes in the implementation as well, to make it more clear we're talking about a
NodeInventoryand not the already existingNodeScan.I concur that the name doesn't feel common, as it's a nonstandard word.
I'd be happy to consider alternatives, because I currently don't know how we could call it otherwise (except reverting back to NodeScanner, which would also be an option). WDYT?