Repository navigation
244 lines (201 loc) · 7.92 KB
/
Copy pathcode-security.yml
File metadata and controls
244 lines (201 loc) · 7.92 KB
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
241
242
243
244
name: workshop
on:
workflow_dispatch:
env:
URL_GITLEAKS_RELEASE: 'https://github.com/gitleaks/gitleaks/releases/download/v8.28.0/gitleaks_8.28.0_linux_x64.tar.gz'
DIR_DOCKERFILE: './src/ConsoleAppJobHttpRequest'
DIR_DEVOPS_ARTIFACTS: './devops'
DIR_TESTS: './tests'
jobs:
secrets_scanning:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout Code
- name: Instalar o Gitleaks
run: |
mkdir tmp-gitleaks
cd tmp-gitleaks
echo ''
echo "Url utilizada para download do Gitleaks: ${{ env.URL_GITLEAKS_RELEASE }}"
echo ''
curl -L -o gitleaks.tar.gz ${{ env.URL_GITLEAKS_RELEASE }}
tar -xvzf gitleaks.tar.gz
ls
chmod +x gitleaks
sudo mv gitleaks /usr/local/bin/
cd ..
rm -rf tmp-gitleaks
- name: Testar o Gitleaks
run: |
gitleaks --version
echo ''
gitleaks --help
- name: Criar diretorio results
run: mkdir results
- name: Executar o Gitleaks no repositorio
run: |
curl -L -o ./results/report-basic.tmpl https://raw.githubusercontent.com/gitleaks/gitleaks/refs/heads/master/report_templates/basic.tmpl
gitleaks dir . \
--report-format=sarif \
--report-path=./results/results-secrets.sarif
- name: Exibir conteudo do diretorio results
if: always()
run: |
cd results
pwd
ls -l
- name: Upload arquivo SARIF file
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ./results/results-secrets.sarif
category: sast-tools
dockerfile_scanning:
needs: secrets_scanning
runs-on: ubuntu-latest
if: always()
steps:
- uses: actions/checkout@v4
- name: Instalar o Checkov via pip
run: pip install checkov
- name: Testar a instalacao do Checkov
run: |
checkov
checkov --help
- name: Criar diretorio results
run: mkdir results
- name: Executar analise com o Checkov
run: |
echo 'Vulnerabilidades que serao ignoradas ao executar o Checkov:'
echo '* CKV_DOCKER_2 - Ensure that HEALTHCHECK instructions have been added to container images'
echo '* CKV_DOCKER_3 - Ensure that the image is not built from a local context'
echo
checkov -d ${{ env.DIR_DOCKERFILE }} \
--framework dockerfile \
--skip-check CKV_DOCKER_2,CKV_DOCKER_3 \
-o cli -o sarif \
--output-file-path ./results/results-dockerfile.sarif
- name: Exibir arquivos gerados em /results
if: always()
run: |
cd results
pwd
echo
echo
ls -l
- name: Upload arquivo SARIF file
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ./results/results-dockerfile.sarif
category: sast-tools
kubernetes_yaml_scanning:
needs: dockerfile_scanning
runs-on: ubuntu-latest
if: always()
steps:
- uses: actions/checkout@v4
- name: Baixa a imagem do KICS
run: docker pull checkmarx/kics:latest
- name: Exibir imagens no ambiente local
run: docker images
- name: Exibir opcoes da linha de comando do KICS
run: docker run -t checkmarx/kics scan --help
- name: Configurar permissoes de diretorio para uso do KICS
run: |
cd ${{ env.DIR_DEVOPS_ARTIFACTS }}
echo '**** Diretorio:'
echo $PWD
echo ''
chmod -R 777 .
echo 'Permissoes apos ajustes'
ls -ld
- name: Configurar permissoes de diretorio para uso do KICS
run: |
echo 'Vulnerabilidades que serao ignoradas ao executar o KICS:'
echo '* 611ab018-c4aa-4ba2-b0f6-a448337509a6 - Namespaces like default, kube-system or kube-public should not be used'
echo '* 48471392-d4d0-47c0-b135-cdec95eb3eef - Service Account Token Automount Not Disabled'
echo '* f377b83e-bd07-4f48-a591-60c82b14a78b - Seccomp Profile Is Not Configured'
echo '* dbbc6705-d541-43b0-b166-dd4be8208b54 - NET_RAW Capabilities Not Being Dropped'
echo '* 02323c00-cdc3-4fdc-a310-4f2b3e7a1660 - Container Running With Low UID'
echo '* cf34805e-3872-4c08-bf92-6ff7bb0cfadb - Containers should only run as non-root user'
echo
cd ${{ env.DIR_DEVOPS_ARTIFACTS }}
docker run -t -v $PWD:/path checkmarx/kics scan -p /path -o "/path/" \
--exclude-severities low,info,trace \
--exclude-queries 611ab018-c4aa-4ba2-b0f6-a448337509a6,48471392-d4d0-47c0-b135-cdec95eb3eef,f377b83e-bd07-4f48-a591-60c82b14a78b,dbbc6705-d541-43b0-b166-dd4be8208b54,02323c00-cdc3-4fdc-a310-4f2b3e7a1660,cf34805e-3872-4c08-bf92-6ff7bb0cfadb \
--report-formats pdf --output-name results-kubernetes \
--type Kubernetes
- name: Exibir arquivos apos execucao do KICS
if: always()
run: |
cd ${{ env.DIR_DEVOPS_ARTIFACTS }}
pwd
echo
echo
ls -l
- name: Upload do relatorio PDF do KICS com resultados da analise
if: always()
uses: actions/upload-artifact@v4.6.2
with:
name: 'results-kubernetes'
path: ${{ env.DIR_DEVOPS_ARTIFACTS }}/results-kubernetes.pdf
tests:
needs: kubernetes_yaml_scanning
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build da imagem da aplicacao
run: |
cd ${{ env.DIR_DOCKERFILE }}
docker build . -t workshop/job-httprequest:$GITHUB_RUN_NUMBER
- name: Exibir imagens no ambiente apos build
run: |
docker images
- name: Verificar se o kind esta instalado
run: kind
- name: Criar cluster de testes com o kind
run: |
cd ${{ env.DIR_TESTS }}
kind create cluster --name kind-01 --config=kind-cluster-config-automation-env.yaml
- name: Testar o cluster Kubernetes criado com o kind
run: |
echo ' '
echo 'Cluster Kubernetes local em funcionamento...'
echo ' '
kubectl get services
- name: Exibir containers em execucao
run: docker container ls
- name: Carregar imagem no cluster criado com kind
run: |
kind load docker-image workshop/job-httprequest:$GITHUB_RUN_NUMBER --name kind-01
- name: Criar namespace integrationtests
run: |
kubectl create namespace integrationtests
kubectl get namespaces
- name: Exibir conteudo do arquivo YAML de deployment antes dos ajustes
run: cat ${{ env.DIR_DEVOPS_ARTIFACTS }}/job-teste.yaml
- name: Ajustar arquivo YAML de deployment
uses: cschleiden/replace-tokens@v1
with:
files: '["**/job-teste.yaml"]'
- name: Exibir conteudo do arquivo YAML de deployment apos ajustes
run: cat ${{ env.DIR_DEVOPS_ARTIFACTS }}/job-teste.yaml
- name: Deployment do Job no ambiente de testes - namespace integrationtests
run: |
cd ${{ env.DIR_DEVOPS_ARTIFACTS }}
kubectl apply -f job-teste.yaml -n integrationtests
- name: Verificar deployment do Job no ambiente de testes - namespace integrationtests
run: |
kubectl get all -n integrationtests
kubectl get jobs -n integrationtests
echo ' '
echo 'Aguardando a inicialização dos serviços no cluster...'
echo ' '
sleep 45s
kubectl get all -n integrationtests
kubectl get jobs -n integrationtests
- name: Exibir logs do Job no ambiente de testes - namespace integrationtests
run: |
kubectl logs job.batch/exemplo-job -n integrationtests