-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
155 lines (146 loc) · 4.46 KB
/
index.ts
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import * as k8s from "@pulumi/kubernetes";
const zapNamespace = new k8s.core.v1.Namespace("zap", {
metadata: { name: 'zap' }
});
const zapGuiService = new k8s.core.v1.Service("zap-gui", {
metadata: {
name: "zap-gui",
namespace: zapNamespace.metadata.name
},
spec: {
type: 'LoadBalancer',
ports: [
{ name: 'proxy', port: 8090, protocol: 'TCP', targetPort: 8090 },
{ name: 'http', port: 8080, protocol: 'TCP', targetPort: 8080 },
],
selector: { app: "zap", mode: "gui" }
}
});
const zapGui = new k8s.core.v1.Pod("zap-gui", {
metadata: {
name: "zap-gui",
namespace: zapNamespace.metadata.name,
labels: { app: "zap", mode: "gui" },
},
spec: {
containers: [{
name: "zap-webswing",
image: "owasp/zap2docker-stable:2.10.0",
args: ['zap-webswing.sh'],
ports: [
{ containerPort: 8080 },
{ containerPort: 8090 },
]
}]
}
});
const zapApiService = new k8s.core.v1.Service("zap-api", {
metadata: {
name: "zap-api",
namespace: zapNamespace.metadata.name
},
spec: {
type: 'LoadBalancer',
ports: [
{ name: 'api', port: 9080, protocol: 'TCP', targetPort: 9080 },
],
selector: { app: "zap", mode: "api" }
}
});
const zapApiDaemon = new k8s.core.v1.Pod("zap-api", {
metadata: {
name: "zap-api",
namespace: zapNamespace.metadata.name,
labels: { app: "zap", mode: "api" }
},
spec: {
containers: [{
name: "zap",
image: "owasp/zap2docker-stable:2.10.0",
args: ['zap.sh', '-daemon',
'-port', '9080',
'-host', '0.0.0.0',
'-config', 'api.addrs.addr.name=.*',
'-config', 'api.addrs.addr.regex=true',
'-config', 'api.key=1qay2wsx3edc'],
ports: [{ containerPort: 9080 }]
}]
}
});
const apiScanCronJob = new k8s.batch.v1beta1.CronJob("zap-api-scan", {
metadata: {
name: "zap-api-scan",
namespace: zapNamespace.metadata.name
},
spec: {
schedule: "*/2 * * * *",
jobTemplate: {
spec: {
ttlSecondsAfterFinished: 120,
template: {
spec: {
containers: [{
name: "zap",
image: "owasp/zap2docker-stable:2.10.0",
args: [
"zap-api-scan.py",
"-t", "http://microservice.default.svc.cluster.local:8080/openapi/",
"-f", "openapi",
"-l", "INFO",
"-I"
]
}],
restartPolicy: "Never",
}
}
}
}
}
});
export const apiScanCronJobName = apiScanCronJob.metadata.name;
const microservice = new k8s.core.v1.Service("microservice", {
metadata: {
name: 'microservice'
},
spec: {
type: 'NodePort',
ports: [
{ name: 'http', port: 8080, protocol: 'TCP' },
],
selector: { app: "microservice" }
}
});
const deployment = new k8s.apps.v1.Deployment("microservice", {
metadata: {
labels: { app: "microservice" }
},
spec: {
replicas: 2,
selector: {
matchLabels: { app: "microservice" }
},
template: {
metadata: {
labels:{ app: "microservice" }
},
spec: {
containers: [{
name: 'microservice',
image: 'lreimer/continuous-zapk8s:latest',
imagePullPolicy: 'Always',
ports: [
{ name: 'http', containerPort: 8080 }
],
livenessProbe: {
initialDelaySeconds: 30,
httpGet: { port: 8080, path: '/health/liveness' }
},
readinessProbe: {
initialDelaySeconds: 15,
httpGet: { port: 8080, path: '/health/readiness' }
}
}]
}
}
}
});