forked from Normation/rudder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-security
217 lines (195 loc) · 8.24 KB
/
Jenkinsfile-security
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
def version = "8.0"
def slackResponse = slackSend(channel: "ci-security", message: "${version} - dependency check - <"+currentBuild.absoluteUrl+"|Link>", color: "#00A8E1")
def errors = []
def running = []
def changeUrl = env.CHANGE_URL
updateSlack(errors, running, slackResponse, version, changeUrl)
// Check vulns in dependencies on repo branches
def failedBuild = false
pipeline {
agent none
triggers { cron('@daily') }
stages {
stage('deps-webapp') {
when { not { changeRequest() } }
agent {
dockerfile {
filename 'webapp/sources/Dockerfile'
additionalBuildArgs "--build-arg USER_ID=${JENKINS_UID}"
// and share maven cache
args '-v /srv/cache/maven:/home/jenkins/.m2'
}
}
steps {
script {
running.add("webapp")
updateSlack(errors, running, slackResponse, version, changeUrl)
}
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('webapp/sources') {
sh script: 'mvn --batch-mode -DfailBuildOnCVSS=7 -DcveValidForHours=48 -DsuppressionFiles=dependency-check-suppression.xml -DossindexAnalyzerEnabled=false org.owasp:dependency-check-maven:aggregate', label: "check webapp dependencies"
sh script: 'mvn --batch-mode license:aggregate-third-party-report', label: 'list webapp dependencies'
}
}
}
post {
always {
archiveArtifacts artifacts: 'webapp/sources/target/dependency-check-report.html, webapp/sources/target/site/aggregate-third-party-report.html'
}
failure {
script {
errors.add("webapp")
webapp = false
failedBuild = true
//notifier.notifyResult("scala-team")
slackSend(channel: slackResponse.threadId, message: "Dependency check error on webapp - <${currentBuild.absoluteUrl}console|Console>", color: "#CC3421")
}
}
cleanup {
script {
running.remove("webapp")
updateSlack(errors, running, slackResponse, version, changeUrl)
}
}
}
}
stage('deps-npm') {
when { not { changeRequest() } }
agent {
dockerfile {
filename 'webapp/sources/Dockerfile'
additionalBuildArgs "--build-arg USER_ID=${JENKINS_UID}"
// and share maven cache
args '-v /srv/cache/maven:/home/jenkins/.m2'
}
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('webapp/sources/rudder/rudder-web/src/main/') {
sh script: 'npm_config_loglevel=error npm ci --no-audit', label: "install dependencies"
sh script: 'npx better-npm-audit audit --level high', label: "check npm dependencies"
}
}
}
post {
failure {
script {
npm = false
failedBuild = true
//notifier.notifyResult("scala-team")
slackSend(channel: slackResponse.threadId, message: "Dependency check error on npm - <${currentBuild.absoluteUrl}console|Console>", color: "#CC3421")
}
}
}
}
stage('deps-relayd') {
when { not { changeRequest() } }
agent {
dockerfile {
filename 'relay/sources/relayd/Dockerfile'
additionalBuildArgs "--build-arg USER_ID=${JENKINS_UID}"
// mount cache
args '-v /srv/cache/cargo:/usr/local/cargo/registry'
}
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('relay/sources/relayd') {
sh script: 'mkdir -p target', label: 'create target directory'
sh script: 'cargo deny check', label: 'check relayd dependencies'
sh script: 'cargo deny list > target/relayd-dependencies.txt', label: 'list relayd dependencies'
}
}
}
post {
failure {
script {
errors.add("relay")
failedBuild = true
slackSend(channel: slackResponse.threadId, message: "Dependency check error on relayd - <${currentBuild.absoluteUrl}console|Console>", color: "#CC3421")
//notifier.notifyResult("rust-team")
}
}
cleanup {
script {
running.remove("relay")
updateSlack(errors, running, slackResponse, version, changeUrl)
}
}
always {
archiveArtifacts artifacts: 'relay/sources/relayd/target/relayd-dependencies.txt'
}
}
}
stage('deps-policies') {
when { not { changeRequest() } }
agent {
dockerfile {
filename 'policies/Dockerfile'
additionalBuildArgs "--build-arg USER_ID=${JENKINS_UID}"
// mount cache
args '-v /srv/cache/cargo:/usr/local/cargo/registry'
}
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('policies') {
sh script: 'mkdir -p target', label: 'create target directory'
sh script: 'cargo deny check', label: 'check policies dependencies'
sh script: 'cargo deny list > target/policies-dependencies.txt', label: 'list policies dependencies'
}
}
}
post {
failure {
script {
errors.add("policies")
failedBuild = true
//notifier.notifyResult("rust-team")
slackSend(channel: slackResponse.threadId, message: "Dependency check error on policies - <${currentBuild.absoluteUrl}console|Console>", color: "#CC3421")
}
}
cleanup {
script {
running.remove("policies")
updateSlack(errors, running, slackResponse, version, changeUrl)
}
}
always {
archiveArtifacts artifacts: 'policies/target/policies-dependencies.txt'
}
}
}
stage('End') {
steps {
script {
if (failedBuild) {
error 'End of build'
} else {
echo 'End of build '
}
}
}
}
}
}
def updateSlack(errors, running, slackResponse, version, changeUrl) {
echo env.CHANGE_URL
def msg ="*${version} - dependency check* - <"+currentBuild.absoluteUrl+"|Link>"
if (changeUrl != null) {
msg ="*${version} PR - dependency check* - <"+currentBuild.absoluteUrl+"|Link> - <"+changeUrl+"|Pull request>"
}
def color = "#00A8E1"
if (! errors.isEmpty()) {
msg += "\n*Errors* :x: ("+errors.size()+")\n • " + errors.join("\n • ")
color = "#CC3421"
}
if (! running.isEmpty()) {
msg += "\n*Running* :arrow_right: ("+running.size()+")\n • " + running.join("\n • ")
}
if (errors.isEmpty() && running.isEmpty()) {
msg += " => All dependencies checked! :white_check_mark:"
color = "good"
}
slackSend(channel: slackResponse.channelId, message: msg, timestamp: slackResponse.ts, color: color)
}