-
Notifications
You must be signed in to change notification settings - Fork 174
ROX-25797: Central Scanner v4 communication #12448
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
3eec6b1
0591fc7
0f7af0b
1794013
49effb4
5d3d70f
02edb48
3aff078
05ef606
7462877
22aaa58
bf489c0
1a5c76b
6446bbb
c8b4712
f0aadf8
66a7a13
268826e
0626984
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 |
|---|---|---|
|
|
@@ -42,21 +42,31 @@ func isNodeIntegration(integration *storage.ImageIntegration) bool { | |
| return false | ||
| } | ||
|
|
||
| // imageIntegrationToNodeIntegration converts the given image integration into a node integration. | ||
| // Currently, only StackRox Scanner is a supported node integration. | ||
| // Assumes integration.GetCategories() includes storage.ImageIntegrationCategory_NODE. | ||
| func imageIntegrationToNodeIntegration(integration *storage.ImageIntegration) (*storage.NodeIntegration, error) { | ||
| if integration.GetType() != scannerTypes.Clairify { | ||
| return nil, errors.Errorf("requires a %s config: %q", scannerTypes.Clairify, integration.GetName()) | ||
| } | ||
| return &storage.NodeIntegration{ | ||
| // ImageIntegrationToNodeIntegration converts the given image integration into a node integration. | ||
| // Currently, only StackRox Scanner and Scanner v4 are supported node integrations. | ||
| // Assumes integration.GetCategories() includes storage.ImageIntegrationCategory_NODE_SCANNER. | ||
| func ImageIntegrationToNodeIntegration(integration *storage.ImageIntegration) (*storage.NodeIntegration, error) { | ||
| i := &storage.NodeIntegration{ | ||
|
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. we should do this after the |
||
| Id: integration.GetId(), | ||
| Name: integration.GetName(), | ||
| Type: integration.GetType(), | ||
| IntegrationConfig: &storage.NodeIntegration_Clairify{ | ||
| } | ||
|
|
||
| switch integration.GetType() { | ||
|
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. It's probably (hopefully) unlikely, but I guess it's possible |
||
| case scannerTypes.ScannerV4: | ||
| i.IntegrationConfig = &storage.NodeIntegration_Scannerv4{ | ||
| Scannerv4: integration.GetScannerV4(), | ||
| } | ||
| case scannerTypes.Clairify: | ||
| i.IntegrationConfig = &storage.NodeIntegration_Clairify{ | ||
| Clairify: integration.GetClairify(), | ||
| }, | ||
| }, nil | ||
| } | ||
| default: | ||
| return nil, errors.Errorf("unsupported integration type: %q.", integration.GetType()) | ||
| } | ||
| log.Debugf("Created Node Integration %s / %s from Image integration", i.GetName(), i.GetType()) | ||
|
|
||
| return i, nil | ||
| } | ||
|
|
||
| func imageIntegrationToOrchestratorIntegration(integration *storage.ImageIntegration) (*storage.OrchestratorIntegration, error) { | ||
|
|
@@ -83,7 +93,8 @@ func (m *managerImpl) Upsert(integration *storage.ImageIntegration) error { | |
| m.cveFetcher.RemoveIntegration(integration.GetId()) | ||
| return nil | ||
| } | ||
| nodeIntegration, err := imageIntegrationToNodeIntegration(integration) | ||
| log.Debugf("Converting Integration to Node: %s / %s", integration.GetName(), integration.GetType()) | ||
| nodeIntegration, err := ImageIntegrationToNodeIntegration(integration) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -92,6 +103,11 @@ func (m *managerImpl) Upsert(integration *storage.ImageIntegration) error { | |
| return err | ||
| } | ||
|
|
||
| if integration.GetType() == scannerTypes.ScannerV4 { | ||
| log.Debugf("Scanner v4 is not an orchestrator Scanner, exiting") | ||
vikin91 marked this conversation as resolved.
Show resolved
Hide resolved
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. Scanner V4 |
||
| return nil | ||
| } | ||
|
|
||
| orchestratorIntegration, err := imageIntegrationToOrchestratorIntegration(integration) | ||
| if err != nil { | ||
| return err | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package enrichment | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stackrox/rox/generated/storage" | ||
| "github.com/stackrox/rox/pkg/protoassert" | ||
| scannerTypes "github.com/stackrox/rox/pkg/scanners/types" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func Test_ImageIntegrationToNodeIntegration(t *testing.T) { | ||
| cases := map[string]struct { | ||
| in *storage.ImageIntegration | ||
| expected *storage.NodeIntegration | ||
| expectedErrorMsg string | ||
| }{ | ||
| "Valid v2": { | ||
| in: &storage.ImageIntegration{ | ||
| Id: "169b0d3f-8277-4900-bbce-1127077defae", | ||
| Name: "Stackrox Scanner", | ||
| Type: scannerTypes.Clairify, | ||
| Categories: []storage.ImageIntegrationCategory{ | ||
| storage.ImageIntegrationCategory_SCANNER, | ||
| storage.ImageIntegrationCategory_NODE_SCANNER, | ||
| }, | ||
| IntegrationConfig: &storage.ImageIntegration_Clairify{ | ||
| Clairify: &storage.ClairifyConfig{ | ||
| Endpoint: "https://localhost:8080", | ||
| }, | ||
| }, | ||
| }, | ||
| expected: &storage.NodeIntegration{ | ||
| Id: "169b0d3f-8277-4900-bbce-1127077defae", | ||
| Name: "Stackrox Scanner", | ||
| Type: scannerTypes.Clairify, | ||
| IntegrationConfig: &storage.NodeIntegration_Clairify{ | ||
| Clairify: &storage.ClairifyConfig{ | ||
| Endpoint: "https://localhost:8080", | ||
| }, | ||
| }, | ||
| }, | ||
| expectedErrorMsg: "", | ||
| }, | ||
| "Valid v4": { | ||
| in: &storage.ImageIntegration{ | ||
| Id: "a87471e6-9678-4e66-8348-91e302b6de07", | ||
| Name: "Scanner V4", | ||
| Type: scannerTypes.ScannerV4, | ||
| Categories: []storage.ImageIntegrationCategory{ | ||
| storage.ImageIntegrationCategory_SCANNER, | ||
| storage.ImageIntegrationCategory_NODE_SCANNER, | ||
| }, | ||
| IntegrationConfig: &storage.ImageIntegration_ScannerV4{ | ||
| ScannerV4: &storage.ScannerV4Config{ | ||
| IndexerEndpoint: "https://localhost:8443", | ||
| MatcherEndpoint: "https://localhost:9443", | ||
| }, | ||
| }, | ||
| }, | ||
| expected: &storage.NodeIntegration{ | ||
| Id: "a87471e6-9678-4e66-8348-91e302b6de07", | ||
| Name: "Scanner V4", | ||
| Type: scannerTypes.ScannerV4, | ||
| IntegrationConfig: &storage.NodeIntegration_Scannerv4{ | ||
| Scannerv4: &storage.ScannerV4Config{ | ||
| IndexerEndpoint: "https://localhost:8443", | ||
| MatcherEndpoint: "https://localhost:9443", | ||
| }, | ||
| }, | ||
| }, | ||
| expectedErrorMsg: "", | ||
| }, | ||
| "Invalid Scanner Type": { | ||
| in: &storage.ImageIntegration{ | ||
| Id: "a87471e6-0000-0000-0000-91e302b6de07", | ||
| Name: "Quay", | ||
| Type: scannerTypes.Quay, | ||
| }, | ||
| expectedErrorMsg: fmt.Sprintf("unsupported integration type: %q.", scannerTypes.Quay), | ||
| }, | ||
| } | ||
|
|
||
| for name, c := range cases { | ||
| t.Run(name, func(t *testing.T) { | ||
| actual, err := ImageIntegrationToNodeIntegration(c.in) | ||
|
|
||
| if c.expectedErrorMsg != "" { | ||
| assert.ErrorContains(t, err, c.expectedErrorMsg) | ||
| } else { | ||
| protoassert.Equal(t, c.expected, actual) | ||
| assert.NoError(t, err) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,9 +66,37 @@ func (p pipelineImpl) Run(ctx context.Context, clusterID string, msg *central.Ms | |
| log.Errorf("index report from node %s has unsupported action: %q", event.GetNode().GetName(), event.GetAction()) | ||
| return nil | ||
| } | ||
| log.Debugf("received node index report for node %s with %d packages from %d content sets", | ||
| event.GetId(), len(report.GetContents().Packages), len(report.GetContents().Repositories)) | ||
| log.Debugf("received node index report with %d packages from %d content sets for node %s", | ||
| len(report.GetContents().Packages), len(report.GetContents().Repositories), event.GetId()) | ||
| cr := report.CloneVT() | ||
|
|
||
| // Read the node from the database, if not found we fail. | ||
| node, found, err := p.nodeDatastore.GetNode(ctx, event.GetId()) | ||
|
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. the node's ID is the same as the event ID? Is that allowed? Is it possible to set the Index Report's "HashID" to the node's ID instead? |
||
| if err != nil { | ||
| return errors.WithMessagef(err, "fetching node: %s", event.GetId()) | ||
| } | ||
| if !found { | ||
| return errors.WithMessagef(err, "node does not exist: %s", event.GetId()) | ||
| } | ||
|
|
||
| // Send the Node and Index Report to Scanner for enrichment | ||
| err = p.enricher.EnrichNodeWithInventory(node, nil, cr) | ||
Maddosaurus marked this conversation as resolved.
Show resolved
Hide resolved
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. Perhaps for a followup: I'm thinking a separate function. We seem to replace Inventory with Index, so I'm thinking we should have a separate Index function, too. If underneath it stays the same, that's ok, as at least the interface would look a bit cleaner |
||
| if err != nil { | ||
| return errors.WithMessagef(err, "enriching node %s with index report", event.GetId()) | ||
| } | ||
| log.Infof("Successfully enriched node %s with index report.", node.GetName()) | ||
|
|
||
| // TODO(ROX-26089): Update the whole node in the database with the new and previous information after conversion | ||
vikin91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /* | ||
| err = p.riskManager.CalculateRiskAndUpsertNode(node) | ||
| if err != nil { | ||
| log.Error(err) | ||
| return err | ||
| } | ||
| */ | ||
|
|
||
| return nil | ||
|
|
||
| } | ||
|
|
||
| func (p pipelineImpl) Reconcile(_ context.Context, _ string, _ *reconciliation.StoreMap) error { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.