Merge pull request #3190 from marcstern/v2/pr/ci_log

CI improvement: First check syntax & always display error/audit logs
This commit is contained in:
Ervin Hegedus 2024-08-20 15:25:13 +02:00 committed by GitHub
commit fd0e042abc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -4,3 +4,5 @@ LoadModule security2_module /usr/lib/apache2/modules/mod_security2.so
SecDataDir /var/cache/modsecurity SecDataDir /var/cache/modsecurity
Include /etc/apache2/modsecurity.conf Include /etc/apache2/modsecurity.conf
</IfModule> </IfModule>
SecAuditLog /var/log/apache2/modsec_audit.log

View File

@ -45,10 +45,18 @@ jobs:
sudo cp unicode.mapping /etc/apache2/ sudo cp unicode.mapping /etc/apache2/
sudo mkdir -p /var/cache/modsecurity sudo mkdir -p /var/cache/modsecurity
sudo chown -R www-data:www-data /var/cache/modsecurity sudo chown -R www-data:www-data /var/cache/modsecurity
- name: first check config (to get syntax errors)
run: sudo apachectl configtest
- name: start apache with module - name: start apache with module
run: sudo systemctl restart apache2.service
- name: Search for errors/warnings in error log
run: | run: |
sudo systemctl restart apache2.service # '|| :' handles the case grep doesn't match, otherwise the script exits with 1 (error)
sudo cat /var/log/apache2/error.log errors=$(grep -E ':(?error|warn)[]]' /var/log/apache2/error.log) || :
if [[ -z "${errors}" ]]; then exit 0; fi
echo "::error:: Found errors/warnings in error.log"
echo "${errors}"
exit 1
- name: Check error.log - name: Check error.log
run: | run: |
# Send requests & check log format # Send requests & check log format
@ -60,3 +68,9 @@ jobs:
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 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
# grep -v succeeded => found some lines with invalid format # grep -v succeeded => found some lines with invalid format
exit 1 exit 1
- name: Show httpd error log
if: always()
run: sudo cat /var/log/apache2/error.log
- name: Show mod_security2 audit log
if: always()
run: sudo cat /var/log/apache2/modsec_audit.log