You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 /var/log/nginx/modsec_audit.log
@victorhora you can leverage approach described at https://forum.nginx.org/read.php?29,247488,247500#msg-247500 (i.e. use standard nginx API to open some stub-file with ngx_conf_open_file(), add required handler, and use it for detecting USR1 and HUP signals from master process) - the question is that libmodsecurity currently does not have an interface to initiate audit/debug log files reopening by connector's request, am I right?
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.
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.
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.
twimc, until it's fixed, workaround is to use 'copytruncate' option in logrotate
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.
If using filebeat i think the best solution would probably be to use "SecAuditLogType HTTPS"
this can be send directly to a remote or localhost filebeat
Activity
ledzepp4eva commentedon Aug 7, 2018
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
/var/log/nginx/modsec_audit.log
defanator commentedon Aug 8, 2018
@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?
victorhora commentedon Aug 17, 2018
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 :)
suddenhead commentedon Sep 12, 2018
twimc, until it's fixed, workaround is to use 'copytruncate' option in logrotate
defanator commentedon Sep 12, 2018
@victorhora you can leverage approach described at
https://forum.nginx.org/read.php?29,247488,247500#msg-247500 (i.e. use standard nginx API to open some stub-file with
ngx_conf_open_file()
, add required handler, and use it for detecting USR1 and HUP signals from master process) - the question is that libmodsecurity currently does not have an interface to initiate audit/debug log files reopening by connector's request, am I right?defanator commentedon Nov 28, 2018
@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
ngx_http_modsecurity_log_flush()
is called in every worker process.victorhora commentedon Nov 28, 2018
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.
deeztek commentedon Jun 4, 2019
Tried adding the "copytruncate" option in the logrotation script but I got the following:
logrotate_script: 2: logrotate_script: copytruncate: not found
mhoran commentedon Jun 4, 2019
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.
deeztek commentedon Jun 4, 2019
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?
github-actions commentedon Jan 29, 2020
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
19 remaining items
zimmerle commentedon Jul 30, 2020
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.
mmelo-yottaa commentedon Jul 30, 2020
ok thanks @zimmerle
github-actions commentedon Aug 31, 2020
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
pgassmann commentedon Sep 1, 2020
Still waiting for #198 to be merged. Which is blocked:
@zimmerle commented
krizbaipeter commentedon Apr 7, 2021
Hi!
Try logrotate with copytruncate option, without postrotate scritp. This is an alternative solution...
duckasylum commentedon Apr 23, 2021
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.
mark4409 commentedon Nov 1, 2021
reloading nginx doesn't appear to work but restarting does. If you're ok with this then:
postrotate
if [ -f /var/run/nginx.pid ]; then
/usr/sbin/service nginx restart
fi
appears to work for me.
luigimolinaro commentedon Nov 3, 2021
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.
luigifab commentedon Jul 5, 2022
Some news? (to work without
copytruncate
and with the default nginx logrorate configuration file).amsnek commentedon May 10, 2023
If using filebeat i think the best solution would probably be to use "SecAuditLogType HTTPS"
this can be send directly to a remote or localhost filebeat
SecAuditLogType HTTPS
SecAuditLog http://127.0.0.1:80
with concurrent + filebeat -> performance issues (it doesnt seem to like large files)
nginx: fix continued writes to rotatrd modsecurity log files
nginx: fix continued writes to rotated modsecurity log files