forked from malevarro/reactjs-shopping-cart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines-devsecops.yml
240 lines (217 loc) · 8.04 KB
/
azure-pipelines-devsecops.yml
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# Full Scan
# Pipeline para realizar análisis de código fuente, build de la imagen y análisis de la imagen de un contenedor
#
trigger:
- master
resources:
- repo: self
variables:
dockerRegistryServiceConnection: '26a65500-b05f-4a4c-a7dd-73a9e7a59dcb'
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
pool:
vmImage: $(vmImageName)
stages:
# Análisis del código fuente
- stage: CodeSecurityScan
displayName: Code Security Scan
jobs:
# Análisis con Mend
- job: Mend
displayName: Mend
pool:
vmImage: $(vmImageName)
steps:
- task: WhiteSource@21
inputs:
cwd: '$(System.DefaultWorkingDirectory)'
projectName: '$(MendProj)'
# Análisis con SonarCloud
- job: SonarCloud
displayName: SonarCloud
pool:
vmImage: $(vmImageName)
steps:
- checkout: self
fetchDepth: 0
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'SonarCloud'
organization: '$(SonarOrg)'
scannerMode: 'CLI'
configMode: 'manual'
cliProjectKey: '$(SonarProjKey)'
cliProjectName: '$(SonarProj)'
cliSources: '.'
- task: SonarCloudAnalyze@1
- task: SonarCloudPublish@1
inputs:
pollingTimeoutSec: '300'
# Análisis con Checkov
- job: Checkov
displayName: Checkov
pool:
vmImage: $(vmImageName)
steps:
- task: Bash@3
displayName: 'Install Checkov CLI'
inputs:
targetType: 'inline'
script: |
echo 'Install Checkov'
pip3 install checkov
mkdir checkov-report
- task: Bash@3
displayName: 'Checkov Dockerfile Analysis'
inputs:
targetType: 'inline'
script: |
checkov -d . --soft-fail --framework all --output junitxml > ./checkov-report/TEST-checkov-IaC-report.xml
- task: Bash@3
displayName: 'Checkov SCA Analysis'
inputs:
targetType: 'inline'
script: |
checkov -d . --soft-fail --framework sca_package --bc-api-key $(API) --output junitxml > ./checkov-report/TEST-checkov-SCA-report.xml
- task: PublishTestResults@2
displayName: 'Checkov Dockerfile Report'
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/TEST-checkov-IaC-report.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/checkov-report'
mergeTestResults: false
testRunTitle: 'Checkov Dockerfile Report'
failTaskOnFailedTests: false
publishRunAttachments: true
- task: PublishTestResults@2
displayName: 'Checkov SCA Report'
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/TEST-checkov-SCA-report.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/checkov-report'
mergeTestResults: false
testRunTitle: 'Checkov SCA Report'
failTaskOnFailedTests: false
publishRunAttachments: true
# Creación de imagen de contenedor
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
# Análisis de imagen de contenedor
- stage: ImageSecurityScan
displayName: Image Security Analysis
jobs:
# Análisis con Snyk
- job: Snyk
displayName: Snyk
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Registry Login
inputs:
containerRegistry: '$(containerRegistrys)'
command: 'login'
- task: SnykSecurityScan@1
inputs:
serviceConnectionEndpoint: 'SnykApp'
testType: 'container'
dockerImageName: '$(URL)/$(imageRepository):$(tag)'
dockerfilePath: '$(dockerfilePath)'
monitorWhen: 'always'
failOnIssues: false
# Análisis con Trivy
- job: Trivy
displayName: Trivy
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: 'Registry Login'
inputs:
containerRegistry: '$(containerRegistrys)'
command: 'login'
- task: trivy@1
inputs:
version: 'latest'
docker: false
exitCode: 0
image: $(URL)/$(imageRepository):$(tag)
debug: true
- task: Bash@3
displayName: Trivy CLI
inputs:
targetType: 'inline'
script: |
cd $(Build.SourcesDirectory)
mkdir $(sariflog)
export TRIVY_AUTH_URL=$(URL)
export TRIVY_USERNAME=$(USERNAME)
export TRIVY_PASSWORD=$(PASSWORD)
echo "[+] Fetching Trivy"
export TRIVYVERSION=$(git ls-remote --refs --sort="version:refname" --tags https://github.com/aquasecurity/trivy | cut -d/ -f3-|tail -n1 | sed -e 's/^.//')
echo "[+] Trivy Version:" ${TRIVYVERSION}
wget -nv --no-cache https://github.com/aquasecurity/trivy/releases/download/v${TRIVYVERSION}/trivy_${TRIVYVERSION}_Linux-64bit.deb
echo "[+] Installing Trivy"
sudo dpkg -i trivy_${TRIVYVERSION}_Linux-64bit.deb
echo "[+] Trivy Installed "${TRIVYVERSION}
echo "[+] Running Trivy"
echo "***Vulneability Assesment***"
echo "[+] Creating Trivy Vulnerabilities"
trivy --quiet image --format sarif -o $(sariflog)/Trivy_Vulnerabilities.sarif --exit-code 0 $(URL)/$(imageRepository):$(tag)
echo "***License Inventory***"
echo "[+] Creating Trivy License Inventory"
trivy --quiet image -f table --scanners license --license-full --exit-code 0 $(URL)/$(imageRepository):$(tag) > $(sariflog)/License_Report.txt
echo "***Docker Compliance Analysis***"
echo "[+] Creating Trivy Docker Compliance File"
trivy --quiet image -f table --compliance docker-cis $(URL)/$(imageRepository):$(tag) > $(sariflog)/CIS_Compliance_Report.txt
echo "***Dockerfile Analysis***"
echo "[+] Creating Dockerfile Compliance"
trivy --quiet --format sarif -o $(sariflog)/Compliance_Dockerfile_Report.sarif config $(dockerfilePath)
echo "***SBOM Analysis***"
echo "[+] Creating Trivy SBOM JSON File"
trivy --quiet image --list-all-pkgs --scanners vuln --format cyclonedx --output $(sariflog)/SBOM_Cyclonedx_Report.json --exit-code 0 $(URL)/$(imageRepository):$(tag)
- task: PublishPipelineArtifact@1
inputs:
targetPath: './$(sariflog)'
artifact: '$(sariflog)'
publishLocation: 'pipeline'
#Publicando la aplicacion en Azure
- stage: DeployWebApp
displayName: Deploy Web App
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: $(vmImageName)
steps:
- task: AzureRmWebAppDeployment@4
displayName: Deploy Web App Service
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'AzureVS'
appType: 'webAppContainer'
WebAppName: '$(WebAppSvc)'
DockerNamespace: '$(URL)'
DockerRepository: '$(imageRepository)'
DockerImageTag: '$(tag)'
AppSettings: '-port 3000'
- task: AzureAppServiceManage@0
displayName: Restart Web App Service
inputs:
azureSubscription: 'AzureVS'
Action: 'Restart Azure App Service'
WebAppName: '$(WebAppSvc)'