The Bastion Sentinel: Non-Repudiation Audit Command Proxy
Intercept and proxy privileged root execution through an immutable logging wrapper that records environmental telemetry, hashes binaries, and blocks destructive patterns.
audit_proxy() { local ts=$(date -u +%FT%TZ); local caller=$(whoami); local sha=$(sha256sum "$(which "$1" 2>/dev/null)" 2>/dev/null | awk '{print $1}'); logger -t AUDIT_PROXY "[PROXY_CALL] ts=$ts user=$caller cmd='$*' binary_sha=$sha"; if [[ "$*" =~ (rm\ -rf\ /|mkfs|dd\ if=) ]]; then echo "[SECURITY BLOCK] Destructive ward triggered! Execution denied." >&2; return 1; fi; sudo "$@"; }; audit_proxy apt-get update The Lineage to the Gang of Four
In the Gang of Four catalog, the Proxy pattern mediates access to a protected resource:
“Provide a surrogate or placeholder for another object to control access to it.” — Gang of Four, Structural Patterns
The GoF identified the Protection Proxy as a component that controls access to sensitive objects based on access rights, security policies, and parameter validation before passing requests to the real subject.
The Transmutation to Privileged Command Execution
Granting unconstrained sudo privileges to automation scripts, deployment pipelines, or on-call engineers creates severe operational risks:
- Accidental execution of catastrophic disk-wiping commands (
rm -rf /or unintendeddd). - Lack of non-repudiation audit trails for compliance frameworks (SOC 2, ISO 27001).
- Execution of tampered or trojanized binaries without cryptographic integrity verification.
The Bastion Sentinel functions as an architectural Protection Proxy:
- It sits between the user/script and the real privileged executor (
sudo). - It intercepts every command, logging structured telemetry to
syslog(/dev/log). - It computes the SHA-256 fingerprint of the target executable to detect malicious binary replacements.
- It scans the arguments for prohibited destruction signatures and aborts execution before the kernel touches any hardware.
The Spell Formula
Cast this function definition in /etc/profile.d/audit_proxy.sh or within your automation pipelines:
audit_proxy() {
local ts=$(date -u +%FT%TZ)
local caller=$(whoami)
local bin_path=$(which "$1" 2>/dev/null)
local sha=$(sha256sum "$bin_path" 2>/dev/null | awk '{print $1}')
# 1. Log telemetry to syslog with immutable proxy tag
logger -t AUDIT_PROXY \
"[PROXY_CALL] ts=$ts user=$caller cmd='$*' bin=$bin_path sha256=$sha"
# 2. Protection Proxy Gate: Block destructive commands
if [[ "$*" =~ (rm\ -rf\ /|mkfs|dd\ if=) ]]; then
echo "[SECURITY BLOCK] Destructive ward triggered! Execution denied for: $*" >&2
logger -t AUDIT_PROXY "[SECURITY_ALERT] Blocked prohibited command: $*"
return 1
fi
# 3. Delegate to the Real Subject
sudo "$@"
}
audit_proxy systemctl restart nginx
Anatomy of the Proxy Pipeline
[Caller / Automation Runner]
│
▼
┌───────────────────────────────────────┐
│ The Bastion Audit Proxy │
│ 1. Compute SHA-256 of target binary │
│ 2. Record non-repudiation audit log │
│ 3. Evaluate security filter rules │
└───────────────────┬───────────────────┘
│
┌─────────┴─────────┐
▼ ▼
[VIOLATION] [AUTHORIZED]
│ │
(Drop & Alert) ▼
[sudo / Real Command]
Why the Proxy Pattern Beats Raw Sudoers Configuration
While standard /etc/sudoers supports binary-level whitelisting, it lacks dynamic contextual telemetry (binary cryptographic verification, payload regex interception, structured JSON/syslog telemetry). The Protection Proxy provides a defense-in-depth shield that intercepts requests at the invocation perimeter.