Enforce Pre-Delete Hooks and TOCTOU Guards¶
Refer to Configuration Schema and Invariants before you change security controls.
Prerequisites¶
- Make sure that
filecleanerv1.1.0 or newer is installed on the host. - Prepare a dedicated hook script path such as
/usr/local/bin/verify_checksum_before_delete.sh. - Make sure that the hook script returns
0to permit action,42to skip, and1to abort.
Safety Instructions¶
CAUTION: Keep follow_symlinks = false on all production rules.
Symbolic link traversal can expose files outside the configured rule directory.
CAUTION: Invoke the hook script directly in pre_delete_hook.command.
Never pass sh -c or cmd /C wrappers that permit filename shell injection.
Procedure¶
- Install the checksum veto hook script and set executable permissions:
sudo install -m 0755 examples/hooks/verify_checksum_before_delete.sh /usr/local/bin/verify_checksum_before_delete.sh
- Create
/etc/filecleaner/secure-hooks.tomlwith symlink checks, six in-use probes, and[rules.pre_delete_hook]:
dry_run = true
global_trash_dir = "/var/tmp/filecleaner-quarantine"
[audit]
log_path = "/var/log/filecleaner/security-audit.jsonl"
jsonl = true
[[rules]]
name = "verified-etl-spool"
path = "/var/spool/etl/incoming"
recursive = true
max_depth = 3
follow_symlinks = false
include_globs = ["*.parquet", "*.csv"]
exclude_globs = ["*.sha256", "quarantine/**"]
time_basis = "modified"
max_age = "12h"
max_total_size = "20GiB"
actions = ["compress", "trash"]
compression = "lz4"
trash_dir = "/var/tmp/filecleaner-quarantine/etl"
[rules.in_use]
enabled = true
check_sidecar_locks = true
sidecar_suffixes = [".lock", ".lck", ".part", ".tmp", ".processing"]
check_os_locks = true
check_proc_fd = true
min_idle_age = "30s"
stability_window = "3s"
[rules.pre_delete_hook]
command = "/usr/local/bin/verify_checksum_before_delete.sh"
args = ["--strict", "{path}", "{size}"]
timeout = "15s"
on_failure = "abort_rule"
skip_exit_code = 42
run_in_dry_run = false
- Set private
0600permissions on/etc/filecleaner/secure-hooks.toml:
- Validate the configuration file with
filecleaner validate:
- Test an active file with
filecleaner check-in-usebefore any live sweep:
filecleaner check-in-use /var/spool/etl/incoming/sample.parquet --idle-age 30s --stability 3s --json
- Change
dry_run = truetodry_run = false, then run a live sweep:
NOTE: FileCleaner opens candidate files with O_NOFOLLOW on Unix and FILE_FLAG_OPEN_REPARSE_POINT on Windows.
Before truncation or S3 upload, FileCleaner also checks device and inode continuity.
Verification¶
- Confirm
filecleaner validateexits with code0. - Place a
.partsidecar beside a test file and confirmfilecleaner check-in-useexits with code10. - Remove the
.sha256manifest on a settled file and confirm"decision":"skip_hook"insecurity-audit.jsonl.
Rollback¶
If the hook blocks valid archival or causes rule aborts, do these steps:
- Set
dry_run = truein/etc/filecleaner/secure-hooks.toml. - Restore the previous hook script under
/usr/local/bin/verify_checksum_before_delete.sh. - Run
filecleaner plan --config /etc/filecleaner/secure-hooks.toml --jsonbefore you restoredry_run = false.
Related Documentation¶
- Reference: Configuration Schema and Invariants
- Reference: Error and Alert Matrix
- Explanation: Retention Calculus and TOCTOU Defenses
- Explanation: ADR-001: Pure-Rust Fail-Closed Engine