Scripts, plugins and the security model
Probeward can run programs on the probe host to measure things that have no sensor of their own. Two sensor kinds use this, and a third runs a program on the monitored machine over SSH (below):
| Kind | Runs | Reads |
|---|---|---|
script | a program you wrote, on the probe host | Probeward's native JSON result, or the incumbent's custom sensor result format (JSON or XML) |
nagios_plugin | a Nagios-compatible plugin, unchanged, on the probe host | the exit status, the first line of output and the performance data |
ssh_script | a program that already exists on the target, over SSH | the same formats as script |
Running a program is the most powerful thing a monitoring server does, so it is switched off until an administrator of the host turns it on, and it is fenced in.
Switching it on
Set one environment variable on the Probeward process and restart it:
PROBEWARD_SCRIPT_DIR=/var/lib/probeward/scriptsUnset or empty, no program ever runs and the sensors fail with a message that names the variable. With the reference Compose install, mount a directory into the container and set the variable in .env:
volumes:
- ./scripts:/var/lib/probeward/scripts:roMount it read-only, so that nothing running inside Probeward can change what it executes.
On a remote probe
A script or nagios_plugin sensor under a remote probe runs on that probe, from the probe host's own directory: set PROBEWARD_SCRIPT_DIR in the probe's environment (/etc/probeward-probe/probe.env with the unit in deploy/probe/, /etc/probeward/probeward-probe.env with the deb package). The core's setting does not reach the probe and no program is ever sent to it, so put the programs on each probe host yourself, the same way as on the core. Each probe decides for itself: a probe without the variable refuses to run anything, and its script sensors fail with the same configuration message as on a core without it, even when the core has scripts switched on. Everything else on this page applies on the probe unchanged. Keep the directory owned by root and not writable by the probeward-probe user.
Where programs come from
The programs are files in that one directory. They cannot be uploaded through the API or the interface, and there is no way to point a sensor at another directory. You put them there as the administrator of the host: by copying them in, by a configuration management tool, or by mounting a volume. A sensor names the file only:
fileis a plain name: letters, digits,.,_,-and+, at most 128 characters, no/or\, no leading dot.../x,/bin/shandsub/xare refused when the sensor is saved and again before every run.- The name is resolved inside the directory, with symbolic links followed, and the result must still be a regular file directly in the directory. A link that leaves it is refused. A link inside it is fine.
- The file must be executable. Probeward does not guess an interpreter: a script starts with
#!.
What a run looks like
| User | The user Probeward runs as. Probeward refuses to run programs when it is root. The container image runs as an unprivileged user. Give that user no more rights than the programs need. |
| Process | Started directly with the arguments you set as a list. There is no shell: a b, ; reboot, $(id) and backticks are just characters in one argument. {address} and {hostname} are replaced in an argument by the device's address and host name; a host name that starts with - or holds whitespace or control characters is refused. |
| Environment | Cleaned: only PATH=/usr/local/bin:/usr/bin:/bin, LC_ALL=C, LANG=C, PROBEWARD_ADDRESS, PROBEWARD_HOSTNAME, and PROBEWARD_SECRET when the sensor asks for it. Nothing of Probeward's own environment is passed on: not the database URL, not the vault key path. |
| Directory, input | The script directory. Standard input is closed. |
| Time | The poll's timeout (the sensor's timeout, at most 90 % of it for the program). When it passes, the program and everything it started (it leads its own process group) are killed. |
| Output | At most 256 KiB on standard output and the first 16 KiB of standard error are read. A program that writes more is killed and the poll fails. |
| Arguments | At most 32, each at most 1024 bytes, no NUL. |
| Secrets | A credential is handed over only when the sensor's pass_secret is on, in PROBEWARD_SECRET. It is not an argument, so ps does not show it to other users. It is never written to a message, log or event. |
| Who | Only an administrator can create such a sensor or change its parameters, by the API and in the interface. Operators can still rename it, switch it off, pause it and set limits. A device template cannot attach one, so discovery never proposes a program. |
What this does not do: it is not a sandbox. A program has the rights of the Probeward user and can read what that user can read, including files Probeward owns, and use the network. The fence keeps untrusted input (a parameter, a host name, a stolen operator account) from turning into code. It does not make untrusted programs safe. Only put programs there that you trust. If you need more, run the probe host in a container with a read-only file system, no capabilities and a network policy, or wait for the sandboxed plugin runtime that is on the roadmap.
Runtimes
The programs use whatever interpreter their first line names, and that has to exist on the probe host, in the container if Probeward runs in one. The Probeward image is minimal and has /bin/sh; a Perl or Python plugin needs that installed in your own image layer. Test each plugin the way Probeward will run it: from the script directory, with the cleaned environment, as the Probeward user.
Writing a script (native format)
#!/bin/sh
# Reports the number of jobs waiting in the queue.
n=$(wc -l < /var/spool/jobs/queue 2>/dev/null) || { echo '{"error":"queue file unreadable"}'; exit 0; }
printf '{"status":"ok","message":"%s jobs waiting","channels":[{"key":"waiting","name":"Jobs waiting","value":%s,"unit":"jobs"}]}\n' "$n" "$n"Make the sensor {"file": "queue.sh", "output": "native_json"}, set limits on the waiting channel, and test the script by running it by hand first. The format is in the script sensor's page.
Exit with status 0 whatever you found: the status is for failures of the script itself. Use status and error in the output to say what you found.
Using an existing script from the incumbent
A script that prints the incumbent's custom sensor result format runs as it is with "output": "incumbent_json" or "incumbent_xml". What is read is described in the script sensor's page. Differences to know of:
- The channel key comes from the channel's name. Renaming a channel in the script starts a new history.
- Units, names and display options are not stored: only the value and the limits' effect are.
- Limits the script sets (
limitmaxerror, ...) make the sensor Warning or Down for that poll. They are not imported as Probeward limits; set those on the sensor. - Scripts are called with the arguments you put in
args, not with the incumbent's placeholders for the sensor's parameters; replace%hostand the like by{address}and{hostname}. - A script that expects its runtime (PowerShell, a particular Python) needs it on the probe host.
Using Nagios plugins
Copy the plugins you want into the script directory (from the monitoring-plugins package, usually /usr/lib/nagios/plugins, or your own) and make a sensor for each use. Copy them: a symbolic link to the package's directory is refused, because it leaves the script directory.
The reference image is Alpine, whose binaries are linked against musl, so plugins built for Debian or Red Hat will not run in it. Alpine packages the Monitoring Plugins as monitoring-plugins, which installs them in /usr/lib/monitoring-plugins. A derived image can bring the ones you need:
FROM probeward:local
USER root
RUN apk add --no-cache monitoring-plugins \
&& install -d -o probeward -g probeward /var/lib/probeward/scripts \
&& cp /usr/lib/monitoring-plugins/check_tcp /usr/lib/monitoring-plugins/check_disk \
/usr/lib/monitoring-plugins/check_procs /var/lib/probeward/scripts/
USER probeward:probeward
ENV PROBEWARD_SCRIPT_DIR=/var/lib/probeward/scripts(In that case do not mount a volume over the directory.) Then make a sensor for each use:
{"file": "check_tcp", "args": ["-H", "{address}", "-p", "5432", "-w", "0.5", "-c", "2"]}The plugin's exit status becomes health, its first line the message, and its performance data the channels. Run the plugin by hand as the Probeward user first. Plugins that use the network need it from the probe host. A plugin that wants to run sudo will not work: Probeward does not allow it any rights.
Running a program on the target over SSH
The ssh_script sensor does not use the script directory and does not need PROBEWARD_SCRIPT_DIR: the program is a file on the monitored machine, and it runs as the account of the sensor's SSH credential. It parses what the program prints with the same parsers as script. The model is different in what is trusted and what is fenced:
| Who | Only an administrator can create such a sensor or change its parameters, by the API and in the interface, as for script. A device template cannot attach one, so discovery never proposes it. |
| What runs | A fixed absolute path on the target, and arguments. The path may hold only letters, digits, ., _, -, + and /, with no . or .. segment, so a shell can read nothing into it. Each argument is sent as one single-quoted word in the one exec request (a ' inside becomes '\''), so a b, ; reboot, $(id) and backticks are the characters of one argument. Arguments have no control characters, at most 32 of at most 1024 bytes. No part of the command line is built from the device's name, the program's output or anything but the sensor's own parameters. |
| Shell | The target's login shell for the account reads the line, so it has to understand single quotes (sh, bash, dash, zsh, fish). |
| Host key | A pinned fingerprint (host_key) is required, or trust_on_first_use has to be switched on by name. Without either the sensor is refused when it is saved. A pinned key is checked before any credential is sent. Trust on first use records the first key seen and warns in the message of every poll. |
| Credential | The ssh_password or ssh_key credential of the sensor, as for the other SSH sensors. It is never in a message, log or event. |
| Output | At most 256 KiB on standard output is read; the first line of standard error is quoted in a failure message. |
| Limits | The poll's timeout covers connecting, signing in and the run. |
What this does not do: it is not a sandbox on the target. The program runs with every right the SSH account has, and anyone who can write to the program's file, or to a directory in its path, controls what Probeward runs there. Use an account of its own, give it only what the program needs, and keep the program and its directories writable by root alone. The fence keeps untrusted input (a parameter, a stolen operator account) from becoming code; it does not make an untrusted program safe.
What the runner guarantees
Arguments with shell metacharacters stay single arguments and nothing they spell runs; a link that leaves the directory, a path, a hidden file and a file that is not executable are refused; the environment holds nothing but the fixed set; a program that runs too long is killed together with any child it started in the background; a program that floods its output is stopped; and nothing runs when the directory is unset. Only administrators can attach these sensors.