-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
284 lines (249 loc) · 9.11 KB
/
Copy pathazure-pipelines.yml
File metadata and controls
284 lines (249 loc) · 9.11 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
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
# Azure Pipeline for Lab 08: Docker Network Security
# Tests all 5 scenarios to ensure they work correctly
trigger:
branches:
include:
- main
- develop
paths:
include:
- labs/08-network-security/**
pr:
branches:
include:
- main
- develop
paths:
include:
- labs/08-network-security/**
pool:
vmImage: 'ubuntu-latest'
variables:
LAB_DIR: 'labs/08-network-security'
stages:
- stage: ValidateScripts
displayName: 'Validate Scripts'
jobs:
- job: ShellCheck
displayName: 'Run ShellCheck on Demo Scripts'
steps:
- script: |
sudo apt-get update
sudo apt-get install -y shellcheck
displayName: 'Install ShellCheck'
- script: |
cd $(LAB_DIR)
shellcheck demo-*.sh cleanup.sh run-all-demos.sh || true
displayName: 'Analyze Shell Scripts'
- stage: TestScenarios
displayName: 'Test Network Security Scenarios'
dependsOn: ValidateScripts
jobs:
- job: Scenario1
displayName: 'Scenario 1: Network Isolation'
timeoutInMinutes: 10
steps:
- script: |
cd $(LAB_DIR)
chmod +x demo-isolation.sh cleanup.sh
# Run in non-interactive mode (auto-confirm all pauses)
yes "" | timeout 300 ./demo-isolation.sh || true
./cleanup.sh
displayName: 'Run Scenario 1'
- script: |
# Verify no containers left running
if docker ps -a | grep -E "web-frontend|web-backend|api"; then
echo "ERROR: Containers not cleaned up"
exit 1
fi
displayName: 'Verify Cleanup'
- job: Scenario2
displayName: 'Scenario 2: Multi-Tier Segmentation'
timeoutInMinutes: 10
steps:
- script: |
cd $(LAB_DIR)
chmod +x demo-segmentation.sh cleanup.sh
yes "" | timeout 300 ./demo-segmentation.sh || true
./cleanup.sh
displayName: 'Run Scenario 2'
- script: |
if docker ps -a | grep -E "public-net|app-net|database-net"; then
echo "ERROR: Networks not cleaned up"
exit 1
fi
displayName: 'Verify Cleanup'
- job: Scenario3
displayName: 'Scenario 3: Internal Networks'
timeoutInMinutes: 10
steps:
- script: |
cd $(LAB_DIR)
chmod +x demo-internal-network.sh cleanup.sh
yes "" | timeout 300 ./demo-internal-network.sh || true
./cleanup.sh
displayName: 'Run Scenario 3'
- job: Scenario4
displayName: 'Scenario 4: TLS Encryption'
timeoutInMinutes: 10
steps:
- script: |
set -e
echo "=== Diagnostic Information ==="
echo "Current directory: $(pwd)"
echo "LAB_DIR value: $(LAB_DIR)"
# Navigate to lab directory
cd $(System.DefaultWorkingDirectory)/$(LAB_DIR)
echo "After cd to LAB_DIR: $(pwd)"
echo "Directory contents:"
ls -la
# Check if certs directory exists
if [ ! -d "certs" ]; then
echo "ERROR: certs directory does not exist!"
echo "Creating certs directory..."
mkdir -p certs
fi
# Make scripts executable
chmod +x demo-tls-encryption.sh cleanup.sh
if [ -f "certs/generate-certs.sh" ]; then
chmod +x certs/generate-certs.sh
else
echo "WARNING: certs/generate-certs.sh not found"
echo "Contents of certs directory:"
ls -la certs/ || echo "Cannot list certs directory"
exit 1
fi
# Generate certificates
echo "=== Generating TLS Certificates ==="
cd certs
./generate-certs.sh
cd ..
# Verify certificates exist
echo "=== Verifying Certificate Files ==="
if [ ! -f "certs/server-cert.pem" ] || [ ! -f "certs/server-key.pem" ]; then
echo "ERROR: Certificate generation failed"
echo "Contents of certs directory:"
ls -la certs/
exit 1
fi
echo "SUCCESS: Certificates generated"
ls -lh certs/*.pem
displayName: 'Generate and Verify Certificates'
- script: |
cd $(System.DefaultWorkingDirectory)/$(LAB_DIR)
yes "" | timeout 300 ./demo-tls-encryption.sh || true
displayName: 'Run Scenario 4'
- script: |
cd $(System.DefaultWorkingDirectory)/$(LAB_DIR)
./cleanup.sh
displayName: 'Cleanup'
- job: Scenario5
displayName: 'Scenario 5: Common Misconfigurations'
timeoutInMinutes: 10
steps:
- script: |
cd $(LAB_DIR)
chmod +x demo-misconfigurations.sh cleanup.sh
yes "" | timeout 300 ./demo-misconfigurations.sh || true
./cleanup.sh
displayName: 'Run Scenario 5'
- stage: TestDockerCompose
displayName: 'Test Docker Compose'
dependsOn: TestScenarios
jobs:
- job: SecureCompose
displayName: 'Test Secure Compose'
steps:
- script: |
cd $(System.DefaultWorkingDirectory)/$(LAB_DIR)
docker compose -f docker-compose.yml up -d
sleep 10
docker compose -f docker-compose.yml ps
docker compose -f docker-compose.yml down -v
displayName: 'Test Secure Docker Compose'
- job: ValidateInsecureCompose
displayName: 'Validate Insecure Compose (Educational)'
steps:
- script: |
cd $(System.DefaultWorkingDirectory)/$(LAB_DIR)
# Just validate syntax, don't run (it's intentionally insecure)
docker compose -f docker-compose.insecure.yml config > /dev/null
echo "Insecure compose file syntax is valid"
displayName: 'Validate Insecure Compose Syntax'
- stage: IntegrationTest
displayName: 'Integration Test - Run All'
dependsOn: TestDockerCompose
condition: succeededOrFailed()
jobs:
- job: RunAllScenarios
displayName: 'Run Master Script'
timeoutInMinutes: 30
steps:
- script: |
cd $(LAB_DIR)
chmod +x run-all-demos.sh cleanup.sh
# Run master script in non-interactive mode
yes "" | timeout 1800 ./run-all-demos.sh || true
./cleanup.sh
displayName: 'Run All Scenarios'
- script: |
# Final verification - no resources left
echo "Checking for leftover containers..."
docker ps -a
echo "Checking for leftover networks..."
docker network ls
# Cleanup any remaining test resources
docker rm -f $(docker ps -aq) 2>/dev/null || true
docker network prune -f
displayName: 'Final Cleanup and Verification'
- stage: Documentation
displayName: 'Validate Documentation'
dependsOn: []
jobs:
- job: CheckREADME
displayName: 'Validate README'
steps:
- script: |
cd $(LAB_DIR)
if [ ! -f "README.md" ]; then
echo "ERROR: README.md not found"
exit 1
fi
# Check README has minimum content
if [ $(wc -l < README.md) -lt 100 ]; then
echo "WARNING: README seems incomplete"
fi
echo "README.md validated"
displayName: 'Check README Exists'
- job: CheckScripts
displayName: 'Verify All Scripts Present'
steps:
- script: |
cd $(LAB_DIR)
REQUIRED_SCRIPTS=(
"demo-isolation.sh"
"demo-segmentation.sh"
"demo-internal-network.sh"
"demo-tls-encryption.sh"
"demo-misconfigurations.sh"
"cleanup.sh"
"run-all-demos.sh"
)
MISSING=0
for script in "${REQUIRED_SCRIPTS[@]}"; do
if [ ! -f "$script" ]; then
echo "ERROR: Missing script: $script"
MISSING=1
fi
done
if [ $MISSING -eq 1 ]; then
exit 1
fi
echo "All required scripts present"
displayName: 'Verify Scripts Exist'
# Pipeline success criteria:
# - All shell scripts pass shellcheck (warnings allowed)
# - All 5 scenarios run without errors
# - Docker Compose files are valid
# - All resources cleaned up after tests
# - Documentation is present