-
Notifications
You must be signed in to change notification settings - Fork 9
392 lines (390 loc) · 16.4 KB
/
ansible-playbook.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
name: ansible-playbook
on: [push, pull_request]
env:
ANSIBLE_FORCE_COLOR: '1'
jobs:
# Performing test ID BANN-7126 (Check issue banner file contents)
# Test: Checking file /etc/issue contents for legal key words
# Result: found string 'authori'
# Result: found string 'monitor'
# Result: found string 'report'
# Result: Found only 3 key words (5 or more suggested), to warn unauthorized users and could be increased
# Suggestion: Add a legal banner to /etc/issue, to warn unauthorized users [test:BANN-7126] [details:-] [solution:-]
# Hardening: assigned partial number of hardening points (0 of 1). Currently having 0 points (out of 1)
#
# Performing test ID BANN-7130 (Check issue.net banner file contents)
# Test: Checking file /etc/issue.net contents for legal key words
# Result: found string 'authori'
# Result: found string 'monitor'
# Result: found string 'report'
# Result: Found only 3 key words, to warn unauthorized users and could be increased
# Suggestion: Add legal banner to /etc/issue.net, to warn unauthorized users [test:BANN-7130] [details:-] [solution:-]
# Hardening: assigned partial number of hardening points (0 of 1). Currently having 0 points (out of 2)
banners:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Ansible playbook for banners
run: ansible-playbook -v harden.yml --tags banners --extra-vars run_lynis_after_hardening=true
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-banner.log
path: /var/log/lynis.log
authentication:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group authentication
- name: Run Ansible playbook for passwords, pam & umask
run: ansible-playbook harden.yml --tags passwords,pam,umask,accounts --skip-tags slackware,centos
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group authentication
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: authentication
# We can't use common-* here because "Error: The path for one of the files in artifact is not valid: etc/pam.d/common-auth.10050.2024-12-18@17:28:53~. Contains the following character: Colon :"
path: |
/var/log/lynis.log
/etc/pam.d/common-account
/etc/pam.d/common-auth
/etc/pam.d/common-password
/etc/pam.d/common-session
# 2025-01-08 20:44:29 Performing test ID AUTH-9229 (Check password hashing methods)
# 2025-01-08 20:44:29 Test: Checking password hashing methods
# 2025-01-08 20:44:29 Result: poor password hashing methods found: sha256crypt/sha512crypt(default=5000rounds)
# 2025-01-08 20:44:29 Suggestion: Check PAM configuration, add rounds if applicable and expire passwords to encrypt with new values [test:AUTH-9229] [details:-] [solution:-]
# 2025-01-08 20:44:29 Hardening: assigned partial number of hardening points (0 of 2). Currently having 2 points (out of 4)
- name: Check Lynis score
run: sudo bash tests/check_lynis_score.sh 93
accounting:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group accounting
- name: Run Ansible playbook for accounting, audit & sysstat
run: ansible-playbook harden.yml --tags accounting,audit,sysstat --skip-tags slackware,centos
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group accounting
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-accounting.log
path: /var/log/lynis.log
- name: Check Lynis score
run: sudo bash tests/check_lynis_score.sh 100
# The only test that would be (positively) scored in this category is SCHD-7720,
# but that test is skipped if/when atd is not running.
scheduling:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group scheduling
- name: Run Ansible playbook for cron
run: ansible-playbook harden.yml --tags cron --skip-tags slackware
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group scheduling
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-scheduling.log
path: /var/log/lynis.log
shells:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group shells
- name: Run Ansible playbook for umask & shells
run: ansible-playbook harden.yml --tags umask,shells --skip-tags slackware
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group shells
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-shells.log
path: /var/log/lynis.log
- name: Check Lynis score
run: sudo bash tests/check_lynis_score.sh 100
malware:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group malware
- name: Install jmespath
run: sudo pipx inject ansible-core jmespath
- name: Run Ansible playbook for clamav, rkhunter & chkrootkit
run: ansible-playbook harden.yml --tags clamav,rkhunter,chkrootkit --skip-tags slackware,yara
- name: Run rkhunter
run: sudo rkhunter --check --skip-keypress
- name: Check rkhunter.log for warnings
run: sudo grep '\[ Warning \]$' /var/log/rkhunter.log
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group malware
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-malware.log
path: |
/var/log/lynis.log
/var/log/rkhunter.log
# MALW-3280
# 2025-01-08 21:22:22 Result: no commercial anti-virus tools found
# 2025-01-08 21:22:22 Hardening: assigned partial number of hardening points (0 of 3). Currently having 4 points (out of 7)
- name: Check Lynis score
run: sudo bash tests/check_lynis_score.sh 66
mac_frameworks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group mac_frameworks
- name: Run Ansible playbook for apparmor
run: ansible-playbook harden.yml --tags apparmor
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group mac_frameworks
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-mac_frameworks.log
path: /var/log/lynis.log
- name: Check Lynis score
run: sudo bash tests/check_lynis_score.sh 100
# Not scored
file_permissions:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group file_permissions
- name: Run Ansible playbook for cron & permissions
run: ansible-playbook harden.yml --tags cron,permissions --skip-tags slackware
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group file_permissions
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-file_permissions.log
path: /var/log/lynis.log
# Not scored
homedirs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group homedirs
- name: Run Ansible playbook for permissions
run: ansible-playbook harden.yml --tags permissions --skip-tags slackware
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group homedirs
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-homedirs.log
path: /var/log/lynis.log
kernel_hardening:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group kernel_hardening
- name: Run Ansible playbook for kernel
run: ansible-playbook harden.yml --tags kernel
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group kernel_hardening
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-kernel_hardening.log
path: /var/log/lynis.log
- name: Check Lynis score
run: sudo bash tests/check_lynis_score.sh 94
file_integrity:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group file_integrity
- name: Run Ansible playbook for aide
run: ansible-playbook harden.yml --tags aide
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group file_integrity
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-file_integrity.log
path: /var/log/lynis.log
- name: Check Lynis score
run: sudo bash tests/check_lynis_score.sh 100
storage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group storage
- name: Run Ansible playbook for kernel
run: ansible-playbook harden.yml --tags kernel
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group storage
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-storage.log
path: /var/log/lynis.log
- name: Check Lynis score
run: sudo bash tests/check_lynis_score.sh 100
#firewalls:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Install Lynis
# run: |
# ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
# echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
# - name: Run Lynis (pre-harden)
# run: sudo lynis audit system --skip-plugins --tests-from-group firewalls
# - name: Run Ansible playbook for network
# run: ansible-playbook harden.yml --tags firewall --skip-tags slackware
# - name: Run Lynis
# run: sudo lynis audit system --skip-plugins --tests-from-group firewalls
# - name: chmod Lynis log
# run: sudo chmod -c 644 /var/log/lynis.log
# - name: Archive Lynis log
# uses: actions/upload-artifact@v4
# with:
# name: lynis-firewalls.log
# path: /var/log/lynis.log
#almost-whole-playbook:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Install Lynis
# run: |
# ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
# echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
# - name: Run Lynis (pre-harden)
# run: sudo lynis audit system --skip-plugins
# - name: Run Ansible playbook
# run: ansible-playbook harden.yml --skip-tags slackware,centos,lynis,firewall,yara,sudo
# - name: Run Lynis
# run: sudo lynis audit system --skip-plugins
# - name: chmod Lynis log
# run: sudo chmod -c 644 /var/log/lynis.log
# - name: Archive Lynis log
# uses: actions/upload-artifact@v4
# with:
# name: lynis.log
# path: /var/log/lynis.log
ssh:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Lynis
run: |
ansible-playbook harden.yml --tags lynis --skip-tags slackware,centos
echo 'skip-upgrade-test=yes' | sudo tee -a /etc/lynis/custom.prf
- name: Run Lynis (pre-harden)
run: sudo lynis audit system --skip-plugins --tests-from-group ssh
- name: Run Ansible playbook for SSH
run: ansible-playbook harden.yml --tags ssh
- name: Run Lynis
run: sudo lynis audit system --skip-plugins --tests-from-group ssh
- name: chmod Lynis log
run: sudo chmod -c 644 /var/log/lynis.log
- name: Archive Lynis log
uses: actions/upload-artifact@v4
with:
name: lynis-ssh.log
path: /var/log/lynis.log