Skip to content

filter.d/nginx-bad-request: support the journal log format - #4258

Open
rafaelsoje wants to merge 1 commit into
fail2ban:masterfrom
rafaelsoje:fix/nginx-bad-request-journal
Open

rafaelsoje wants to merge 1 commit into
fail2ban:masterfrom
rafaelsoje:fix/nginx-bad-request-journal

Conversation

@rafaelsoje

Copy link
Copy Markdown
Contributor

Summary

Extends config/filter.d/nginx-bad-request.conf to support the systemd journal log format, completing the request from gh-3732 that was partially addressed in gh-4223 for nginx-botsearch.conf.

Closes gh-3732

Details

  • In config/filter.d/nginx-bad-request.conf:
    • Included before = common.conf and default _daemon = nginx.
    • Updated failregex to use %(__prefix_line)s and match flexible bracketed dates (\[[^\]]*\]). In file logs, the date text is replaced by empty brackets []; in systemd journal format, the date is retained within brackets in the log line.
    • Added \s+\[({DATE}) to datepattern so date matching skips preceding brackets such as nginx[PID] in journalctl / syslog entries.
  • In fail2ban/tests/files/logs/nginx-bad-request:
    • Added sample test cases for logtype = journal (standard message and message with authenticated user).
  • In ChangeLog:
    • Added entry under Fixes.

Verification

  • fail2ban-regex before patch with [logtype=journal]:
    Lines: 1 lines, 0 ignored, 0 matched, 1 missed
  • fail2ban-regex after patch with [logtype=journal]:
    Lines: 1 lines, 0 ignored, 1 matched, 0 missed
  • Standard file format test with fail2ban-regex:
    Lines: 7 lines, 0 ignored, 7 matched, 0 missed
  • Automated test suite:
    ./bin/fail2ban-testcases --no-network samples -> Ran 101 tests, OK

Checklist

  • CONSIDER adding a unit test if your PR resolves an issue
  • LIST ISSUES this PR resolves or describe the approach in detail
  • MAKE SURE this PR doesn't break existing tests
  • KEEP PR small so it could be easily reviewed
  • AVOID making unnecessary stylistic changes in unrelated code
  • ACCOMPANY each new failregex for filter X with sample log lines (and # failJSON) within fail2ban/tests/files/logs/X file
  • PROVIDE ChangeLog entry describing the pull request

Support systemd journal log format for nginx-bad-request filter, allow
flexible bracketed date matching, and update datepattern to skip PID
brackets in journalctl entries.

Closes fail2bangh-3732

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR]: nginx-bad-request.conf nginx-botsearch.conf should also support the new journalctl format introduced in the other nginx filters

1 participant