Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Commit 7e8b115

Browse files
committed
feat(k8s-docker): polaris scanner dockerfile and k8s objects
DISCLAIMER: I haven't found a way to run the service in bare-bone alpine container. polaris keeps a part of runtime needed configuration in yaml files. These files are embedded into polaris binaries with gobuffalo/packr The problem is, packr is not able to embed files from referenced modules gobuffalo/packr#236 To overcome the issue, polaris-scanner is built and is running from the same golang container golang:1.13.7-alpine3.11 using CGO_ENABLED=1 If produced binary is copied to bare-bone alpine container - it's not visible, due the problem described in SO question https://stackoverflow.com/q/34729748/1952990 I tried both options from SO question: nor symlink, neither CGO_ENABLED=0 helps, because of the initial packr issue
1 parent 0628fd3 commit 7e8b115

File tree

4 files changed

+275
-4
lines changed

4 files changed

+275
-4
lines changed

examples/k8s/scanner-polaris.yaml

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: scanner-polaris-cfg
6+
namespace: joseki
7+
labels:
8+
app: scanner-polaris
9+
module: scanners
10+
version: 0.1.1
11+
data:
12+
scanner-polaris-config.yaml: |
13+
scanner:
14+
id: SCANNER_ID
15+
periodicity: "0 2 * * *"
16+
heartbeat-periodicity: 86400
17+
version: 0.1.1
18+
polaris:
19+
configPath: /app/polaris-config.yaml
20+
version: 0.6.0
21+
blobStorageType: azure-blob-storage
22+
azureBlobConfig:
23+
storageBaseUrl: https://STORAGE__ACCOUNT_NAME.blob.core.windows.net/CONTAINER_NAME
24+
sasToken: INSERT_SAS_TOKEN_HERE
25+
logFormat: plain-text
26+
polaris-config.yaml: |
27+
checks:
28+
# resources
29+
cpuRequestsMissing: warning
30+
cpuLimitsMissing: warning
31+
memoryRequestsMissing: warning
32+
memoryLimitsMissing: warning
33+
# images
34+
tagNotSpecified: error
35+
pullPolicyNotAlways: ignore
36+
# healthChecks
37+
readinessProbeMissing: warning
38+
livenessProbeMissing: warning
39+
# networking
40+
hostNetworkSet: warning
41+
hostPortSet: warning
42+
# security
43+
hostIPCSet: error
44+
hostPIDSet: error
45+
notReadOnlyRootFileSystem: warning
46+
privilegeEscalationAllowed: error
47+
runAsRootAllowed: warning
48+
runAsPrivileged: error
49+
dangerousCapabilities: error
50+
insecureCapabilities: warning
51+
controllersToScan:
52+
- Deployments
53+
- StatefulSets
54+
- DaemonSets
55+
- CronJobs
56+
- Jobs
57+
- ReplicationControllers
58+
exemptions:
59+
- controllerNames:
60+
- dns-controller
61+
- datadog-datadog
62+
- kube-flannel-ds
63+
- kube2iam
64+
- aws-iam-authenticator
65+
- datadog
66+
- kube2iam
67+
rules:
68+
- hostNetworkSet
69+
- controllerNames:
70+
- aws-iam-authenticator
71+
- aws-cluster-autoscaler
72+
- kube-state-metrics
73+
- dns-controller
74+
- external-dns
75+
- dnsmasq
76+
- autoscaler
77+
- kubernetes-dashboard
78+
- install-cni
79+
- kube2iam
80+
rules:
81+
- readinessProbeMissing
82+
- livenessProbeMissing
83+
- controllerNames:
84+
- aws-iam-authenticator
85+
- nginx-ingress-controller
86+
- nginx-ingress-default-backend
87+
- aws-cluster-autoscaler
88+
- kube-state-metrics
89+
- dns-controller
90+
- external-dns
91+
- kubedns
92+
- dnsmasq
93+
- autoscaler
94+
- tiller
95+
- kube2iam
96+
rules:
97+
- runAsRootAllowed
98+
- controllerNames:
99+
- aws-iam-authenticator
100+
- nginx-ingress-controller
101+
- nginx-ingress-default-backend
102+
- aws-cluster-autoscaler
103+
- kube-state-metrics
104+
- dns-controller
105+
- external-dns
106+
- kubedns
107+
- dnsmasq
108+
- autoscaler
109+
- tiller
110+
- kube2iam
111+
rules:
112+
- notReadOnlyRootFileSystem
113+
- controllerNames:
114+
- cert-manager
115+
- dns-controller
116+
- kubedns
117+
- dnsmasq
118+
- autoscaler
119+
- insights-agent-goldilocks-vpa-install
120+
rules:
121+
- cpuRequestsMissing
122+
- cpuLimitsMissing
123+
- memoryRequestsMissing
124+
- memoryLimitsMissing
125+
- controllerNames:
126+
- kube2iam
127+
- kube-flannel-ds
128+
rules:
129+
- runAsPrivileged
130+
- controllerNames:
131+
- kube-hunter
132+
rules:
133+
- hostPIDSet
134+
- controllerNames:
135+
- polaris
136+
- kube-hunter
137+
- goldilocks
138+
- insights-agent-goldilocks-vpa-install
139+
rules:
140+
- notReadOnlyRootFileSystem
141+
- controllerNames:
142+
- insights-agent-goldilocks-controller
143+
rules:
144+
- livenessProbeMissing
145+
- readinessProbeMissing
146+
- controllerNames:
147+
- insights-agent-goldilocks-vpa-install
148+
- kube-hunter
149+
rules:
150+
- runAsRootAllowed
151+
152+
---
153+
apiVersion: v1
154+
kind: ServiceAccount
155+
metadata:
156+
name: scanner-polaris
157+
namespace: joseki
158+
labels:
159+
app: scanner-polaris
160+
module: scanners
161+
162+
---
163+
apiVersion: rbac.authorization.k8s.io/v1beta1
164+
kind: ClusterRole
165+
metadata:
166+
name: scanner-polaris
167+
labels:
168+
app: scanner-polaris
169+
module: scanners
170+
rules:
171+
- apiGroups:
172+
- 'apps'
173+
- 'extensions'
174+
resources:
175+
- 'deployments'
176+
- 'statefulsets'
177+
- 'daemonsets'
178+
verbs:
179+
- 'get'
180+
- 'list'
181+
- apiGroups:
182+
- 'batch'
183+
resources:
184+
- 'jobs'
185+
- 'cronjobs'
186+
verbs:
187+
- 'get'
188+
- 'list'
189+
- apiGroups:
190+
- ''
191+
resources:
192+
- 'nodes'
193+
- 'namespaces'
194+
- 'pods'
195+
- 'replicationcontrollers'
196+
verbs:
197+
- 'get'
198+
- 'list'
199+
200+
---
201+
apiVersion: rbac.authorization.k8s.io/v1beta1
202+
kind: ClusterRoleBinding
203+
metadata:
204+
name: scanner-polaris
205+
labels:
206+
app: scanner-polaris
207+
module: scanners
208+
roleRef:
209+
apiGroup: rbac.authorization.k8s.io
210+
kind: ClusterRole
211+
name: scanner-polaris
212+
subjects:
213+
- kind: ServiceAccount
214+
name: scanner-polaris
215+
namespace: joseki
216+
217+
---
218+
apiVersion: batch/v1beta1
219+
kind: CronJob
220+
metadata:
221+
name: scanner-polaris
222+
namespace: joseki
223+
labels:
224+
app: scanner-polaris
225+
module: scanners
226+
version: 0.1.1
227+
spec:
228+
schedule: "0 2 * * *"
229+
jobTemplate:
230+
spec:
231+
template:
232+
spec:
233+
containers:
234+
- name: scanner-polaris
235+
image: deepnetwork/joseki-scanner-polaris:0.1.1-alpine
236+
imagePullPolicy: Always
237+
args:
238+
- --config
239+
- /app/scanner-polaris-config.yaml
240+
volumeMounts:
241+
- name: config
242+
mountPath: /app/scanner-polaris-config.yaml
243+
subPath: scanner-polaris-config.yaml
244+
readOnly: true
245+
- name: config
246+
mountPath: /app/polaris-config.yaml
247+
subPath: polaris-config.yaml
248+
readOnly: true
249+
volumes:
250+
- name: config
251+
configMap:
252+
name: scanner-polaris-cfg
253+
restartPolicy: Never
254+
serviceAccountName: scanner-polaris

src/scanners/polaris/dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM golang:1.13.7-alpine3.11 AS build-env
2+
WORKDIR /go/src/github.com/deepnetworkgmbh/joseki/src/scanners/polaris
3+
4+
COPY go.mod go.sum ./
5+
ENV GOMOD=/go/src/github.com/deepnetworkgmbh/joseki/src/scanners/polaris/go.mod
6+
RUN go mod download
7+
8+
COPY . .
9+
RUN go build -o scanner-polaris .
10+
11+
RUN apk --no-cache add ca-certificates
12+
13+
ENTRYPOINT ["./scanner-polaris"]

src/scanners/polaris/examples/scanner-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
scanner:
22
id: 8fc1b601-d5a2-466d-8236-c747c1dc02a2
33
periodicity: "0 2 * * *"
4-
heartbeat-periodicity: 7200
4+
heartbeat-periodicity: 86400
55
version: 0.1.0
66
polaris:
77
configPath: ./examples/polaris-config.yaml

src/scanners/polaris/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package main
33
import (
44
"flag"
55
"fmt"
6-
"github.com/deepnetworkgmbh/joseki/src/scanners/polaris/pkg/azureblob"
7-
"github.com/deepnetworkgmbh/joseki/src/scanners/polaris/pkg/scanner"
86
"log"
97
"os"
8+
9+
"github.com/deepnetworkgmbh/joseki/src/scanners/polaris/pkg/azureblob"
10+
"github.com/deepnetworkgmbh/joseki/src/scanners/polaris/pkg/scanner"
1011
)
1112

1213
const (
@@ -20,14 +21,17 @@ func main() {
2021
"./examples/scanner-config.yaml",
2122
"Location of Polaris scanner configuration file")
2223

24+
flag.Parse()
25+
2326
if *version {
2427
fmt.Printf("Polaris version %s\n", Version)
2528
os.Exit(0)
2629
}
2730

31+
log.Printf("Parsing config from %v", *configPath)
2832
config, err := scanner.ParseConfig(*configPath)
2933
if err != nil {
30-
log.Fatalf("Failed to parse configuration at %s %v", configPath, err)
34+
log.Fatalf("Failed to parse configuration at %s %v", *configPath, err)
3135
os.Exit(1)
3236
}
3337

0 commit comments

Comments
 (0)