fix: filter hostd volumes in Python to avoid building SQL from a string
Lint / Python (flake8) (push) Successful in 1m35s
Lint / Notify on failure (push) Skipped
Lint / Python (flake8) (pull_request) Successful in 1m30s
Lint / Notify on failure (pull_request) Skipped
Security / Python Security (bandit) (push) Successful in 1m33s
Test / Python Tests (pytest) (push) Successful in 1m46s
Security / Python Security (bandit) (pull_request) Successful in 1m9s
Test / Python Tests (pytest) (pull_request) Successful in 1m16s

Bandit 1.9.4 in CI flagged the query (B608). Select every volume with a
static query and match the mountpoint in Python instead. Also stops a
mount like /mnt/sia-other from matching /mnt/sia.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-06 12:57:52 -05:00
1 parent d8f707ade7
commit 99d4350f4d
2 files changed
+22 -11

No files matched your search

+7 -5
View File
@@ -4128,10 +4128,7 @@ class SystemHealthMonitor:
Reading the database avoids needing the hostd API password on every node.
Returns None if the usage cannot be read.
"""
query = (
"SELECT COALESCE(SUM(used_sectors), 0), COALESCE(SUM(total_sectors), 0) "
f"FROM storage_volumes WHERE disk_path LIKE '{managed['mountpoint']}/%';"
)
query = "SELECT disk_path, used_sectors, total_sectors FROM storage_volumes;"
try:
result = subprocess.run(
['pct', 'exec', vmid, '--', 'sqlite3', f"file:{managed['db_path']}?mode=ro", query],
@@ -4143,7 +4140,12 @@ class SystemHealthMonitor:
if result.returncode != 0:
logger.warning(f"Could not read hostd usage for LXC {vmid}: {result.stderr.strip()}")
return None
used_sectors, total_sectors = (int(value) for value in result.stdout.strip().split('|'))
used_sectors = total_sectors = 0
for row in result.stdout.splitlines():
disk_path, used, total = row.rsplit('|', 2)
if disk_path.startswith(f"{managed['mountpoint']}/"):
used_sectors += int(used)
total_sectors += int(total)
except (subprocess.SubprocessError, OSError, ValueError) as e:
logger.warning(f"Could not read hostd usage for LXC {vmid}: {e}")
return None