From 1aec2ef7368c193a6ce8d214c6d2d01f6802af6d Mon Sep 17 00:00:00 2001 From: an1l4 <1995anila@gmail.com> Date: Fri, 22 Dec 2023 12:16:54 +0530 Subject: [PATCH 1/5] clustername --- agent/kubviz/trivy_sbom.go | 7 +++++++ client/pkg/clickhouse/db_client.go | 3 +++ client/pkg/clickhouse/statements.go | 3 ++- model/trivy_sbom.go | 1 + sql/0000015_trivysbom.up.sql | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/agent/kubviz/trivy_sbom.go b/agent/kubviz/trivy_sbom.go index bbd5cb03..7c93ada9 100644 --- a/agent/kubviz/trivy_sbom.go +++ b/agent/kubviz/trivy_sbom.go @@ -19,6 +19,7 @@ import ( func publishTrivySbomReport(report cyclonedx.BOM, js nats.JetStreamContext) error { metrics := model.SbomData{ ID: uuid.New().String(), + ClusterName: ClusterName, ComponentName: report.CycloneDX.Metadata.Component.Name, PackageUrl: report.CycloneDX.Metadata.Component.PackageURL, BomRef: report.CycloneDX.Metadata.Component.BOMRef, @@ -92,6 +93,12 @@ func RunTrivySbomScan(config *rest.Config, js nats.JetStreamContext) error { continue // Move on to the next image in case of an error } publishTrivySbomReport(report, js) + + for _, packageInfo := range report.Packages { + for _, pkg := range packageInfo.Packages { + log.Printf("****Package name: %#v", pkg.Name) + } + } } return nil } diff --git a/client/pkg/clickhouse/db_client.go b/client/pkg/clickhouse/db_client.go index 4e21d0e2..40ec1c1b 100644 --- a/client/pkg/clickhouse/db_client.go +++ b/client/pkg/clickhouse/db_client.go @@ -699,6 +699,7 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.SbomData) { if _, err := stmt.Exec( metrics.ID, + metrics.ClusterName, metrics.ComponentName, metrics.PackageUrl, metrics.BomRef, @@ -712,6 +713,8 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.SbomData) { log.Fatal(err) } stmt.Close() + + log.Printf("**Clustername :%#v",metrics.ClusterName) } func (c *DBClient) Close() { _ = c.conn.Close() diff --git a/client/pkg/clickhouse/statements.go b/client/pkg/clickhouse/statements.go index 797cb061..d3fdfa10 100644 --- a/client/pkg/clickhouse/statements.go +++ b/client/pkg/clickhouse/statements.go @@ -205,6 +205,7 @@ const quayContainerPushEventTable DBStatement = ` const trivySbomTable DBStatement = ` CREATE TABLE IF NOT EXISTS trivysbom ( id UUID, + cluster_name String, image_name String, package_url String, bom_ref String, @@ -228,6 +229,6 @@ const InsertTrivyVul string = "INSERT INTO trivy_vul (id, cluster_name, namespac const InsertTrivyImage string = "INSERT INTO trivyimage (id, cluster_name, artifact_name, vul_id, vul_pkg_id, vul_pkg_name, vul_installed_version, vul_fixed_version, vul_title, vul_severity, vul_published_date, vul_last_modified_date) VALUES ( ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" const InsertTrivyMisconfig string = "INSERT INTO trivy_misconfig (id, cluster_name, namespace, kind, name, misconfig_id, misconfig_avdid, misconfig_type, misconfig_title, misconfig_desc, misconfig_msg, misconfig_query, misconfig_resolution, misconfig_severity, misconfig_status, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" const InsertAzureContainerPushEvent DBStatement = "INSERT INTO azurecontainerpush (RegistryURL, RepositoryName, Tag, ImageName, Event, Size, SHAID, EventTime) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)" -const InsertTrivySbom string = "INSERT INTO trivysbom (id, image_name, package_url, bom_ref, serial_number, version, bom_format) VALUES (?, ?, ?, ?, ?, ?, ?)" +const InsertTrivySbom string = "INSERT INTO trivysbom (id, cluster_name, image_name, package_url, bom_ref, serial_number, version, bom_format) VALUES (?, ?, ?, ?, ?, ?, ?)" const InsertQuayContainerPushEvent DBStatement = "INSERT INTO quaycontainerpush (name, repository, nameSpace, dockerURL, homePage, tag, Event, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" const InsertJfrogContainerPushEvent DBStatement = "INSERT INTO jfrogcontainerpush (Domain, EventType, RegistryURL, RepositoryName, SHAID, Size, ImageName, Tag, Event, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" diff --git a/model/trivy_sbom.go b/model/trivy_sbom.go index 8eea1769..9e68e610 100644 --- a/model/trivy_sbom.go +++ b/model/trivy_sbom.go @@ -11,6 +11,7 @@ type Sbom struct { type SbomData struct { ID string + ClusterName string ComponentName string PackageUrl string BomRef string diff --git a/sql/0000015_trivysbom.up.sql b/sql/0000015_trivysbom.up.sql index 924f9ec8..be0eb995 100644 --- a/sql/0000015_trivysbom.up.sql +++ b/sql/0000015_trivysbom.up.sql @@ -1,5 +1,6 @@ CREATE TABLE IF NOT EXISTS trivysbom ( id UUID, + cluster_name String image_name String, package_url String, bom_ref String, From 2e75a06ba3cec402e0837591e660c3134e989222 Mon Sep 17 00:00:00 2001 From: an1l4 <1995anila@gmail.com> Date: Fri, 22 Dec 2023 12:40:44 +0530 Subject: [PATCH 2/5] clusternam1 --- agent/kubviz/trivy_sbom.go | 7 +------ model/trivy_sbom.go | 1 + sql/0000015_trivysbom.up.sql | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/agent/kubviz/trivy_sbom.go b/agent/kubviz/trivy_sbom.go index 7c93ada9..38c8f0df 100644 --- a/agent/kubviz/trivy_sbom.go +++ b/agent/kubviz/trivy_sbom.go @@ -17,6 +17,7 @@ import ( ) func publishTrivySbomReport(report cyclonedx.BOM, js nats.JetStreamContext) error { + metrics := model.SbomData{ ID: uuid.New().String(), ClusterName: ClusterName, @@ -93,12 +94,6 @@ func RunTrivySbomScan(config *rest.Config, js nats.JetStreamContext) error { continue // Move on to the next image in case of an error } publishTrivySbomReport(report, js) - - for _, packageInfo := range report.Packages { - for _, pkg := range packageInfo.Packages { - log.Printf("****Package name: %#v", pkg.Name) - } - } } return nil } diff --git a/model/trivy_sbom.go b/model/trivy_sbom.go index 9e68e610..647e34a4 100644 --- a/model/trivy_sbom.go +++ b/model/trivy_sbom.go @@ -13,6 +13,7 @@ type SbomData struct { ID string ClusterName string ComponentName string + PackageName string PackageUrl string BomRef string SerialNumber string diff --git a/sql/0000015_trivysbom.up.sql b/sql/0000015_trivysbom.up.sql index be0eb995..d717d65c 100644 --- a/sql/0000015_trivysbom.up.sql +++ b/sql/0000015_trivysbom.up.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS trivysbom ( id UUID, - cluster_name String + cluster_name String, image_name String, package_url String, bom_ref String, From 212b259208a01b70e8f71a5dad6e24af00efda3c Mon Sep 17 00:00:00 2001 From: an1l4 <1995anila@gmail.com> Date: Fri, 22 Dec 2023 13:18:43 +0530 Subject: [PATCH 3/5] clusternam2 --- client/pkg/clickhouse/statements.go | 2 +- model/trivy_sbom.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/client/pkg/clickhouse/statements.go b/client/pkg/clickhouse/statements.go index d3fdfa10..18c8c1d5 100644 --- a/client/pkg/clickhouse/statements.go +++ b/client/pkg/clickhouse/statements.go @@ -229,6 +229,6 @@ const InsertTrivyVul string = "INSERT INTO trivy_vul (id, cluster_name, namespac const InsertTrivyImage string = "INSERT INTO trivyimage (id, cluster_name, artifact_name, vul_id, vul_pkg_id, vul_pkg_name, vul_installed_version, vul_fixed_version, vul_title, vul_severity, vul_published_date, vul_last_modified_date) VALUES ( ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" const InsertTrivyMisconfig string = "INSERT INTO trivy_misconfig (id, cluster_name, namespace, kind, name, misconfig_id, misconfig_avdid, misconfig_type, misconfig_title, misconfig_desc, misconfig_msg, misconfig_query, misconfig_resolution, misconfig_severity, misconfig_status, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" const InsertAzureContainerPushEvent DBStatement = "INSERT INTO azurecontainerpush (RegistryURL, RepositoryName, Tag, ImageName, Event, Size, SHAID, EventTime) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)" -const InsertTrivySbom string = "INSERT INTO trivysbom (id, cluster_name, image_name, package_url, bom_ref, serial_number, version, bom_format) VALUES (?, ?, ?, ?, ?, ?, ?)" +const InsertTrivySbom string = "INSERT INTO trivysbom (id, cluster_name, image_name, package_url, bom_ref, serial_number, version, bom_format) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" const InsertQuayContainerPushEvent DBStatement = "INSERT INTO quaycontainerpush (name, repository, nameSpace, dockerURL, homePage, tag, Event, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" const InsertJfrogContainerPushEvent DBStatement = "INSERT INTO jfrogcontainerpush (Domain, EventType, RegistryURL, RepositoryName, SHAID, Size, ImageName, Tag, Event, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" diff --git a/model/trivy_sbom.go b/model/trivy_sbom.go index 647e34a4..9e68e610 100644 --- a/model/trivy_sbom.go +++ b/model/trivy_sbom.go @@ -13,7 +13,6 @@ type SbomData struct { ID string ClusterName string ComponentName string - PackageName string PackageUrl string BomRef string SerialNumber string From 105b8ab461503445d90da633ddd8311110b1b057 Mon Sep 17 00:00:00 2001 From: an1l4 <1995anila@gmail.com> Date: Fri, 22 Dec 2023 16:03:56 +0530 Subject: [PATCH 4/5] pckname --- agent/kubviz/trivy_sbom.go | 11 ++++++++++- client/pkg/clickhouse/db_client.go | 1 + client/pkg/clickhouse/statements.go | 3 ++- model/trivy_sbom.go | 1 + sql/0000015_trivysbom.up.sql | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/agent/kubviz/trivy_sbom.go b/agent/kubviz/trivy_sbom.go index 38c8f0df..ff1b6bf5 100644 --- a/agent/kubviz/trivy_sbom.go +++ b/agent/kubviz/trivy_sbom.go @@ -18,10 +18,16 @@ import ( func publishTrivySbomReport(report cyclonedx.BOM, js nats.JetStreamContext) error { + for _,packageinfo :=range report.Packages { + for _, pkg := range packageinfo.Packages { + //log.Println(pkg.Name) + + metrics := model.SbomData{ ID: uuid.New().String(), ClusterName: ClusterName, ComponentName: report.CycloneDX.Metadata.Component.Name, + PackageName: pkg.Name, PackageUrl: report.CycloneDX.Metadata.Component.PackageURL, BomRef: report.CycloneDX.Metadata.Component.BOMRef, SerialNumber: report.CycloneDX.SerialNumber, @@ -37,8 +43,11 @@ func publishTrivySbomReport(report cyclonedx.BOM, js nats.JetStreamContext) erro if err != nil { return err } - log.Printf("Trivy sbom report with Id %v has been published\n", metrics.ID) + +} +} + return nil } diff --git a/client/pkg/clickhouse/db_client.go b/client/pkg/clickhouse/db_client.go index 40ec1c1b..377fffe5 100644 --- a/client/pkg/clickhouse/db_client.go +++ b/client/pkg/clickhouse/db_client.go @@ -701,6 +701,7 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.SbomData) { metrics.ID, metrics.ClusterName, metrics.ComponentName, + metrics.PackageName, metrics.PackageUrl, metrics.BomRef, metrics.SerialNumber, diff --git a/client/pkg/clickhouse/statements.go b/client/pkg/clickhouse/statements.go index 18c8c1d5..c248aab3 100644 --- a/client/pkg/clickhouse/statements.go +++ b/client/pkg/clickhouse/statements.go @@ -207,6 +207,7 @@ const trivySbomTable DBStatement = ` id UUID, cluster_name String, image_name String, + package_name String, package_url String, bom_ref String, serial_number String, @@ -229,6 +230,6 @@ const InsertTrivyVul string = "INSERT INTO trivy_vul (id, cluster_name, namespac const InsertTrivyImage string = "INSERT INTO trivyimage (id, cluster_name, artifact_name, vul_id, vul_pkg_id, vul_pkg_name, vul_installed_version, vul_fixed_version, vul_title, vul_severity, vul_published_date, vul_last_modified_date) VALUES ( ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" const InsertTrivyMisconfig string = "INSERT INTO trivy_misconfig (id, cluster_name, namespace, kind, name, misconfig_id, misconfig_avdid, misconfig_type, misconfig_title, misconfig_desc, misconfig_msg, misconfig_query, misconfig_resolution, misconfig_severity, misconfig_status, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" const InsertAzureContainerPushEvent DBStatement = "INSERT INTO azurecontainerpush (RegistryURL, RepositoryName, Tag, ImageName, Event, Size, SHAID, EventTime) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)" -const InsertTrivySbom string = "INSERT INTO trivysbom (id, cluster_name, image_name, package_url, bom_ref, serial_number, version, bom_format) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" +const InsertTrivySbom string = "INSERT INTO trivysbom (id, cluster_name, image_name, package_name, package_url, bom_ref, serial_number, version, bom_format) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" const InsertQuayContainerPushEvent DBStatement = "INSERT INTO quaycontainerpush (name, repository, nameSpace, dockerURL, homePage, tag, Event, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" const InsertJfrogContainerPushEvent DBStatement = "INSERT INTO jfrogcontainerpush (Domain, EventType, RegistryURL, RepositoryName, SHAID, Size, ImageName, Tag, Event, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" diff --git a/model/trivy_sbom.go b/model/trivy_sbom.go index 9e68e610..647e34a4 100644 --- a/model/trivy_sbom.go +++ b/model/trivy_sbom.go @@ -13,6 +13,7 @@ type SbomData struct { ID string ClusterName string ComponentName string + PackageName string PackageUrl string BomRef string SerialNumber string diff --git a/sql/0000015_trivysbom.up.sql b/sql/0000015_trivysbom.up.sql index d717d65c..0e3a9c2e 100644 --- a/sql/0000015_trivysbom.up.sql +++ b/sql/0000015_trivysbom.up.sql @@ -2,6 +2,7 @@ CREATE TABLE IF NOT EXISTS trivysbom ( id UUID, cluster_name String, image_name String, + package_name String, package_url String, bom_ref String, serial_number String, From 166ee4eb4fed0f5071580f2a2b57f1518db40254 Mon Sep 17 00:00:00 2001 From: an1l4 <1995anila@gmail.com> Date: Fri, 22 Dec 2023 18:26:18 +0530 Subject: [PATCH 5/5] log-removed --- agent/kubviz/trivy_sbom.go | 8 ++------ client/pkg/clickhouse/db_client.go | 2 -- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/agent/kubviz/trivy_sbom.go b/agent/kubviz/trivy_sbom.go index ff1b6bf5..5cc0f13c 100644 --- a/agent/kubviz/trivy_sbom.go +++ b/agent/kubviz/trivy_sbom.go @@ -20,14 +20,12 @@ func publishTrivySbomReport(report cyclonedx.BOM, js nats.JetStreamContext) erro for _,packageinfo :=range report.Packages { for _, pkg := range packageinfo.Packages { - //log.Println(pkg.Name) - metrics := model.SbomData{ ID: uuid.New().String(), - ClusterName: ClusterName, + ClusterName: ClusterName, ComponentName: report.CycloneDX.Metadata.Component.Name, - PackageName: pkg.Name, + PackageName: pkg.Name, PackageUrl: report.CycloneDX.Metadata.Component.PackageURL, BomRef: report.CycloneDX.Metadata.Component.BOMRef, SerialNumber: report.CycloneDX.SerialNumber, @@ -44,10 +42,8 @@ func publishTrivySbomReport(report cyclonedx.BOM, js nats.JetStreamContext) erro return err } log.Printf("Trivy sbom report with Id %v has been published\n", metrics.ID) - } } - return nil } diff --git a/client/pkg/clickhouse/db_client.go b/client/pkg/clickhouse/db_client.go index 377fffe5..35460db3 100644 --- a/client/pkg/clickhouse/db_client.go +++ b/client/pkg/clickhouse/db_client.go @@ -714,8 +714,6 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.SbomData) { log.Fatal(err) } stmt.Close() - - log.Printf("**Clustername :%#v",metrics.ClusterName) } func (c *DBClient) Close() { _ = c.conn.Close()