Scroll to navigation

xchpst(8) System Manager's Manual xchpst(8)

NAME

xchpsteXtended CHange Process STate

SYNOPSIS

xchpst --help

xchpst --version

xchpst --exit[=retcode]

xchpst [OPTIONS] [--] command ...

DESCRIPTION

The xchpst utility changes process state according to the supplied options and then calls () on a named executable with the positional arguments.

xchpst is a backwards-compatible extension to the chpst(8) tool which is supplied with runit. xchpst enables runit service scripts to take advantage of hardening capabilities available with recent Linux kernels such as namespaces and capabilities. xchpst can set up shadow subtrees within the filesystem hierarchy to isolate long-running services from parts of the system to which they ought to need no access, e.g. with private /tmp areas and read-only /usr.

Extended xchpst options

The extra options provided by xchpst are as follows:

Show help text and usage.
[=retcode]
Exit immediately with exit status 0, or retcode if specified.
Create new mount namespace. Various other options also implicitly enable mount namespaces as this is important to their operation; this option is rarely likely to be needed to be specified explicitly.
Create new network namespace. This will more or less isolate the process from the networking subsystem.
Create new UTS namespace.
Create a PID namespace. This implies --fork-join because a new process is needed to act as PID 1 and in order to be able to mount a new procfs for the namespace.
Fork a new process and wait for it to finish, passing on to the child process any signals received by the xchpst process. This option is necessary to take advantage of PID namespaces. The exit status is that of the child process.
Create a user namespace.
path
Adopt the network namespace bound to path. The binding will be deleted from the filesystem meaning that the namespace will disappear when the process exits, if there is no other reference to it. This allows the calling script to set up a suitable networking environment for the process and hand it over.
Create a new root filesystem (will implicitly enable the creation of a new mount namespace).
Mount an isolated /run directory for the process. Unless /X.Fl -new-root is also specified, the old shared /run directory will still be accessible if the stacked mount is removed.
Mount an isolated /tmp directory for the process. Unless --new-root is also specified, the old shared /run directory will still be accessible if the stacked mount is removed.
Mount isolated /home, /root and /run/user directories for the process. Unless --new-root is also specified, the old shared host directories will still be accessible if the stacked mounts are removed.
Create a read-only filesystem hierarchy. Converts /usr and /boot into read-only mounts.
capability[,capability...]
Keeps only the listed capabilities in the bounding set.
capability[,capability...]
Drops the listed capabilities from the bounding set. Use only one of the two options governing the bounding set.
capability[,capability...]
Retain the listed capabilities when dropping to a non-root user.
capability[,capability...]
Drop the listed capabilities when dropping to a non-root user, but retain all others.
Prevent the target application from obtaining any new privileges. See PR_SET_NO_NEW_PRIVS(2const).
other | batch | idle
Set the scheduler policy, as per sched_setscheduler(2).
rt | best-effort | idle [:PRIORITY]
Set the I/O scheduler policy, as per ionice(1).
START[-END[:STRIDE]][,...]
Set CPU affinity in the same format as taskset(1).
bytes
Set soft limit for stack segment size.
bytes
Set soft limit for address space size.
bytes
Set soft limit for amount of locked memory.
Switches to chpst-compatible option handling only for the remaining options. This is to support scripts that can convert an xchpst invocation into a command line for chpst if xchpst is not present on the system.

chpst-compatible options

The options compatible with classic chpst are as follows:

user[:group]...
Set uid, gid and supplementary groups. Prepend the argument with a colon for numerical inputs rather than names to be looked up. If no group is specified then the specified user's group is used. There is no space within the argument.
user[:group]
Like -u but the environment variables UID and GID are set instead of changing the user. Supplementary groups are ignored.
argv0
Set argv[0] to argv0 instead of the target executable path when launching the program.
dir
Populate environment. For every file within dir, the filename represents an environment variable that will be set or unset. The first line of the corresponding files is the content to be set, with NUL characters replaced by LF and trailing whitespace removed. If the file is 0 bytes long then the variable is unset. (So a file with just a newline results in the variable being set with an empty value.)
dir
Run in a chroot. Change to the dir directory and make it the new root.
dir
Change directory. Change to the dir directory (after any chroot setting is applied).
inc
Increase niceness by inc, which can be negative, resulting in the process taking a higher priority.
file
Wait for lock. Take a lock out on file and wait to obtain it before proceeding to ().
file
Try to obtain lock; bail out if it can't be obtained.
bytes
Set soft limit for data and stack segments and virtual memory size and locked memory.
bytes
Set soft limit for data segment size.
files
Set soft limit for the number of open files.
procs
Set soft limit for the number of processes for this user.
bytes
Set soft limit for the size of file that this process may create.
bytes
Set soft limit for the size of core this process may dump.
seconds
Set soft limit for the amount of CPU time this process may consume.
Be verbose. This option may be repeated for increased verbosity to support debugging.
Show xchpst version number.
Make this process the process group leader, allocating a new session idea.
Close stdin.
Close stout.
Close stderr.

Emulating ancestor tools

When invoked as chpst, envdir, envuidgid, pgrphack, setlock, setuidgid, or softlimit, the xchpst executable emulates the corresponding tools from the “runit” or “daemontools” packages respectively. As an additional feature, all these tools when so invoked, accept the -v option to increase verbosity.

EXIT STATUS

0
The default exit status when --exit is specified is 0. This can be used for a quick test that xchpst is available on the system in shell scripts.
100
The return code when an invalid option or option argument is specified, including if a username cannot be resolved, for example.
111
When the requested process state cannot be changed.
other
The --exit option takes an optional argument with a return code to use.

If there is no error and the intended application is exec()'d, the exit status will be that of the application, not xchpst.

EXAMPLES

Testing the emulation of ‘envdir’:

xchpst -b envdir -- xchpst

Launch with read-only filesystem if xchpst is available, else use chpst:

xchpst --exit && exec xchpst --ro-sys -l /var/lock/ntpsec-ntpdate ntpd; exec chpst -l /var/log/ntpsec-ntpdate ntpd

Drop a capability from the bounding set:

xchpst --cap-bs-drop CAP_SYS_ADMIN -- acmed

Drop user while retaining some capabilities:

xchpst -u :500:500 --caps-keep CAP_DAC_OVERRIDE fakeroot /usr/sbin/gpm -D -m /dev/input/mice -t exps2

SEE ALSO

chpst(8), runit(8), unshare(1), capsh(1), taskset(1,) chrt(1)

HISTORY

xchpst version 0.x has an unstable interface for initial feature development.

xchpst was written from scratch to be backwards compatible with chpst. The extent of the planned extensions dwarfing the complexity of the original options led to the decision to write a new tool rather than extending the existing one. The new xchpst tool is targeted at new versions of Linux distributions so is written with a recent tooling and kernel baseline.

xchpst has different design principles from chpst. Use xchpst if you need the additional options to harden runit-supervised tasks; use chpst if you do not need them, for a minimal footprint.

AUTHORS

Andrew Bower <andrew@bower.uk>

BUGS

Please raise bug reports at: https://gitlab.com/abower/xchpst/-/issues

December 25, 2024 Debian