diff --git a/cautils/reportv2tov1.go b/cautils/reportv2tov1.go index 5b1562ed..9b006339 100644 --- a/cautils/reportv2tov1.go +++ b/cautils/reportv2tov1.go @@ -120,7 +120,12 @@ func controlReportV2ToV1(opaSessionObj *OPASessionObj, frameworkName string, con ruleResponse := reporthandling.RuleResponse{} ruleResponse.Rulename = rulev2.GetName() for i := range rulev2.Paths { - ruleResponse.FailedPaths = append(ruleResponse.FailedPaths, rulev2.Paths[i].FailedPath) + if rulev2.Paths[i].FailedPath != "" { + ruleResponse.FailedPaths = append(ruleResponse.FailedPaths, rulev2.Paths[i].FailedPath) + } + if rulev2.Paths[i].FixPath.Path != "" { + ruleResponse.FixPaths = append(ruleResponse.FixPaths, rulev2.Paths[i].FixPath) + } } ruleResponse.RuleStatus = string(status.Status()) if len(rulev2.Exception) > 0 { diff --git a/clihandler/initcli.go b/clihandler/initcli.go index c3ce60c7..d8b5aae4 100644 --- a/clihandler/initcli.go +++ b/clihandler/initcli.go @@ -5,6 +5,7 @@ import ( "io/fs" "os" + "github.com/armosec/armoapi-go/armotypes" "github.com/armosec/k8s-interface/k8sinterface" "github.com/armosec/kubescape/resultshandling/printer" printerv1 "github.com/armosec/kubescape/resultshandling/printer/v1" @@ -157,9 +158,21 @@ func ScanCliSetup(scanInfo *cautils.ScanInfo) error { } func Scan(policyHandler *policyhandler.PolicyHandler, scanInfo *cautils.ScanInfo) error { - policyNotification := &reporthandling.PolicyNotification{Rules: scanInfo.PolicyIdentifier} - if err := policyHandler.HandleNotificationRequest(policyNotification, scanInfo); err != nil { - return err + policyNotification := &reporthandling.PolicyNotification{ + Rules: scanInfo.PolicyIdentifier, + KubescapeNotification: reporthandling.KubescapeNotification{ + Designators: armotypes.PortalDesignator{}, + NotificationType: reporthandling.TypeExecPostureScan, + }, + } + switch policyNotification.KubescapeNotification.NotificationType { + case reporthandling.TypeExecPostureScan: + if err := policyHandler.HandleNotificationRequest(policyNotification, scanInfo); err != nil { + return err + } + + default: + return fmt.Errorf("notification type '%s' Unknown", policyNotification.KubescapeNotification.NotificationType) } return nil } diff --git a/go.mod b/go.mod index d226c90b..2e92db83 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/armosec/kubescape go 1.17 require ( - github.com/armosec/armoapi-go v0.0.41 + github.com/armosec/armoapi-go v0.0.49 github.com/armosec/k8s-interface v0.0.56 - github.com/armosec/opa-utils v0.0.105 + github.com/armosec/opa-utils v0.0.106 github.com/armosec/rbac-utils v0.0.12 github.com/armosec/utils-go v0.0.3 github.com/armosec/utils-k8s-go v0.0.1 @@ -37,6 +37,7 @@ require ( github.com/Azure/go-autorest/logger v0.2.1 // indirect github.com/Azure/go-autorest/tracing v0.6.0 // indirect github.com/OneOfOne/xxhash v1.2.8 // indirect + github.com/armosec/utils-k8s-go v0.0.1 // indirect github.com/armosec/armo-interfaces v0.0.3 // indirect github.com/aws/aws-sdk-go v1.41.11 // indirect github.com/coreos/go-oidc v2.2.1+incompatible // indirect diff --git a/go.sum b/go.sum index 0a6a0e4f..63b03775 100644 --- a/go.sum +++ b/go.sum @@ -83,20 +83,18 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/armosec/armo-interfaces v0.0.3 h1:kG4mJIPgWBJvQFDDy8JzdqX3ASbyl8t32IuJYqB31Pk= -github.com/armosec/armo-interfaces v0.0.3/go.mod h1:7XYefhcBCFYoF5LflCZHWuUHu+JrSJbmzk0zoNv2WlU= github.com/armosec/armoapi-go v0.0.2/go.mod h1:vIK17yoKbJRQyZXWWLe3AqfqCRITxW8qmSkApyq5xFs= github.com/armosec/armoapi-go v0.0.23/go.mod h1:iaVVGyc23QGGzAdv4n+szGQg3Rbpixn9yQTU3qWRpaw= -github.com/armosec/armoapi-go v0.0.41 h1:iMkaCsME+zhE6vnCOMaqfqc0cp7pste8QFHojeGKfGg= -github.com/armosec/armoapi-go v0.0.41/go.mod h1:exk1O3rK6V+X8SSyxc06lwb0j9ILQuKAoIdz9hs6Ndw= +github.com/armosec/armoapi-go v0.0.49 h1:b3gvZ5YB5DSEfk8pt7x0705b4Pcuahd3wI/ZmGYmB3Y= +github.com/armosec/armoapi-go v0.0.49/go.mod h1:iaVVGyc23QGGzAdv4n+szGQg3Rbpixn9yQTU3qWRpaw= github.com/armosec/k8s-interface v0.0.8/go.mod h1:xxS+V5QT3gVQTwZyAMMDrYLWGrfKOpiJ7Jfhfa0w9sM= github.com/armosec/k8s-interface v0.0.37/go.mod h1:vHxGWqD/uh6+GQb9Sqv7OGMs+Rvc2dsFVc0XtgRh1ZU= github.com/armosec/k8s-interface v0.0.50/go.mod h1:vHxGWqD/uh6+GQb9Sqv7OGMs+Rvc2dsFVc0XtgRh1ZU= github.com/armosec/k8s-interface v0.0.56 h1:7dOgc3qZaI7ReLRZcJa2JZKk0rliyYi05l1vuHc6gcE= github.com/armosec/k8s-interface v0.0.56/go.mod h1:vHxGWqD/uh6+GQb9Sqv7OGMs+Rvc2dsFVc0XtgRh1ZU= github.com/armosec/opa-utils v0.0.64/go.mod h1:6tQP8UDq2EvEfSqh8vrUdr/9QVSCG4sJfju1SXQOn4c= -github.com/armosec/opa-utils v0.0.105 h1:HQdP2LpFJtBoJpsfygh4IDXLLukIkQEuETOUePF/Zas= -github.com/armosec/opa-utils v0.0.105/go.mod h1:BNTjeianyXlflJMz3bZM0GimBWqmzirUf1whWR6Os04= +github.com/armosec/opa-utils v0.0.106 h1:YRKJ3hSwpAdTFbj2MUyo8MT9w6pDdzWYYTmov67Z8Bc= +github.com/armosec/opa-utils v0.0.106/go.mod h1:Wc1P4gkB6UQeGW8I76zCuitGGl15Omp0bKw7N0tR9dk= github.com/armosec/rbac-utils v0.0.1/go.mod h1:pQ8CBiij8kSKV7aeZm9FMvtZN28VgA7LZcYyTWimq40= github.com/armosec/rbac-utils v0.0.12 h1:uJpMGDyLAX129PrKHp6NPNB6lVRhE0OZIwV6ywzSDrs= github.com/armosec/rbac-utils v0.0.12/go.mod h1:Ex/IdGWhGv9HZq6Hs8N/ApzCKSIvpNe/ETqDfnuyah0= diff --git a/opaprocessor/processorhandler.go b/opaprocessor/processorhandler.go index e1a4d73c..599a4644 100644 --- a/opaprocessor/processorhandler.go +++ b/opaprocessor/processorhandler.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/armosec/armoapi-go/armotypes" "github.com/armosec/kubescape/cautils" ksscore "github.com/armosec/kubescape/score" "github.com/armosec/opa-utils/objectsenvelopes" @@ -204,7 +205,10 @@ func (opap *OPAProcessor) processRule(rule *reporthandling.PolicyRule) (map[stri ruleResult.Status = apis.StatusFailed for j := range ruleResponses[i].FailedPaths { - ruleResult.Paths = append(ruleResult.Paths, resourcesresults.Path{FailedPath: ruleResponses[i].FailedPaths[j]}) + ruleResult.Paths = append(ruleResult.Paths, armotypes.PosturePaths{FailedPath: ruleResponses[i].FailedPaths[j]}) + } + for j := range ruleResponses[i].FixPaths { + ruleResult.Paths = append(ruleResult.Paths, armotypes.PosturePaths{FixPath: ruleResponses[i].FixPaths[j]}) } resources[failedResources[j].GetID()] = ruleResult }