nginx: use copytruncate for modsecurity log rotation #957
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 betweencopying and the truncation being done.
PL-132296
@flyingcircusio/release-managers
Release process
Impact: -
Changelog:
/var/log/nginx/modsec_audit.log
/var/log/nginx/modsec_*.log
are now rotated via copying and then truncating the open logmodsec_*
to not accidentally grow unrotated. This is the naming convention suggested by our nginx modsecurity configuration examples.PR release workflow (internal)
Design notes
on
oroff
. Example: rate limiting.Security implications