-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reopen audit log on SIGUSR1 and SIGHUP #121
Comments
Sorry for hijacking this issue, but I didn't want to raise a duplicated issue as this sounds like the same problem we are having. Seeing the same behaviour with
nginx configuration snippet
Using the default nginx logrotation script
However despite the access log and error logs being rotated and nginx reload relasing the file handles on them this isn't the case for |
@suddenhead @ledzepp4eva thanks for reporting this. @zimmerle @victorhora do you think that having some interface between library and connectors to perform such kind of tasks worth to implement? |
Hey @defanator Indeed I don't see such interface at shared_files. It might be interesting for sure, I'm curious if we could use a similar approach as this: https://forum.nginx.org/read.php?29,247488,247500#msg-247500 I'll let @zimmerle weight-in as well :) |
twimc, until it's fixed, workaround is to use 'copytruncate' option in logrotate |
@victorhora you can leverage approach described at |
@victorhora @zimmerle just for the reference, here's a dirty PoC on how to catch SIGUSR1 in modsecurity connector, code diff:
Logs after sending SIGUSR1 to master process:
Please note that |
Thanks @defanator! We can try turning this PoC into a feature for the next release :) I've created owasp-modsecurity/ModSecurity#1968 to track this feature in libModSecurity. |
Tried adding the "copytruncate" option in the logrotation script but I got the following: logrotate_script: 2: logrotate_script: copytruncate: not found |
While this is a fine workaround that I've employed myself, it's not the ideal solution for a couple of reasons. First, there's the possibility of losing logs between the copy and the truncate. It's a small chance, but possible -- and you might not want to lose your modsecurity audit logs. Second, not all systems have logrotate with copytruncate installed. For example, FreeBSD's newsyslog does not support copytruncate. I've had to install logrotate simply to rotate the modsecurity audit log. |
Ubuntu's logrotate doesn't seem to support copytruncate either it seems. Unless it has to be re-compiled with that option. So what's the solution? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days |
We've just experienced a related issue: on our server modsec audit log events were logged into I suspect modsec kept open the file handle during rename. Unfortunately this way logcheck wasn't able to alert us about security incidents as it was set to process the |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days |
This is still an issue. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days |
This is still an issue, but I can't remove the stale tag. |
@mhoran The "nostale" tag has been set for this one. We'll get to it when possible. Thank you. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days |
This should stay open until #198 is merged. |
Any estimate when #198 (and owasp-modsecurity/ModSecurity#2304) might merge into master? we could definitely use this fix. thank you!!! |
Hey @mmelo-yottaa Not yet. I would call that more a feature than a fix. It is in our queue. It is likely to hit version v3.1. Notice that this is a coordinated effort that also adds new functionality to libModSecurity as stated at owasp-modsecurity/ModSecurity#2304. |
ok thanks @zimmerle |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days |
Still waiting for #198 to be merged. Which is blocked:
|
Hi! |
I don't know how nginx does the signal handling, but I use nginx -s reopen in my postrotate scripts and this also suffers from the handles not switched over correctly error. |
reloading nginx doesn't appear to work but restarting does. If you're ok with this then: postrotate appears to work for me. |
This is actually a good work-around but if you want to filbeat (or similar) to push logs to a remote logging system you are in trouble beacuse of inodes and how those system works. |
Some news? (to work without |
If using filebeat i think the best solution would probably be to use "SecAuditLogType HTTPS" SecAuditLogType HTTPS with concurrent + filebeat -> performance issues (it doesnt seem to like large files) |
Because modsecurity is not re-opening its logfile after rotation and continues to write into the same file descriptor, we need to use `copytruncate`. Better handling of that situation is stuck upstream for several years. owasp-modsecurity/ModSecurity-nginx#121 We use the presence of `/var/log/modesc_*.log` as a heuristic for modsecurity being enabled, these files are now rotated with copytruncate. All other nginx logs are still rotated by moving and reloading. Note that, due to overlapping wildcard matches, this specific case got a higher logrotate match priority and needs an `ignoreduplicates`. `copytruncate` is non-atomic and might loose some logs written between copying and the truncation being done. PL-132296
Because modsecurity is not re-opening its logfile after rotation and continues to write into the same file descriptor, we need to use `copytruncate`. Better handling of that situation is stuck upstream for several years. owasp-modsecurity/ModSecurity-nginx#121 We use the presence of `/var/log/modesc_*.log` as a heuristic for modsecurity being enabled, these files are now rotated with copytruncate. All other nginx logs are still rotated by moving and reloading. Note that, due to overlapping wildcard matches, this specific case got a higher logrotate match priority and needs an `ignoreduplicates`. `copytruncate` is non-atomic and might loose some logs written between copying and the truncation being done. PL-132296
Modsecurity should reopen audit log on these two signals for proper logrotate operation.
The text was updated successfully, but these errors were encountered: