-
Notifications
You must be signed in to change notification settings - Fork 29
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
Rapidast on rhwa FAR operator #310
base: main
Are you sure you want to change the base?
Changes from all commits
a3b48ad
c9b7101
9b7e579
7ab7ced
98e6e72
47b2202
45c39b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package tests | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/openshift-kni/eco-goinfra/pkg/deployment" | ||
"github.com/openshift-kni/eco-goinfra/pkg/reportxml" | ||
|
||
"github.com/openshift-kni/eco-gotests/tests/rhwa/far-operator/internal/farparams" | ||
rapidast "github.com/openshift-kni/eco-gotests/tests/rhwa/internal/rapidast" | ||
. "github.com/openshift-kni/eco-gotests/tests/rhwa/internal/rhwainittools" | ||
"github.com/openshift-kni/eco-gotests/tests/rhwa/internal/rhwaparams" | ||
) | ||
|
||
var _ = Describe( | ||
"FAR Post Deployment tests", | ||
Ordered, | ||
ContinueOnFailure, | ||
Label(farparams.Label), Label("dast"), func() { | ||
BeforeAll(func() { | ||
By("Get FAR deployment object") | ||
farDeployment, err := deployment.Pull( | ||
APIClient, farparams.OperatorDeploymentName, rhwaparams.RhwaOperatorNs) | ||
Expect(err).ToNot(HaveOccurred(), "Failed to get FAR deployment") | ||
|
||
By("Verify FAR deployment is Ready") | ||
Expect(farDeployment.IsReady(rhwaparams.DefaultTimeout)).To(BeTrue(), "FAR deployment is not Ready") | ||
}) | ||
|
||
It("Verify FAR Operator passes trivy scan without vulnerabilities", reportxml.ID("76877"), func() { | ||
|
||
By("Creating rapidast pod") | ||
dastTestPod := rapidast.PrepareRapidastPod(APIClient) | ||
|
||
output, err := rapidast.RunRapidastScan(*dastTestPod, rhwaparams.RhwaOperatorNs) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
By("Checking vulnerability scan results") | ||
var parsableStruct rapidast.DASTReport | ||
err = json.Unmarshal(output.Bytes(), &parsableStruct) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
var vulnerabilityFound = false | ||
for _, resource := range parsableStruct.Resources { | ||
for _, result := range resource.Results { | ||
if result.MisconfSummary.Failures > 0 { | ||
fmt.Printf("%d vulnerability(s) found in %s\n", result.MisconfSummary.Failures, resource.Name) | ||
for _, misconfiguration := range result.Misconfigurations { | ||
fmt.Printf("- %+v\n", misconfiguration) | ||
} | ||
vulnerabilityFound = true | ||
} | ||
} | ||
} | ||
Expect(vulnerabilityFound).NotTo(BeTrue(), "Found vulnerability(s)") | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package rapidast | ||
|
||
// DASTReport struct that receives the results of the rapidast scan. | ||
type DASTReport struct { | ||
ClusterName string | ||
Resources []struct { | ||
Name string | ||
Namespace string | ||
Results []struct { | ||
Target string | ||
Class string | ||
Type string | ||
MisconfSummary struct { | ||
Success int | ||
Failures int | ||
Exceptions int | ||
} | ||
Misconfigurations []struct { | ||
Type string | ||
ID string | ||
AVDID string | ||
Description string | ||
Message string | ||
Namespace string | ||
Query string | ||
Resolution string | ||
Severity string | ||
PrimaryURL string | ||
References []string | ||
Status string | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package rapidast | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/golang/glog" | ||
"github.com/openshift-kni/eco-goinfra/pkg/clients" | ||
"github.com/openshift-kni/eco-goinfra/pkg/nodes" | ||
"github.com/openshift-kni/eco-goinfra/pkg/pod" | ||
"github.com/openshift-kni/eco-goinfra/pkg/rbac" | ||
"github.com/openshift-kni/eco-goinfra/pkg/serviceaccount" | ||
. "github.com/openshift-kni/eco-gotests/tests/rhwa/internal/rhwainittools" | ||
"github.com/openshift-kni/eco-gotests/tests/rhwa/internal/rhwaparams" | ||
|
||
v1 "k8s.io/api/rbac/v1" | ||
) | ||
|
||
const ( | ||
logLevel = rhwaparams.LogLevel | ||
) | ||
|
||
// PrepareRapidastPod initializes the pod in the cluster that allows to run rapidast. | ||
func PrepareRapidastPod(apiClient *clients.Settings) *pod.Builder { | ||
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. Consider returning the error from one of the error condition you already handle below with logging only. |
||
nodes, err := nodes.List(apiClient) | ||
if err != nil { | ||
glog.V(logLevel).Infof( | ||
"Error in node list retrieval %s", err.Error()) | ||
} | ||
|
||
_, err = serviceaccount.NewBuilder(APIClient, "trivy-service-account", rhwaparams.TestNamespaceName).Create() | ||
if err != nil { | ||
glog.V(logLevel).Infof( | ||
"Error in service acount creation %s", err.Error()) | ||
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. Typo: s/acount/account |
||
} | ||
|
||
_, err = rbac.NewClusterRoleBuilder(APIClient, "trivy-clusterrole", v1.PolicyRule{ | ||
APIGroups: []string{ | ||
"", | ||
}, | ||
Resources: []string{ | ||
"pods", | ||
}, | ||
Verbs: []string{ | ||
"get", | ||
"list", | ||
"watch", | ||
}, | ||
}).Create() | ||
if err != nil { | ||
glog.V(logLevel).Infof( | ||
"Error in ClusterRoleBuilder creation %s", err.Error()) | ||
} | ||
|
||
_, err = rbac.NewClusterRoleBindingBuilder(APIClient, "trivy-clusterrole-binding", "trivy-clusterrole", v1.Subject{ | ||
Kind: "ServiceAccount", | ||
Name: "trivy-service-account", | ||
Namespace: rhwaparams.TestNamespaceName, | ||
}).Create() | ||
if err != nil { | ||
glog.V(logLevel).Infof( | ||
"Error in ClusterRoleBindingBuilder creation %s", err.Error()) | ||
} | ||
|
||
dastTestPod := pod.NewBuilder( | ||
APIClient, "rapidastclientpod", rhwaparams.TestNamespaceName, rhwaparams.TestContainerDast). | ||
DefineOnNode(nodes[0].Object.Name). | ||
WithTolerationToMaster(). | ||
WithPrivilegedFlag() | ||
dastTestPod.Definition.Spec.ServiceAccountName = "trivy-service-account" | ||
|
||
_, err = dastTestPod.CreateAndWaitUntilRunning(time.Minute) | ||
if err != nil { | ||
glog.V(logLevel).Infof( | ||
"Error in rapidast client pod creation %s", err.Error()) | ||
} | ||
|
||
return dastTestPod | ||
} | ||
|
||
// RunRapidastScan executes the rapidast scan configured in the container. | ||
func RunRapidastScan(dastTestPod pod.Builder, namespace string) (bytes.Buffer, error) { | ||
command := []string{"bash", "-c", | ||
fmt.Sprintf("NAMESPACE=%s rapidast.py --config ./config/rapidastConfig.yaml 2> /dev/null", namespace)} | ||
|
||
return dastTestPod.ExecCommand(command) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,10 @@ const ( | |
RhwaOperatorNs = "openshift-workload-availability" | ||
// DefaultTimeout represents the default timeout. | ||
DefaultTimeout = 300 * time.Second | ||
// TestNamespaceName namespace where all dast test cases are performed. | ||
TestNamespaceName = "dast-tests" | ||
// LogLevel for the supporting functions. | ||
LogLevel = 90 | ||
// TestContainerDast specifies the container image to use for rapidast tests. | ||
TestContainerDast = "quay.io/ocp-edge-qe/eco-dast:latest" | ||
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 wonder if using always the |
||
) |
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 function comment uses the expression "allows to" which can be a bit vague. If this pod is directly responsible for running the scanner, which is what I assume from the comment, it would be clearer to say it explicitly.
What do you think about something like