-
Notifications
You must be signed in to change notification settings - Fork 686
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean out old OSSEC diff and state files
These files are never pruned by OSSEC so they tend to accumulate, which can be a big deal for very big binary files like the ones in /boot. A script triggered by a daily timer will now clean up old state and diff files that are more than a year old. Fixes #7325.
- Loading branch information
Showing
6 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
securedrop/debian/config/lib/systemd/system/securedrop-cleanup-ossec.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[Unit] | ||
Description=Cleanup OSSEC diff queue | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/bin/securedrop-cleanup-ossec.py | ||
User=root |
10 changes: 10 additions & 0 deletions
10
securedrop/debian/config/lib/systemd/system/securedrop-cleanup-ossec.timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Unit] | ||
Description=Cleanup OSSEC diff queue | ||
|
||
[Timer] | ||
OnCalendar=daily | ||
Persistent=true | ||
RandomizedDelaySec=5m | ||
|
||
[Install] | ||
WantedBy=timers.target |
33 changes: 33 additions & 0 deletions
33
securedrop/debian/config/usr/bin/securedrop-cleanup-ossec.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/python3 | ||
""" | ||
Delete OSSEC diff/state files older than a year | ||
Runs as root on both app and mon servers | ||
""" | ||
|
||
import os | ||
import re | ||
from datetime import datetime, timedelta | ||
|
||
OSSEC_DIFFS = "/var/ossec/queue/diff/local/" | ||
KEEP_DAYS = 365 | ||
# Match e.g. state.1667271785 | ||
RE_REMOVE = re.compile(r"^(state|diff)\.\d+$") | ||
|
||
|
||
def main() -> None: | ||
cutoff_date = datetime.now() - timedelta(days=KEEP_DAYS) | ||
|
||
for root, dirs, files in os.walk(OSSEC_DIFFS): | ||
for file in files: | ||
if RE_REMOVE.match(file): | ||
file_path = os.path.join(root, file) | ||
modified_time = os.path.getmtime(file_path) | ||
file_modified_date = datetime.fromtimestamp(modified_time) | ||
if file_modified_date < cutoff_date: | ||
os.remove(file_path) | ||
print(f"Deleted file: {file_path} (Last modified: {file_modified_date})") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
debian/config/etc / | ||
debian/config/lib / | ||
debian/config/opt / | ||
debian/config/usr / |