From dea5649e01ae3f6b20b5314081d38f2662d4ce3b Mon Sep 17 00:00:00 2001 From: David Wertenteil Date: Sat, 4 Mar 2023 22:34:08 +0200 Subject: [PATCH 1/5] wip: update link in docs Signed-off-by: David Wertenteil --- docs/providers/armo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/providers/armo.md b/docs/providers/armo.md index 2ff731de..23f863ea 100644 --- a/docs/providers/armo.md +++ b/docs/providers/armo.md @@ -1,6 +1,6 @@ -[ARMO Platform](https://cloud.armosec.io/account/sign-up) is an enterprise solution based on Kubescape. It’s a multi-cloud Kubernetes and CI/CD security platform with a single pane of glass including risk analysis, security compliance, misconfiguration, image vulnerability, repository and registry scanning, RBAC visualization, and more. +[ARMO Platform](https://cloud.armosec.io/account/sign-up?utm_source=ARMOgithub&utm_medium=ARMOcli) is an enterprise solution based on Kubescape. It’s a multi-cloud Kubernetes and CI/CD security platform with a single pane of glass including risk analysis, security compliance, misconfiguration, image vulnerability, repository and registry scanning, RBAC visualization, and more. ## Connect Kubescape to ARMO Platform Step #1: Install Kubescape in your CLI From 6c54aff451e474c8e55ec62d4089c0bcc1dc77e0 Mon Sep 17 00:00:00 2001 From: David Wertenteil Date: Sat, 4 Mar 2023 22:46:20 +0200 Subject: [PATCH 2/5] wip: removed unused code Signed-off-by: David Wertenteil --- core/pkg/resultshandling/reporter/v2/utils.go | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/core/pkg/resultshandling/reporter/v2/utils.go b/core/pkg/resultshandling/reporter/v2/utils.go index 352eb50b..c3e88431 100644 --- a/core/pkg/resultshandling/reporter/v2/utils.go +++ b/core/pkg/resultshandling/reporter/v2/utils.go @@ -5,26 +5,6 @@ import ( "strings" ) -/* unused for now -func maskID(id string) string { - sep := "-" - splitted := strings.Split(id, sep) - if len(splitted) != 5 { - return "" - } - str := splitted[0][:4] - splitted[0] = splitted[0][4:] - for i := range splitted { - for j := 0; j < len(splitted[i]); j++ { - str += "X" - } - str += sep - } - - return strings.TrimSuffix(str, sep) -} -*/ - func parseHost(urlObj *url.URL) { if strings.Contains(urlObj.Host, "http://") { urlObj.Scheme = "http" From c2b0e5c0a2d58c2a40c227a2e4ebaaabc34df39b Mon Sep 17 00:00:00 2001 From: David Wertenteil Date: Sat, 4 Mar 2023 23:04:26 +0200 Subject: [PATCH 3/5] Do not display URL when message is empty Signed-off-by: David Wertenteil --- .../reporter/v2/mockreporter.go | 21 +++--- .../reporter/v2/mockreporter_test.go | 66 +++++++++++++++---- 2 files changed, 67 insertions(+), 20 deletions(-) diff --git a/core/pkg/resultshandling/reporter/v2/mockreporter.go b/core/pkg/resultshandling/reporter/v2/mockreporter.go index d4a2e191..a4489dab 100644 --- a/core/pkg/resultshandling/reporter/v2/mockreporter.go +++ b/core/pkg/resultshandling/reporter/v2/mockreporter.go @@ -7,8 +7,11 @@ import ( "os" "github.com/kubescape/kubescape/v2/core/cautils" + "github.com/kubescape/kubescape/v2/core/pkg/resultshandling/reporter" ) +var _ reporter.IReport = &ReportMock{} + type ReportMock struct { query string message string @@ -36,17 +39,19 @@ func (reportMock *ReportMock) GetURL() string { return "" } - q := u.Query() - q.Add("utm_source", "GitHub") - q.Add("utm_medium", "CLI") - q.Add("utm_campaign", "Submit") - - u.RawQuery = q.Encode() - return u.String() } func (reportMock *ReportMock) DisplayReportURL() { + if m := reportMock.strToDisplay(); m != "" { + cautils.InfoTextDisplay(os.Stderr, m) + } +} + +func (reportMock *ReportMock) strToDisplay() string { + if reportMock.message == "" { + return "" + } sep := "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" message := sep + "\n" @@ -55,5 +60,5 @@ func (reportMock *ReportMock) DisplayReportURL() { message += "For more details: " + link + "\n" } message += sep + "\n" - cautils.InfoTextDisplay(os.Stderr, fmt.Sprintf("\n%s\n", message)) + return fmt.Sprintf("\n%s\n", message) } diff --git a/core/pkg/resultshandling/reporter/v2/mockreporter_test.go b/core/pkg/resultshandling/reporter/v2/mockreporter_test.go index 2a699a54..83d14a12 100644 --- a/core/pkg/resultshandling/reporter/v2/mockreporter_test.go +++ b/core/pkg/resultshandling/reporter/v2/mockreporter_test.go @@ -1,10 +1,13 @@ package reporter -import "testing" +import ( + "testing" +) func TestReportMock_GetURL(t *testing.T) { type fields struct { - query string + query string + message string } tests := []struct { name string @@ -13,19 +16,17 @@ func TestReportMock_GetURL(t *testing.T) { }{ { name: "TestReportMock_GetURL", - fields: struct { - query string - }{ - query: "https://kubescape.io", + fields: fields{ + query: "https://kubescape.io", + message: "some message", }, - want: "https://kubescape.io?utm_campaign=Submit&utm_medium=CLI&utm_source=GitHub", + want: "https://kubescape.io", }, { name: "TestReportMock_GetURL_empty", - fields: struct { - query string - }{ - query: "", + fields: fields{ + query: "", + message: "", }, want: "", }, @@ -33,7 +34,8 @@ func TestReportMock_GetURL(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { reportMock := &ReportMock{ - query: tt.fields.query, + query: tt.fields.query, + message: tt.fields.message, } if got := reportMock.GetURL(); got != tt.want { t.Errorf("ReportMock.GetURL() = %v, want %v", got, tt.want) @@ -41,3 +43,43 @@ func TestReportMock_GetURL(t *testing.T) { }) } } + +func TestReportMock_strToDisplay(t *testing.T) { + type fields struct { + query string + message string + } + tests := []struct { + name string + fields fields + want string + }{ + { + name: "TestReportMock_strToDisplay", + fields: fields{ + query: "https://kubescape.io", + message: "some message", + }, + want: "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nScan results have not been submitted: some message\nFor more details: https://kubescape.io\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n", + }, + { + name: "TestReportMock_strToDisplay_empty", + fields: fields{ + query: "https://kubescape.io", + message: "", + }, + want: "", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + reportMock := &ReportMock{ + query: tt.fields.query, + message: tt.fields.message, + } + if got := reportMock.strToDisplay(); got != tt.want { + t.Errorf("ReportMock.strToDisplay() = %v, want %v", got, tt.want) + } + }) + } +} From 2cda4864e7bf0abdf8ccb09049027df9be7dbe6c Mon Sep 17 00:00:00 2001 From: David Wertenteil Date: Sat, 4 Mar 2023 23:05:02 +0200 Subject: [PATCH 4/5] wip: do not add message when account ID is empty Signed-off-by: David Wertenteil --- core/core/initutils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/core/initutils.go b/core/core/initutils.go index ea26142d..3c3c3fec 100644 --- a/core/core/initutils.go +++ b/core/core/initutils.go @@ -77,7 +77,7 @@ func getReporter(ctx context.Context, tenantConfig cautils.ITenantConfig, report } if tenantConfig.GetAccountID() == "" { // Add link only when scanning a cluster using a framework - return reporterv2.NewReportMock("https://hub.armosec.io/docs/installing-kubescape", "run kubescape with the '--account' flag") + return reporterv2.NewReportMock("", "") } var message string if !fwScan { From 0698c99241a988fbf7f7d09ad0a8886e4e14822b Mon Sep 17 00:00:00 2001 From: David Wertenteil Date: Sat, 4 Mar 2023 23:05:38 +0200 Subject: [PATCH 5/5] wip: update UTMs & display UTM only on first scan Signed-off-by: David Wertenteil --- .../reporter/v2/reporteventreceiver.go | 14 ++++---- .../reporter/v2/reporteventreceiver_test.go | 35 +++++++++++++++---- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/core/pkg/resultshandling/reporter/v2/reporteventreceiver.go b/core/pkg/resultshandling/reporter/v2/reporteventreceiver.go index d55449fb..c937c243 100644 --- a/core/pkg/resultshandling/reporter/v2/reporteventreceiver.go +++ b/core/pkg/resultshandling/reporter/v2/reporteventreceiver.go @@ -14,6 +14,7 @@ import ( "github.com/kubescape/k8s-interface/workloadinterface" "github.com/kubescape/kubescape/v2/core/cautils" "github.com/kubescape/kubescape/v2/core/cautils/getter" + "github.com/kubescape/kubescape/v2/core/pkg/resultshandling/reporter" "github.com/kubescape/opa-utils/reporthandling" "github.com/kubescape/opa-utils/reporthandling/results/v1/prioritization" "github.com/kubescape/opa-utils/reporthandling/results/v1/resourcesresults" @@ -31,6 +32,8 @@ const ( SubmitContextRepository SubmitContext = "repository" ) +var _ reporter.IReport = &ReportEventReceiver{} + type ReportEventReceiver struct { httpClient *http.Client clusterName string @@ -121,13 +124,6 @@ func (report *ReportEventReceiver) GetURL() string { parseHost(&u) report.addPathURL(&u) - q := u.Query() - q.Add("utm_source", "GitHub") - q.Add("utm_medium", "CLI") - q.Add("utm_campaign", "Submit") - - u.RawQuery = q.Encode() - return u.String() } @@ -286,6 +282,10 @@ func (report *ReportEventReceiver) addPathURL(urlObj *url.URL) { q := urlObj.Query() q.Add("invitationToken", report.token) q.Add("customerGUID", report.customerGUID) + + // Adding utm parameters + q.Add("utm_source", "ARMOgithub") + q.Add("utm_medium", "createaccount") urlObj.RawQuery = q.Encode() } diff --git a/core/pkg/resultshandling/reporter/v2/reporteventreceiver_test.go b/core/pkg/resultshandling/reporter/v2/reporteventreceiver_test.go index 39f215a8..ea9b6593 100644 --- a/core/pkg/resultshandling/reporter/v2/reporteventreceiver_test.go +++ b/core/pkg/resultshandling/reporter/v2/reporteventreceiver_test.go @@ -11,13 +11,13 @@ import ( func TestReportEventReceiver_addPathURL(t *testing.T) { tests := []struct { - name string report *ReportEventReceiver urlObj *url.URL want *url.URL + name string }{ { - name: "add scan path", + name: "URL for submitted data", report: &ReportEventReceiver{ clusterName: "test", customerGUID: "FFFF", @@ -31,9 +31,30 @@ func TestReportEventReceiver_addPathURL(t *testing.T) { Host: "localhost:8080", }, want: &url.URL{ + Scheme: "https", + Host: "localhost:8080", + Path: "compliance/test", + RawQuery: "", + }, + }, + { + name: "URL for first scan", + report: &ReportEventReceiver{ + clusterName: "test", + customerGUID: "FFFF", + token: "XXXX", + reportID: "1234", + submitContext: SubmitContextScan, + }, + urlObj: &url.URL{ Scheme: "https", Host: "localhost:8080", - Path: "compliance/test", + }, + want: &url.URL{ + Scheme: "https", + Host: "localhost:8080", + Path: "account/sign-up", + RawQuery: "customerGUID=FFFF&invitationToken=XXXX&utm_medium=createaccount&utm_source=ARMOgithub", }, }, } @@ -59,7 +80,7 @@ func TestGetURL(t *testing.T) { "", SubmitContextScan, ) - assert.Equal(t, "https://cloud.armosec.io/compliance/test?utm_campaign=Submit&utm_medium=CLI&utm_source=GitHub", reporter.GetURL()) + assert.Equal(t, "https://cloud.armosec.io/compliance/test", reporter.GetURL()) } // Test rbac submit and registered url @@ -74,7 +95,7 @@ func TestGetURL(t *testing.T) { "", SubmitContextRBAC, ) - assert.Equal(t, "https://cloud.armosec.io/rbac-visualizer?utm_campaign=Submit&utm_medium=CLI&utm_source=GitHub", reporter.GetURL()) + assert.Equal(t, "https://cloud.armosec.io/rbac-visualizer", reporter.GetURL()) } // Test repo submit and registered url @@ -89,7 +110,7 @@ func TestGetURL(t *testing.T) { "XXXX", SubmitContextRepository, ) - assert.Equal(t, "https://cloud.armosec.io/repository-scanning/XXXX?utm_campaign=Submit&utm_medium=CLI&utm_source=GitHub", reporter.GetURL()) + assert.Equal(t, "https://cloud.armosec.io/repository-scanning/XXXX", reporter.GetURL()) } // Test submit and NOT registered url @@ -104,7 +125,7 @@ func TestGetURL(t *testing.T) { "", SubmitContextScan, ) - assert.Equal(t, "https://cloud.armosec.io/account/sign-up?customerGUID=1234&invitationToken=token&utm_campaign=Submit&utm_medium=CLI&utm_source=GitHub", reporter.GetURL()) + assert.Equal(t, "https://cloud.armosec.io/account/sign-up?customerGUID=1234&invitationToken=token&utm_medium=createaccount&utm_source=ARMOgithub", reporter.GetURL()) } }