-
Notifications
You must be signed in to change notification settings - Fork 2
287 lines (256 loc) · 12.9 KB
/
auto-test.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
name: Auto-testing
on:
push:
branches:
- "feature/auto_policy_testing"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
resource_priority_list:
type: string
description: Priority list for resources (you can remove unnecessary resources during testing)
default: '["storage", "webapp", "vnet", "network", "vm", "synapse", "sql", "mysql", "subscription", "disk", "postgresql", "cosmosdb", "signalr", "spring", "search", "service-fabric", "stream", "redis", "servicebus", "role", "monitor", "machine-learning", "logic", "kusto", "aks", "keyvault", "iothub", "front-door", "event", "data", "defender", "container", "cognitiveservice", "batch", "automation", "application", "app-configuration", "api", "alert"]'
#'["storage", "webapp", "vnet", "network", "vm", "synapse", "sql", "mysql", "subscription", "disk", "postgresql", "cosmosdb", "signalr", "spring", "search", "service-fabric", "stream", "redis", "servicebus", "role", "monitor", "machine-learning", "logic", "kusto", "aks", "keyvault", "iothub", "front-door", "event", "data", "defender", "container", "cognitiveservice", "batch", "automation", "application", "app-configuration", "api", "alert"]'
required: true
# limits to only one workflow in time
concurrency:
group: ${{ github.workflow }}
env:
AUTO_TEST_DIR: "auto_policy_testing"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_SECRET_VALUE: ${{ secrets.AZURE_SECRET_VALUE }}
default_resource_priority_list: '["storage", "webapp", "vnet", "network", "vm", "synapse", "sql", "mysql", "subscription", "disk", "postgresql", "cosmosdb", "signalr", "spring", "search", "service-fabric", "stream", "redis", "servicebus", "role", "monitor", "machine-learning", "logic", "kusto", "aks", "keyvault", "iothub", "front-door", "event", "data", "defender", "container", "cognitiveservice", "batch", "automation", "application", "app-configuration", "api", "alert"]'
#default_resource_priority_list: '["storage", "webapp", "vnet", "network", "vm", "synapse", "sql", "mysql", "subscription", "disk", "postgresql", "cosmosdb", "signalr", "spring", "search", "service-fabric", "stream", "redis", "servicebus", "role", "monitor", "machine-learning", "logic", "kusto", "aks", "keyvault", "iothub", "front-door", "event", "data", "defender", "container", "cognitiveservice", "batch", "automation", "application", "app-configuration", "api", "alert"]'
TF_VAR_project: ${{ secrets.TF_VAR_project }}
TF_VAR_region: ${{ secrets.AWS_REGION }}
TF_VAR_zone: ${{ secrets.TF_VAR_zone }}
TF_BACKEND_STORAGE_NAME: ${{ secrets.TF_BACKEND_STORAGE_NAME }}
TF_CLI_ARGS: "-no-color"
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }}
RED: '\033[0;31m'
ACTIONS_REPO_BRANCH: "main"
permissions:
contents: read # This is required for actions/checkout
id-token: write # This is required for requesting the JWT
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
deploy_common_resources:
name: Deploy common
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
compliance: ["green", "red"]
env:
COMPLINCE: ${{ matrix.compliance }}
RESOURCE: common_resources
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Checkout ecc-actions
run: git clone -b $ACTIONS_REPO_BRANCH "https://git:[email protected]/epmc-sec/cloudlab/cloud_custodian/ecc-actions.git" ecc-actions
env:
PROJECT_TOKEN: ${{ secrets.ECC_CHANGELOG_ACTION }}
ACTIONS_REPO_BRANCH: ${{ env.ACTIONS_REPO_BRANCH }}
- name: Deploy common
uses: ./ecc-actions/auto-test-actions/deploy-common-resources
with:
CI_ASSUME_ROLE: ${{ secrets.CI_ASSUME_ROLE }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
COMPLIANCE: ${{ matrix.compliance }}
# create_readonly_role_for_scans:
# name: Create readonly role for scans
# if: github.repository == 'epam/ecc-azure-rulepack'
# runs-on: ubuntu-22.04
# # needs: deploy_common_resources
# outputs:
# readonly_role_name: ${{ steps.create-readonly-role.outputs.readonly_role_name }}
# steps:
# - name: Git clone the repository
# uses: actions/checkout@v4
# - name: Checkout ecc-actions
# run: git clone -b $ACTIONS_REPO_BRANCH "https://git:[email protected]/epmc-sec/cloudlab/cloud_custodian/ecc-actions.git" ecc-actions
# env:
# PROJECT_TOKEN: ${{ secrets.ECC_CHANGELOG_ACTION }}
# ACTIONS_REPO_BRANCH: ${{ env.ACTIONS_REPO_BRANCH }}
# - name: Create readonly role for scans
# id: create-readonly-role
# uses: ./ecc-actions/auto-test-actions/readonly-role-for-scans
# with:
# CI_ASSUME_ROLE: ${{ secrets.CI_ASSUME_ROLE }}
# AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
# SERVICE_ACCOUNT: ${{ secrets.SERVICE_ACCOUNT }}
# WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
# COMPLIANCE: ${{ matrix.compliance }}
# PROJECT_TOKEN: ${{ secrets.CLOUDCUSTODIAN_CORE }}
# ROLE_ACTION: "create"
prepare_resource_matrix:
name: Prepare resource matrix
runs-on: ubuntu-22.04
needs: deploy_common_resources
outputs:
parallel_resources_list: ${{ steps.prepare-resource-matrix.outputs.parallel_resources_to_scan }}
not_parallel_resources_list: ${{ steps.prepare-resource-matrix.outputs.not_parallel_resources_to_scan }}
sequential_resources_list: ${{ steps.prepare-resource-matrix.outputs.sequential_resources_to_scan }}
sequential_resources_length: ${{ steps.prepare-resource-matrix.outputs.sequential_resources_length }}
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Checkout ecc-actions
run: git clone -b $ACTIONS_REPO_BRANCH "https://git:[email protected]/epmc-sec/cloudlab/cloud_custodian/ecc-actions.git" ecc-actions
env:
PROJECT_TOKEN: ${{ secrets.ECC_CHANGELOG_ACTION }}
ACTIONS_REPO_BRANCH: ${{ env.ACTIONS_REPO_BRANCH }}
- name: Prepare resource matrix
id: prepare-resource-matrix
uses: ./ecc-actions/auto-test-actions/prepare-resource-matrix
deploy_and_scan_parallel_resources:
name: Scan P
runs-on: ubuntu-22.04
needs: [ deploy_common_resources, prepare_resource_matrix ]
if: ${{ needs.prepare_resource_matrix.outputs.parallel_resources_list != '[]' }}
strategy:
max-parallel: 10
fail-fast: false
matrix:
compliance: ['green', 'red']
resource: ${{fromJson(needs.prepare_resource_matrix.outputs.parallel_resources_list)}}
env:
COMPLINCE: ${{ matrix.compliance }}
RESOURCE: ${{ matrix.resource }}
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Checkout ecc-actions
run: git clone -b $ACTIONS_REPO_BRANCH "https://git:[email protected]/epmc-sec/cloudlab/cloud_custodian/ecc-actions.git" ecc-actions
env:
PROJECT_TOKEN: ${{ secrets.ECC_CHANGELOG_ACTION }}
ACTIONS_REPO_BRANCH: ${{ env.ACTIONS_REPO_BRANCH }}
- name: Deploy and scan parallel resources
uses: ./ecc-actions/auto-test-actions/deploy-and-scan-resources
with:
CI_ASSUME_ROLE: ${{ secrets.CI_ASSUME_ROLE }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
COMPLIANCE: ${{ matrix.compliance }}
PROJECT_TOKEN: ${{ secrets.CLOUDCUSTODIAN_CORE }}
deploy_and_scan_not_parallel_resources:
name: Scan N/P
runs-on: ubuntu-22.04
needs: [ deploy_common_resources, prepare_resource_matrix]
if: ${{ needs.prepare_resource_matrix.outputs.not_parallel_resources_list != '[]' }}
strategy:
max-parallel: 1
fail-fast: false
matrix:
compliance: ['green', 'red']
resource: ${{fromJson(needs.prepare_resource_matrix.outputs.not_parallel_resources_list)}}
env:
COMPLINCE: ${{ matrix.compliance }}
RESOURCE: ${{ matrix.resource }}
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Checkout ecc-actions
run: git clone -b $ACTIONS_REPO_BRANCH "https://git:[email protected]/epmc-sec/cloudlab/cloud_custodian/ecc-actions.git" ecc-actions
env:
PROJECT_TOKEN: ${{ secrets.ECC_CHANGELOG_ACTION }}
ACTIONS_REPO_BRANCH: ${{ env.ACTIONS_REPO_BRANCH }}
- name: Deploy and scan non parallel resources
uses: ./ecc-actions/auto-test-actions/deploy-and-scan-resources
with:
CI_ASSUME_ROLE: ${{ secrets.CI_ASSUME_ROLE }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
COMPLIANCE: ${{ matrix.compliance }}
PROJECT_TOKEN: ${{ secrets.CLOUDCUSTODIAN_CORE }}
deploy_and_scan_sequential_resources:
name: Scan S
runs-on: ubuntu-22.04
needs: [deploy_common_resources, prepare_resource_matrix]
if: ${{ needs.prepare_resource_matrix.outputs.sequential_resources_list != '[]' }}
strategy:
fail-fast: false
matrix:
resource: ${{fromJson(needs.prepare_resource_matrix.outputs.sequential_resources_list)}}
env:
RESOURCE: ${{ matrix.resource }}
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Checkout ecc-actions
run: git clone -b $ACTIONS_REPO_BRANCH "https://git:[email protected]/epmc-sec/cloudlab/cloud_custodian/ecc-actions.git" ecc-actions
env:
PROJECT_TOKEN: ${{ secrets.ECC_CHANGELOG_ACTION }}
ACTIONS_REPO_BRANCH: ${{ env.ACTIONS_REPO_BRANCH }}
- name: Deploy and scan non-parallel resource (green)
uses: ./ecc-actions/auto-test-actions/deploy-and-scan-resources
env:
COMPLINCE: "green"
with:
CI_ASSUME_ROLE: ${{ secrets.CI_ASSUME_ROLE }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
COMPLIANCE: "green"
PROJECT_TOKEN: ${{ secrets.CLOUDCUSTODIAN_CORE }}
- name: Deploy and scan non-parallel resource (red)
uses: ./ecc-actions/auto-test-actions/deploy-and-scan-resources
env:
COMPLINCE: "red"
if: always()
with:
CI_ASSUME_ROLE: ${{ secrets.CI_ASSUME_ROLE }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
COMPLIANCE: "red"
PROJECT_TOKEN: ${{ secrets.CLOUDCUSTODIAN_CORE }}
# delete_readonly_role_for_scans:
# name: Delete readonly role for scans
# if: ${{ always() }}
# runs-on: ubuntu-22.04
# needs: [ create_readonly_role_for_scans ] #, deploy_and_scan_parallel_resources, deploy_and_scan_not_parallel_resources ]
# steps:
# - name: Git clone the repository
# uses: actions/checkout@v4
# - name: Checkout ecc-actions
# run: git clone -b $ACTIONS_REPO_BRANCH "https://git:[email protected]/epmc-sec/cloudlab/cloud_custodian/ecc-actions.git" ecc-actions
# env:
# PROJECT_TOKEN: ${{ secrets.ECC_CHANGELOG_ACTION }}
# ACTIONS_REPO_BRANCH: ${{ env.ACTIONS_REPO_BRANCH }}
# - name: Delete readonly role for scans
# uses: ./ecc-actions/auto-test-actions/readonly-role-for-scans
# with:
# CI_ASSUME_ROLE: ${{ secrets.CI_ASSUME_ROLE }}
# AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
# SERVICE_ACCOUNT: ${{ secrets.SERVICE_ACCOUNT }}
# WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
# COMPLIANCE: ${{ matrix.compliance }}
# PROJECT_TOKEN: ${{ secrets.CLOUDCUSTODIAN_CORE }}
# ROLE_ACTION: "delete"
# env:
# created_role_name: ${{ needs.create_readonly_role_for_scans.outputs.readonly_role_name }}
destroy_common_resources:
name: Destroy common
runs-on: ubuntu-22.04
needs: [deploy_and_scan_not_parallel_resources, deploy_and_scan_parallel_resources, deploy_and_scan_sequential_resources]
if: ${{ always() }}
strategy:
max-parallel: 10
fail-fast: false
matrix:
compliance: ["green", "red"]
env:
COMPLINCE: ${{ matrix.compliance }}
RESOURCE: common_resources
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Checkout ecc-actions
run: git clone -b $ACTIONS_REPO_BRANCH "https://git:[email protected]/epmc-sec/cloudlab/cloud_custodian/ecc-actions.git" ecc-actions
env:
PROJECT_TOKEN: ${{ secrets.ECC_CHANGELOG_ACTION }}
ACTIONS_REPO_BRANCH: ${{ env.ACTIONS_REPO_BRANCH }}
- name: Destroy common resources
uses: ./ecc-actions/auto-test-actions/destroy-common-resources
with:
CI_ASSUME_ROLE: ${{ secrets.CI_ASSUME_ROLE }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
COMPLIANCE: ${{ matrix.compliance }}