Skip to content

Commit

Permalink
utils: ignore auditd if it is not running
Browse files Browse the repository at this point in the history
Missing log dir means that the daemon is not running, we can't
really do anything about that since the daemon can not be started
manually and it is likely that it is even missing.
  • Loading branch information
pbrezina committed Jul 1, 2024
1 parent e1f5016 commit e704ccc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pytest_mh/utils/auditd.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(

self.artifacts: set[str] = {"/var/log/audit/audit.log"}
self._backup: str | None = None
self._auditd_running: bool = False

def setup(self) -> None:
"""
Expand All @@ -61,6 +62,11 @@ def setup(self) -> None:
result = self.host.ssh.run(
"""
set -e
if [ ! -d /var/log/audit ]; then
exit 0
fi
tmp=`mktemp -d`
cp -r --archive /var/log/audit "$tmp"
truncate --size 0 /var/log/audit/audit.log*
Expand All @@ -69,7 +75,10 @@ def setup(self) -> None:
log_level=SSHLog.Error,
)

self._backup = result.stdout.strip()
tmp_path = result.stdout.strip()
if tmp_path:
self._auditd_running = True
self._backup = tmp_path

def teardown(self) -> None:
"""
Expand Down Expand Up @@ -108,7 +117,7 @@ def pytest_report_teststatus(
if report.when != "call":
return None

if self.avc_mode == "ignore" or report.outcome == "skipped":
if not self._auditd_running or self.avc_mode == "ignore" or report.outcome == "skipped":
return None

self.logger.info("Checking for AVC denials")
Expand Down

0 comments on commit e704ccc

Please sign in to comment.