Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit 9daf162

Browse files
authored
Merge pull request #80 from secureCodeBox/telemetry
Send Anonymous Telemetry Data
2 parents 0ca2bfe + 966780b commit 9daf162

File tree

7 files changed

+137
-1
lines changed

7 files changed

+137
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,16 @@ jobs:
6363
cd operator/
6464
go fmt ./...
6565
go vet ./...
66+
- name: Parse Tag
67+
id: parse-tag
68+
run: echo ::set-output name=version::${GITHUB_REF#refs/*/}
6669
- name: "Build'n Push Operator"
6770
uses: docker/build-push-action@v1
6871
with:
6972
username: ${{ secrets.DOCKER_USERNAME }}
7073
password: ${{ secrets.DOCKER_PASSWORD }}
7174
repository: scbexperimental/operator
75+
build_args: VERSION=`${{ steps.parse-tag.outputs.version }}
7276
tag_with_ref: true
7377
tag_with_sha: true
7478
path: ./operator/

operator/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RUN go mod download
1313
COPY main.go main.go
1414
COPY apis/ apis/
1515
COPY controllers/ controllers/
16+
COPY internal/ internal/
1617
COPY utils/ utils/
1718

1819
# Build
@@ -21,6 +22,11 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager
2122
# Use distroless as minimal base image to package the manager binary
2223
# Refer to https://github.com/GoogleContainerTools/distroless for more details
2324
FROM gcr.io/distroless/static:nonroot
25+
26+
ARG VERSION=unkown
27+
ENV VERSION ENV ${BRANCH}
28+
ENV TELEMETRY_ENABLED "true"
29+
2430
WORKDIR /
2531
COPY --from=builder /workspace/manager .
2632
USER nonroot:nonroot
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package telemetry
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"net/http"
8+
"os"
9+
"time"
10+
11+
"sigs.k8s.io/controller-runtime/pkg/client"
12+
13+
"github.com/go-logr/logr"
14+
executionv1 "github.com/secureCodeBox/secureCodeBox-v2/operator/apis/execution/v1"
15+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16+
)
17+
18+
var telemetryInterval = 24 * time.Hour
19+
20+
// officialScanTypes contains the list of official secureCodeBox Scan Types.
21+
// Unofficial Scan Types should be reported as "other" to avoid leakage of confidential data via the scan-types name
22+
var officialScanTypes map[string]bool = map[string]bool{
23+
"amass": true,
24+
"kube-hunter": true,
25+
"kubeaudit": true,
26+
"ncrack": true,
27+
"nikto": true,
28+
"nmap": true,
29+
"ssh-scan": true,
30+
"sslyze": true,
31+
"trivy": true,
32+
"wpscan": true,
33+
"zap-baseline": true,
34+
"zap-api-scan": true,
35+
"zap-full-scan": true,
36+
}
37+
38+
// telemetryData submitted by operator
39+
type telemetryData struct {
40+
Version string `json:"version"`
41+
InstalledScanTypes []string `json:"installedScanTypes"`
42+
}
43+
44+
// Loop Submits Telemetry Data in a regular interval
45+
func Loop(apiClient client.Client, log logr.Logger) {
46+
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/telemetry")
47+
48+
// Wait until controller cache is initialized
49+
time.Sleep(10 * time.Second)
50+
51+
for {
52+
var version string
53+
if envVersion, ok := os.LookupEnv("VERSION"); ok {
54+
version = envVersion
55+
} else {
56+
version = "unkown"
57+
}
58+
59+
ctx := context.Background()
60+
61+
installedScanTypes := map[string]bool{}
62+
var scanTypes executionv1.ScanTypeList
63+
err := apiClient.List(ctx, &scanTypes, client.InNamespace(metav1.NamespaceAll))
64+
65+
if err != nil {
66+
log.Error(err, "Failed to list ScanTypes")
67+
}
68+
for _, scanType := range scanTypes.Items {
69+
installedScanTypes[scanType.Name] = true
70+
}
71+
72+
installedScanTypesList := []string{}
73+
for key := range installedScanTypes {
74+
if _, ok := officialScanTypes[key]; ok {
75+
installedScanTypesList = append(installedScanTypesList, key)
76+
} else {
77+
installedScanTypesList = append(installedScanTypesList, "other")
78+
}
79+
}
80+
81+
log.Info("Submitting Anonymous Telemetry Data", "Version", version, "InstalledScanTypes", installedScanTypesList)
82+
83+
reqBody, err := json.Marshal(telemetryData{
84+
Version: version,
85+
InstalledScanTypes: installedScanTypesList,
86+
})
87+
88+
if err != nil {
89+
log.Error(err, "Failed to encode telemetry data to json")
90+
}
91+
response, err := http.Post("https://telemetry.chase.securecodebox.io/v1/submit", "application/json", bytes.NewBuffer(reqBody))
92+
if err != nil {
93+
log.Error(err, "Failed to send telemetry data")
94+
}
95+
if response != nil {
96+
response.Body.Close()
97+
}
98+
99+
time.Sleep(telemetryInterval)
100+
}
101+
}

operator/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
executionv1 "github.com/secureCodeBox/secureCodeBox-v2/operator/apis/execution/v1"
3131
executioncontroller "github.com/secureCodeBox/secureCodeBox-v2/operator/controllers/execution"
3232
scancontroller "github.com/secureCodeBox/secureCodeBox-v2/operator/controllers/execution/scans"
33+
"github.com/secureCodeBox/secureCodeBox-v2/operator/internal/telemetry"
3334
// +kubebuilder:scaffold:imports
3435
)
3536

@@ -87,6 +88,10 @@ func main() {
8788
}
8889
// +kubebuilder:scaffold:builder
8990

91+
if enabled, ok := os.LookupEnv("TELEMETRY_ENABLED"); ok && enabled == "true" {
92+
go telemetry.Loop(mgr.GetClient(), ctrl.Log.WithName("telemetry"))
93+
}
94+
9095
setupLog.Info("starting manager")
9196
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
9297
setupLog.Error(err, "problem running manager")

operator/templates/NOTES.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
secureCodeBox Operator Deployed 🚀
2+
3+
The operator can orchestrate the execution of various security scanning tools inside of your cluster.
4+
You can find a list of all officially supported scanners here: https://www.securecodebox.io/integrations/
5+
The website also lists other integrations, like persisting scan results to DefectDojo or Elasticsearch.
6+
7+
{{ if .Values.telemetryEnabled -}}
8+
The operator send out regular telemetry pings to a central service.
9+
This lets us, the secureCodeBox team, get a grasp on how much the secureCodeBox is used.
10+
The submitted data is chosen to be as anonymous as possible.
11+
You can find a complete report of the data submitted and links to the source-code at: https://www.securecodebox.io/telemetry
12+
The first ping is send one hour after the install, you can prevent this by upgrading the chart and setting `telemetryEnabled` to `false`.
13+
{{ else -}}
14+
Telemetry data collection has been disabled.
15+
{{ end -}}

operator/templates/manager/manager.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ spec:
2828
imagePullPolicy: {{ .Values.image.pullPolicy }}
2929
name: manager
3030
env:
31+
- name: TELEMETRY_ENABLED
32+
value: {{ .Values.telemetryEnabled | quote }}
3133
# TODO: integrate with cert manager and auto gen a cert for minio
3234
{{- if .Values.minio.enabled }}
3335
- name: S3_USE_SSL

operator/values.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# This is a YAML-formatted file.
33
# Declare variables to be passed into your templates.
44

5+
# telemetryEnabled -- 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/telemetry
6+
telemetryEnabled: true
7+
58
image:
69
registry: docker.io
710
repository: scbexperimental/operator
@@ -45,4 +48,4 @@ resources:
4548
memory: 30Mi
4649
requests:
4750
cpu: 100m
48-
memory: 20Mi
51+
memory: 20Mi

0 commit comments

Comments
 (0)