Skip to content

Commit 62467b9

Browse files
Add repositoryURL to vulnerability report attributes (#585)
Find this from a default annotation and communicate it upstream
1 parent 860a3a3 commit 62467b9

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require (
3737
github.com/openshift/api v0.0.0-20250908150922-8634aa495a26
3838
github.com/orcaman/concurrent-map/v2 v2.0.1
3939
github.com/pkg/errors v0.9.1
40-
github.com/pluralsh/console/go/client v1.54.3
40+
github.com/pluralsh/console/go/client v1.54.4
4141
github.com/pluralsh/controller-reconcile-helper v0.1.0
4242
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34
4343
github.com/pluralsh/polly v0.3.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,8 @@ github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgm
881881
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
882882
github.com/pluralsh/console/go/client v1.54.3 h1:J/GDYuHFAUaTlsRv1tiUPfXrq5RElFTJKwqAvkn5+88=
883883
github.com/pluralsh/console/go/client v1.54.3/go.mod h1:EwMrcI23s61oLY3etCVc3NE5RYxgfoiokvU0O7KDOQg=
884+
github.com/pluralsh/console/go/client v1.54.4 h1:61wfURaw7si9zsNbGjJA3diVa+OyJsETryzM0kkZmuE=
885+
github.com/pluralsh/console/go/client v1.54.4/go.mod h1:EwMrcI23s61oLY3etCVc3NE5RYxgfoiokvU0O7KDOQg=
884886
github.com/pluralsh/controller-reconcile-helper v0.1.0 h1:BV3dYZFH5rn8ZvZjtpkACSv/GmLEtRftNQj/Y4ddHEo=
885887
github.com/pluralsh/controller-reconcile-helper v0.1.0/go.mod h1:RxAbvSB4/jkvx616krCdNQXPbpGJXW3J1L3rASxeFOA=
886888
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 h1:ab2PN+6if/Aq3/sJM0AVdy1SYuMAnq4g20VaKhTm/Bw=

internal/controller/vulnerabilityreports_controller.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const (
3838
vulnerabilityJitter = 10 * time.Minute
3939

4040
reportChunkSize = 15
41+
42+
repositoryURLAnnotationKey = "platform.plural.sh/repository-url"
4143
)
4244

4345
// VulnerabilityReportReconciler reconciles a Trivy VulnerabilityReport resource.
@@ -63,18 +65,23 @@ func (r *VulnerabilityReportReconciler) Reconcile(ctx context.Context, req ctrl.
6365
return ctrl.Result{}, nil
6466
}
6567

66-
var serviceId *string
68+
var serviceId, repositoryURL *string
6769
if len(vulnerabilityReport.OwnerReferences) > 0 {
6870
k8sObj, err := GetObjectFromOwnerReference(ctx, r.Client, vulnerabilityReport.OwnerReferences[0], vulnerabilityReport.Namespace)
6971
if err != nil {
7072
return ctrl.Result{}, err
7173
}
72-
svcId, ok := k8sObj.GetAnnotations()[smcommon.OwningInventoryKey]
73-
if ok {
74+
75+
annotations := k8sObj.GetAnnotations()
76+
if svcId, ok := annotations[smcommon.OwningInventoryKey]; ok {
7477
serviceId = lo.ToPtr(svcId)
7578
}
79+
80+
if repoURL, ok := annotations[repositoryURLAnnotationKey]; ok {
81+
repositoryURL = lo.ToPtr(repoURL)
82+
}
7683
}
77-
attrs, timestamp := createVulnAttributes(*vulnerabilityReport, serviceId)
84+
attrs, timestamp := createVulnAttributes(*vulnerabilityReport, serviceId, repositoryURL)
7885
r.reports.Set(req.String(), vulnReport{
7986
attributes: &attrs,
8087
timestamp: timestamp,
@@ -85,7 +92,7 @@ func (r *VulnerabilityReportReconciler) Reconcile(ctx context.Context, req ctrl.
8592
return jitterRequeue(vulnerabilityRequeueAfter, vulnerabilityJitter), nil
8693
}
8794

88-
func createVulnAttributes(vulnerabilityReport trivy.VulnerabilityReport, serviceID *string) (console.VulnerabilityReportAttributes, time.Time) {
95+
func createVulnAttributes(vulnerabilityReport trivy.VulnerabilityReport, serviceID *string, repositoryURL *string) (console.VulnerabilityReportAttributes, time.Time) {
8996
var namespaces []*console.NamespaceVulnAttributes
9097
os := &console.VulnOsAttributes{
9198
Eosl: lo.ToPtr(vulnerabilityReport.Report.OS.Eosl),
@@ -147,6 +154,7 @@ func createVulnAttributes(vulnerabilityReport trivy.VulnerabilityReport, service
147154
Class: lo.ToPtr(v.Class),
148155
PackageType: lo.ToPtr(v.PackageType),
149156
PkgPath: lo.ToPtr(v.PkgPath),
157+
RepositoryURL: repositoryURL,
150158
}
151159
if v.PublishedDate != "" {
152160
vulnerabilityAttr.PublishedDate = lo.ToPtr(v.PublishedDate)

0 commit comments

Comments
 (0)