-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathtelemetry.go
More file actions
122 lines (104 loc) · 3.7 KB
/
telemetry.go
File metadata and controls
122 lines (104 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// SPDX-FileCopyrightText: the secureCodeBox authors
//
// SPDX-License-Identifier: Apache-2.0
package telemetry
import (
"bytes"
"context"
"encoding/json"
"net/http"
"os"
"time"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/go-logr/logr"
executionv1 "github.com/secureCodeBox/secureCodeBox/operator/apis/execution/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var telemetryInterval = 24 * time.Hour
// officialScanTypes contains the list of official secureCodeBox Scan Types.
// Unofficial Scan Types should be reported as "other" to avoid leakage of confidential data via the scan-types name
var officialScanTypes map[string]bool = map[string]bool{
"amass": true,
"cmseek": true,
"doggo": true,
"ffuf": true,
"git-repo-scanner": true,
"gitleaks": true,
"kube-hunter": true,
"kubeaudit": true,
"ncrack": true,
"nikto": true,
"nmap": true,
"nuclei": true,
"screenshooter": true,
"semgrep": true,
"ssh-audit": true,
"ssh-scan": true, // deprecated. we'll keep it in this list to still recieve telemetry data from older versions
"sslyze": true,
"trivy-image": true,
"trivy-filesystem": true,
"trivy-repo": true,
"trivy-sbom-image": true,
"typo3scan": true,
"whatweb": true,
"wpscan": true,
"zap-baseline-scan": true,
"zap-api-scan": true,
"zap-full-scan": true,
"zap-automation-scan": true,
"zap-automation-framework": true,
"zap-advanced-scan": true,
}
// telemetryData submitted by operator
type telemetryData struct {
Version string `json:"version"`
InstalledScanTypes []string `json:"installedScanTypes"`
}
// Loop Submits Telemetry Data in a regular interval
func Loop(apiClient client.Client, log logr.Logger) {
log.Info("The Operator sends anonymous telemetry data, to give the team an overview how much the secureCodeBox is used. Find out more at https://www.securecodebox.io/docs/telemetry")
// Wait 1hour to give users time to uninstall / disable telemetry
time.Sleep(1 * time.Hour)
for {
var version string
if envVersion, ok := os.LookupEnv("VERSION"); ok {
version = envVersion
} else {
version = "unknown"
}
ctx := context.Background()
installedScanTypes := map[string]bool{}
var scanTypes executionv1.ScanTypeList
err := apiClient.List(ctx, &scanTypes, client.InNamespace(metav1.NamespaceAll))
if err != nil {
log.Error(err, "Failed to list ScanTypes")
}
for _, scanType := range scanTypes.Items {
installedScanTypes[scanType.Name] = true
}
installedScanTypesList := []string{}
for key := range installedScanTypes {
if _, ok := officialScanTypes[key]; ok {
installedScanTypesList = append(installedScanTypesList, key)
} else {
installedScanTypesList = append(installedScanTypesList, "other")
}
}
log.Info("Submitting Anonymous Telemetry Data", "Version", version, "InstalledScanTypes", installedScanTypesList)
reqBody, err := json.Marshal(telemetryData{
Version: version,
InstalledScanTypes: installedScanTypesList,
})
if err != nil {
log.Error(err, "Failed to encode telemetry data to json")
}
response, err := http.Post("https://telemetry.securecodebox.io/v1/submit", "application/json", bytes.NewBuffer(reqBody))
if err != nil {
log.Error(err, "Failed to send telemetry data")
}
if response != nil {
response.Body.Close()
}
time.Sleep(telemetryInterval)
}
}