Skip to content

Security

Ask two questions for every plugin that runs as root (it ships in assets/sudoers/, or its README tells the admin to grant sudo), and again for every parameter you add:

  1. What else can a local attacker who controls all arguments do? The monitoring user (icinga / nagios) supplies every value and owns what they can create (/tmp, their home). Follow each parameter to the file, command or socket it reaches, assuming value and filesystem are hostile.
  2. Who may set the parameter, and with what privileges does the resulting action run? Selecting data the plugin reads back and filters is low risk; redirecting a privileged action (file opened as root, binary executed, socket used) hands over that privilege unless confined. That is the class behind GHSA-q8c8-wxhc-3h4c and GHSA-f54c-p5vg-mr5c.

  3. External commands: Use lib.shell.shell_exec() with an argv list (always shell=False), never os.system() or subprocess with shell=True. Put each user-supplied value in its own element (['restic', f'--repo={repo}', 'check'], ['ping', '-q', hostname]), never assemble a command string. A value starting with - can still become an option (an ssh destination -oProxyCommand=..., ping -f), so guard values that reach a command as a positional argument or target with coe(lib.shell.safe_cli_value(args.HOSTNAME, '--hostname')). Unlike the official Monitoring Plugins guidelines, we accept PATH-based resolution for cross-platform compatibility, aware that a compromised PATH could redirect commands.

  4. Input validation: Validate all user input; use argparse type converters (type=int, type=float, type=lib.args.csv).
  5. Temporary files: Avoid them; prefer lib.db_sqlite or lib.cache. If unavoidable, fail cleanly when the file cannot be created, and delete it when done.
  6. Confining a path a privileged plugin was pointed at: When a root plugin opens, stats, globs or lists a location a caller-supplied value can steer (--path, --filename, --socket, a scanned directory or a file found inside it), a planted symlink makes root read e.g. /etc/shadow; --path=/var/crash and --path=/tmp/attacker look alike without a containment check. Confine every edge (directory, each file found, final read):

    • Reading a file: let lib.disk open it, success, content = lib.disk.read_file(candidate, allowed_roots=[root], nofollow=True). Never check and then open() yourself (check-then-use; O_NOFOLLOW guards only the last component): lib.disk.open_file(), behind read_file() and read_env(), verifies the opened handle against the path and accepts only regular files. Take everything from that handle; a second look at the path (os.stat(), file_exists(), open()) may see another file. For log lines, lib.logsource.read(..., allowed_roots=...) does the same.
    • Executing a file, connecting to a socket, or taking an account from a file's owner: these cannot be checked on a handle, so call success, resolved = lib.disk.resolve_trusted_path(candidate) (lib.base.cu(resolved) on failure) and use resolved, never candidate. It requires that only root (and the given owners) can change the object and every directory above it. References: --command in apache-httpd-security and nginx-security, --socket in fail2ban and strongswan-connections, and lib.nextcloud.run_occ(), which runs occ as the owner of config/config.php and refuses a symlinked config.php.
    • A location is never trusted by its prefix: the monitoring user owns /run/icinga2 and /var/log/icinga2, /run/user/<uid> exists per session, and /opt trees often belong to service accounts. Only the ownership check decides.
    • Answer "does not exist" and "not allowed" identically for paths outside the roots, and check the roots first, otherwise the plugin reveals which files exist. Under --test, read fixtures only through lib.lftest.test_text() or lib.lftest.test_json(), never with file_exists() first.
    • Never weaken this to a filename check (if name == 'vmcore-dmesg.txt'), which binds the symlink's name, not its target. Where a shared lib function reads, the guard belongs in the lib. As defense in depth, pin arguments in the sudoers entry (see the LF_LIBRENMS_VALIDATE alias in assets/sudoers/), but never rely on it alone. Treat a socket like a binary: a planted one feeds root a chosen response, which is code execution when the client deserializes it (fail2ban-client uses pickle).
  7. Credentials: Never log or print passwords, tokens or other secrets, not even in verbose mode.

  8. Network communication: HTTPS by default. Support --insecure for self-signed certificates, never make insecure the default.
  9. Internal management endpoints (Icinga API, BMC, storage controller, backup appliance) are the one exception: they practically always use their own CA, so plugins for them may set DEFAULT_INSECURE = True and must then offer --no-insecure (help=lib.args.help('--no-insecure'), action='store_false') as the counterpart to --insecure (action='store_true'). Both share dest='INSECURE' and the same default=DEFAULT_INSECURE, so declaration order does not matter. Checks against public or customer-facing endpoints keep DEFAULT_INSECURE = False and offer --insecure only.

sudoers File

If the plugin requires sudo, add it to the sudoers files of all supported operating systems in assets/sudoers/. File names match ansible_facts['os_family'] (Debian, RedHat, Suse), each with a -logging companion; use symbolic links to prevent duplicates (Suse.sudoers links to RedHat.sudoers).

Attention: The newline at the end is required!