# /etc/sudoers.d/sysagent
# Install with: sudo install -m 440 sudoers/sysagent /etc/sudoers.d/sysagent
# Validate with: sudo visudo -cf /etc/sudoers.d/sysagent
#
# Dedicated user "sysagent" may run a narrow set of commands without a password.
# Members of the "sysagent" group may invoke the agent via /usr/bin/sysagent.
#
# ⚠️ SECURITY POSTURE — READ THIS BEFORE INSTALLING
# The regex denylist in policy.py is a tripwire, NOT a boundary:
# `bash -lc "$(printf 'r%s' m) -rf /"`, `eval`, `base64 -d | sh` and `r\m` all
# slip past it. These sudoers rules are the real boundary — and
# `NOPASSWD: /bin/systemctl` is root-equivalent (`systemctl link /tmp/evil.service
# && systemctl start evil`), as is a wide `apt-get *` rule. If you want a real
# deny-by-default boundary, grant ONLY the allowlist wrapper instead of raw
# commands: the "HARDENED VARIANT" at the bottom of this file does exactly that
# (selftools/rootcmd + its allowlist at ~/.config/sysadmin_agent/rootcmd.allow).

Defaults:sysagent !requiretty

sysagent ALL=(root) NOPASSWD: /usr/bin/apt-get, /usr/bin/apt
sysagent ALL=(root) NOPASSWD: /usr/bin/env DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get *
sysagent ALL=(root) NOPASSWD: /bin/systemctl, /usr/bin/systemctl
sysagent ALL=(root) NOPASSWD: /usr/bin/journalctl

# Allow members of the sysagent group to run the agent wrapper as the sysagent user
%sysagent ALL=(sysagent) NOPASSWD: /opt/sysadmin_agent/.venv/bin/sysagent

# ─────────────────────────────────────────────────────────────────────────────
# HARDENED VARIANT (recommended for an internet-facing / untrusted-LLM setup).
# Comment out the four `sysagent ALL=(root) NOPASSWD: ...` lines above, then
# uncomment these two. Every privileged action then has to go through the
# deny-by-default allowlist wrapper, and the agent's apt_*/systemctl_* tools
# route through it automatically when SYSAGENT_PRIV_WRAPPER is exported:
#     SYSAGENT_PRIV_WRAPPER=/usr/local/bin/rootcmd
#
# sysagent ALL=(root) NOPASSWD: /usr/local/bin/rootcmd
# Defaults:sysagent env_keep += "ROOTCMD_ALLOWFILE"
# ─────────────────────────────────────────────────────────────────────────────
