Skip to content

filter.d/authelia: add new filter and jail for Authelia - #4259

Merged
sebres merged 2 commits into
fail2ban:masterfrom
rafaelsoje:add-authelia-filter
Nov 2, 2026
Merged

sebres merged 2 commits into
fail2ban:masterfrom
rafaelsoje:add-authelia-filter

Conversation

@rafaelsoje

Copy link
Copy Markdown
Contributor

Summary

Adds official filter and jail configuration for the Authelia 2FA/SSO authentication portal, supporting both standard key-value (file) and structured JSON logging formats.

Closes gh-4005

Details

  • config/filter.d/authelia.conf:
    • Implements dual format logging through logtype: file (default key-value format) and json (structured JSON format).
    • Captures authentication failures for all Authelia methods (1FA, TOTP, Duo, WebAuthn) using the pattern Unsuccessful \S+ authentication attempt by user '<F-USER>'.
    • Captures the source IP via <ADDR> from remote_ip.
    • Configures journalmatch = _SYSTEMD_UNIT=authelia.service for systemd journal integration.
  • config/jail.conf:
    • Added [authelia] jail definition with standard ports http,https,9091 and logpath /var/log/authelia/authelia.log.
    • Added documentation comments on activating JSON mode via filter = authelia[logtype=json].
  • fail2ban/tests/files/logs/authelia:
    • Unit test log samples for standard text logs (1FA LDAP failure, TOTP failure, Duo IPv6 failure).
    • Unit test log samples for JSON format (filterOptions: [{"logtype": "json"}]) covering 1FA, TOTP, and WebAuthn.
    • Negative control cases (# failJSON: { "match": false }) for successful authentications in both formats to prevent false positives.
  • ChangeLog:
    • Added entry under ### New Features and Enhancements.

Verification

  • fail2ban-regex against text log format:
    Lines: 1 lines, 0 ignored, 1 matched, 0 missed
  • fail2ban-regex against JSON log format ([logtype=json]):
    Lines: 1 lines, 0 ignored, 1 matched, 0 missed
  • Automated test suite:
    ./bin/fail2ban-testcases --no-network samples -> Ran 102 tests in 0.540s, 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

Add filter and jail configuration for Authelia 2FA/SSO portal,
supporting standard key-value (file) and structured JSON logging
formats with respective unit test samples.

Closes fail2bangh-4005
datepattern = <lt_<logtype>/datepattern>
ignoreregex =

journalmatch = _SYSTEMD_UNIT=authelia.service

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this filter would work with journal (because normally it'd expect a typical journal prefix, with host and [pid]), but OK - one can do it later...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for merging and for the regex optimization! That makes total sense regarding the journal prefix. I'll test Authelia logs under systemd-journald and submit a follow-up PR to handle the journal prefix properly.

@sebres
sebres merged commit fe34bcf into fail2ban:master Nov 2, 2026
10 checks passed
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]: Authelia

2 participants