Skip to content

Commit fd0e042

Browse files
authored
Merge pull request #3190 from marcstern/v2/pr/ci_log
CI improvement: First check syntax & always display error/audit logs
2 parents e7e11d9 + 110b61f commit fd0e042

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.github/security2.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ LoadModule security2_module /usr/lib/apache2/modules/mod_security2.so
44
SecDataDir /var/cache/modsecurity
55
Include /etc/apache2/modsecurity.conf
66
</IfModule>
7+
8+
SecAuditLog /var/log/apache2/modsec_audit.log

.github/workflows/ci.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,18 @@ jobs:
4545
sudo cp unicode.mapping /etc/apache2/
4646
sudo mkdir -p /var/cache/modsecurity
4747
sudo chown -R www-data:www-data /var/cache/modsecurity
48+
- name: first check config (to get syntax errors)
49+
run: sudo apachectl configtest
4850
- name: start apache with module
51+
run: sudo systemctl restart apache2.service
52+
- name: Search for errors/warnings in error log
4953
run: |
50-
sudo systemctl restart apache2.service
51-
sudo cat /var/log/apache2/error.log
54+
# '|| :' handles the case grep doesn't match, otherwise the script exits with 1 (error)
55+
errors=$(grep -E ':(?error|warn)[]]' /var/log/apache2/error.log) || :
56+
if [[ -z "${errors}" ]]; then exit 0; fi
57+
echo "::error:: Found errors/warnings in error.log"
58+
echo "${errors}"
59+
exit 1
5260
- name: Check error.log
5361
run: |
5462
# Send requests & check log format
@@ -60,3 +68,9 @@ jobs:
6068
grep -F ModSecurity < /var/log/apache2/error.log | grep -vP "^\[[^\]]+\] \[security2:[a-z]+\] \[pid [0-9]+:tid [0-9]+\] (?:\[client [0-9.:]+\] )?ModSecurity" || exit 0
6169
# grep -v succeeded => found some lines with invalid format
6270
exit 1
71+
- name: Show httpd error log
72+
if: always()
73+
run: sudo cat /var/log/apache2/error.log
74+
- name: Show mod_security2 audit log
75+
if: always()
76+
run: sudo cat /var/log/apache2/modsec_audit.log

0 commit comments

Comments
 (0)