Skip to content

Commit

Permalink
test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Jogeleit committed May 30, 2022
1 parent 773ce3d commit 38cadcc
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v2
with:
fetch-depth: 0

Expand All @@ -22,7 +22,7 @@ jobs:
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Install Helm
uses: azure/setup-helm@v2.1
uses: azure/setup-helm@v1

- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.2.1
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 0.0.2

* Add unique ResultID props to VulnerabilityReport results
* Remove duplicated results from ConfigAuditReport
4 changes: 2 additions & 2 deletions charts/trivy-operator-polr-adapter/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name: trivy-operator-polr-adapter
description: Helm Chart to install the trivy-operator PolicyReport adapter

type: application
version: "0.0.1"
appVersion: "0.0.1"
version: "0.0.2"
appVersion: "0.0.2"
2 changes: 1 addition & 1 deletion charts/trivy-operator-polr-adapter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ image:
registry: ghcr.io
repository: fjogeleit/trivy-operator-polr-adapter
pullPolicy: IfNotPresent
tag: 0.0.1
tag: 0.0.2

imagePullSecrets: []
nameOverride: ""
Expand Down
6 changes: 5 additions & 1 deletion pkg/adapters/auditr/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ var (
)

func Map(report *v1alpha1.ConfigAuditReport, polr *v1alpha2.PolicyReport) (*v1alpha2.PolicyReport, bool) {
if len(report.Report.Checks) == 0 {
return nil, false
}

var updated bool

if polr == nil {
Expand All @@ -49,7 +53,7 @@ func Map(report *v1alpha1.ConfigAuditReport, polr *v1alpha2.PolicyReport) (*v1al

res := CreateObjectReference(report)

for _, check := range append(report.Report.Checks, report.Report.PodChecks...) {
for _, check := range report.Report.Checks {
props := map[string]string{}

for i, m := range check.Messages {
Expand Down
4 changes: 3 additions & 1 deletion pkg/adapters/auditr/polr_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func (p *PolicyReportClient) GenerateReport(ctx context.Context, report *v1alpha
}

polr, updated := Map(report, polr)
if updated {
if polr == nil {
return nil
} else if updated {
_, err = p.k8sClient.PolicyReports(report.Namespace).Update(ctx, polr, v1.UpdateOptions{})
} else {
_, err = p.k8sClient.PolicyReports(report.Namespace).Create(ctx, polr, v1.CreateOptions{})
Expand Down
19 changes: 18 additions & 1 deletion pkg/adapters/vulnr/mapper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vulnr

import (
"crypto/sha1"
"fmt"

"github.com/aquasecurity/trivy-operator/pkg/apis/aquasecurity/v1alpha1"
Expand Down Expand Up @@ -38,6 +39,10 @@ var (
)

func Map(report *v1alpha1.VulnerabilityReport, polr *v1alpha2.PolicyReport) (*v1alpha2.PolicyReport, bool) {
if len(report.Report.Vulnerabilities) == 0 {
return nil, false
}

var updated bool

if polr == nil {
Expand All @@ -56,12 +61,15 @@ func Map(report *v1alpha1.VulnerabilityReport, polr *v1alpha2.PolicyReport) (*v1
score = *vuln.Score
}

result := MapResult(vuln.Severity)

props := map[string]string{
"artifact.repository": report.Report.Artifact.Repository,
"artifact.tag": report.Report.Artifact.Tag,
"registry.server": report.Report.Registry.Server,
"score": fmt.Sprint(score),
"resource": vuln.Resource,
"resultID": generateID(string(res.UID), res.Name, vuln.VulnerabilityID, vuln.Resource, string(result)),
}

if vuln.FixedVersion != "" {
Expand All @@ -79,7 +87,7 @@ func Map(report *v1alpha1.VulnerabilityReport, polr *v1alpha2.PolicyReport) (*v1
Message: vuln.Title,
Properties: props,
Resources: []*corev1.ObjectReference{res},
Result: MapResult(vuln.Severity),
Result: result,
Severity: MapServerity(vuln.Severity),
Category: category,
Timestamp: *report.CreationTimestamp.ProtoTime(),
Expand Down Expand Up @@ -162,3 +170,12 @@ func GeneratePolicyReportName(report *v1alpha1.VulnerabilityReport) string {

return fmt.Sprintf("%s-%s", reportPrefix, name)
}

func generateID(uid, name, policy, rule, result string) string {
id := fmt.Sprintf("%s_%s_%s_%s_%s", uid, name, policy, rule, result)

h := sha1.New()
h.Write([]byte(id))

return fmt.Sprintf("%x", h.Sum(nil))
}
4 changes: 3 additions & 1 deletion pkg/adapters/vulnr/polr_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func (p *PolicyReportClient) GenerateReport(ctx context.Context, report *v1alpha
}

polr, updated := Map(report, polr)
if updated {
if polr == nil {
return nil
} else if updated {
_, err = p.k8sClient.PolicyReports(report.Namespace).Update(ctx, polr, v1.UpdateOptions{})
} else {
_, err = p.k8sClient.PolicyReports(report.Namespace).Create(ctx, polr, v1.CreateOptions{})
Expand Down

0 comments on commit 38cadcc

Please sign in to comment.