96.1.67. pepsi-console

run Pepsi commands in a terminal of the browser console

Manual section:

1

96.1.67.1.1. Name

pepsi-console - the daemon behind the browser console’s CLI windows, and the restricted shell that runs in each of them.

96.1.67.1.2. Synopsis

pepsi-console [GLOBAL-OPTIONS] serve [–idle SECS]

pepsi-console [GLOBAL-OPTIONS] shell

96.1.67.1.3. Description

The administration console of pepsi-httpd(1) has a button >_ at the top right that opens a terminal window in the browser. Each such window is a console: a pseudo-terminal on the server, in which a restricted shell runs the Pepsi commands that an administrator types. pepsi-console serve is the daemon that creates these pseudo-terminals, starts the shell in each and relays the terminal’s input and output to pepsi-httpd, which carries them to the browser over a WebSocket. pepsi-console shell is that shell.

The shell runs Pepsi commands only. It is not a shell of the operating system: it has no pipes, no redirection, no wildcards, no variables and no command that leads to another shell. Each command runs under the account that the program is meant to run as (see Programs), with this host’s configuration file.

The daemon runs as root, because it starts programs under several accounts. It is started on demand by pepsi-console.socket, which systemd binds at /run/pepsi/console.sock as root:pepsi-httpd, mode 0660, so that only pepsi-httpd (and root) can connect. Both units belong to the Debian package pepsi-httpd-admin and ship disabled: nothing offers a console until the operator arms the socket with systemctl enable --now pepsi-console.socket. On macOS the job net.taler.pepsi.console is enabled with pepsi-launchd enable console; there the daemon runs continuously and binds its socket itself. The daemon exits when no console has been left for –idle seconds; the next connection starts it again.

Whoever opens a console needs the scope cli:exec, which only the role superadmin includes. The daemon does not take pepsi-httpd’s word for it: it checks the administrator’s console session in the database itself, and checks it again every minute while the console is open (see Authorisation).

96.1.67.1.4. Commands

serve [–idle SECS]

Run the daemon. Under systemd it takes the listening socket that pepsi-console.socket passes (file descriptor 3). Without socket activation (a host without systemd, or a test) it binds [pepsi-console] SOCKET itself, owned by root with group pepsi-httpd and mode 0660. It exits after SECS seconds (default 300) in which no console exists, attached or detached.

shell

The restricted shell. The daemon starts it as the session leader of each console’s pseudo-terminal, with a cleared environment: TERM=xterm-256color, LANG=C.UTF-8, a PATH of the installation’s program directory, /usr/bin and /bin, and PEPSI_CONSOLE_USER and PEPSI_CONSOLE_ID naming the administrator and the console. It reports every command and its exit status to the daemon on its standard error, which the daemon reads and turns into the audit record; the programs that it starts get the terminal as their standard error instead. Started by hand, for a test, it works the same, but its reports go to the terminal and nothing is audited.

The daemon also has a hidden subcommand, exec-as, through which the shell starts a program. It checks the command against the table of programs again, sets the program’s account and runs the program from the installation’s program directory with -c and the host’s configuration file first. It is not meant to be run by hand.

96.1.67.1.5. The restricted shell

The shell shows the prompt pepsi@HOST> and, when it starts, one line that names the administrator and the command help.

Line editing. Left and Right, Home and End (or Ctrl-A and Ctrl-E) move the cursor; Backspace and Delete remove a character; Ctrl-U removes the text before the cursor, Ctrl-K the text after it and Ctrl-W the word before it. Up and Down walk through the last 200 lines entered in this console. Ctrl-L clears the screen, Ctrl-C abandons the line and Ctrl-D on an empty line ends the console. Tab completes a program name and, as the second word, one of the program’s subcommands, which the shell reads from the program’s --help; when several fit, Tab lists them.

Words. A line is split into words at white space. Single quotes, double quotes and a backslash keep white space inside a word, as in a POSIX shell. An unquoted |, &, ;, <, >, (, ), $ or backquote refuses the whole line with the message that the console runs one Pepsi command and no shell operators. Nothing is expanded: no wildcard, no ~ and no variable.

Built-in commands.

help

List the programs that the console runs, one line each.

history

Show the lines entered in this console.

clear

Clear the screen.

exit, quit

End the console.

Running a program. The first word must name a program in the table below; anything else is refused. The shell starts the program from the installation’s program directory by its absolute path, as the program’s account (supplementary groups, group and user, in that order), with -c and the host’s configuration file put first, as the programs’ grammar requires. A line that gives -c or --config itself is refused, in every spelling, a cluster of short options such as -vc included: the console always uses the host’s configuration. The subcommands serve and worker are refused too, since a daemon or a stage worker does not belong in an interactive terminal, and so is pepsi-setup apply, the privileged applier.

The program runs in a process group of its own, which owns the terminal while it runs, so Ctrl-C reaches the program and not the shell. The console has no job control: when Ctrl-Z stops a program, the shell continues it at once and prints a notice. When the program has exited, the shell takes the terminal back and shows the prompt.

96.1.67.1.5.1. Programs

The shell runs these programs, under these accounts. The account is the one under which the program’s own systemd units and timers run it, or the one that its manual page names:

Program

Runs as

For

pepsi-setup

root

Validation, checks, DNS records, certificates, the schema, the interview (--wizard).

pepsi-config

root

The effective configuration, the overlay, export and import.

pepsi-keys

root

Identities, correspondents’ keys, trust anchors, second factors, the managed PKI, the user directory. It runs as root like its timers and becomes pepsi-crypto for each database call.

pepsi-status

pepsi

The health report.

pepsi-queue

pepsi

The queue: list, show, requeue, quarantine.

pepsi-settings

pepsi

Per-address settings.

pepsi-whitelist

root

Whitelists. The program is setuid pepsi-whitelist; started by root, it may act for every local account.

pepsi-list, pepsi-archive

pepsi

Mailing lists and their archives.

pepsi-quota

pepsi

Mailbox quotas (its setgid bit supplies the group pepsi-maildir).

pepsi-reputation

pepsi

IP blocklists and the self-check.

pepsi-tlsrpt

pepsi

TLS reports.

pepsi-dkim

pepsi-dkim

DKIM keys: status, records, rotation.

pepsi-greylist

pepsi-greylist

Greylisting state and rules.

help prints the table that the shell actually uses. No stage program (pepsi-stage-*), no helper (pepsi-helper-*), no daemon, pepsi-sendmail, pepsi-failure-bouncer, pepsi-telemetry-client and pepsi-console itself are in it.

Warning

A console is as powerful as root. pepsi-setup, pepsi-config, pepsi-keys and pepsi-whitelist run as root; the first two can rewrite the configuration, which names the programs that the pipeline runs, and pepsi-keys reaches every private key. Give cli:exec only to administrators whom you would give a root shell. See pepsi-httpd(1) and the manual’s threat model.

96.1.67.1.6. Socket protocol

Only pepsi-httpd speaks this protocol. The daemon checks the peer of every connection with SO_PEERCRED: anything other than the pepsi-httpd account, root or the daemon’s own account (which matters only for a daemon that a test runs unprivileged) is closed without an answer and logged.

  1. The client sends one line of JSON, at most 8 KiB, ending in a newline: {"v":1,"op":"open","session":…,"rows":…,"cols":…,"client":…} to open a console, or the same with "op":"attach" and "console": ID to re-attach one. session is the value of the administrator’s session cookie, and client the browser’s address as pepsi-httpd saw it.

  2. The daemon answers one line: {"ok":true,"console": ID}, where ID is 32 lower-case hexadecimal digits, or {"ok":false,"error": CODE ,"message":…} and closes the connection. CODE is forbidden, no_such_console, busy (the console is attached elsewhere), limit, bad_request or internal.

  3. Then both sides send frames: one byte of type, four bytes of length (big endian, at most 65536) and the payload. From the client: type 1 is input, type 2 a new window size (four bytes: rows and columns, each a big-endian 16-bit number) and type 3 ends the console. From the daemon: type 1 is output, and type 4 the end, with the payload {"reason":…} (exit, expired, revoked, idle or shutdown), after which the daemon closes the connection.

On attach, the daemon first sends what the console has written recently (up to SCROLLBACK) as output frames. A client that closes the connection without sending type 3 detaches: the console keeps running, its output goes to the scrollback, and the same administrator session may attach it again within DETACHED_TIMEOUT. Nobody else may.

96.1.67.1.7. Authorisation

The daemon hashes the session value with SHA-256 and looks it up in pepsi.admin_session and pepsi.admin_account, connecting as the database owner pepsi-owner (it switches its effective user to that account for the connection). It opens or attaches a console only when the session exists, neither its idle nor its absolute expiry has passed, the account is not disabled, and the account holds cli:exec. An attach also needs the session that opened the console. Every refusal answers forbidden without saying why, and writes the audit record cli.refused.

While a console is open, the daemon repeats the check every 60 seconds. When the session has expired, been signed out or lost the scope, the console ends with the reason expired or revoked and its programs are ended. IDLE_TIMEOUT without input ends a console too (reason idle). When the database cannot answer a check, the console keeps running and the next check asks again, so a session that was signed out or lost its scope keeps its open consoles until the database answers.

This check keeps a request that pepsi-httpd handles wrongly from opening a console, and binds every console to an account and a session. It does not keep out code that runs as pepsi-httpd: that account may write the console’s sessions and accounts in the database. While pepsi-console.socket is armed, a compromised pepsi-httpd therefore reaches root.

96.1.67.1.8. Audit

The daemon, never the shell, writes these records to pepsi.event_log. Each names the administrator’s account, the client address and the console:

cli.open, cli.attach, cli.detach, cli.close

A console was opened, attached, detached or ended (cli.close with the reason).

cli.command

A program ran: its arguments word for word, the account it ran as and its exit status.

cli.refused

An open or attach that was refused, or a line that the shell refused. A line that names no program of the table is recorded only as such a refusal.

cli.open and cli.close also appear in the console’s Logs > System Events, as job cli. The journal of pepsi-console.service has the same events. What is typed in answer to a program is never logged: a passphrase that a program asks for reaches only that program. The arguments of a command line are logged, and anyone with logs:read can read them, so a secret typed as an argument ends up in the audit log. Let the program ask for a secret instead.

96.1.67.1.9. Configuration

[pepsi-console] is read from the configuration file only, never from the database overlay. pepsi-httpd reads SOCKET from the same section.

SOCKET

The daemon’s socket (default /run/pepsi/console.sock).

MAX_CONSOLES

How many consoles may exist on the host at once, attached or detached (default 16). One more is refused with limit.

MAX_PER_SESSION

How many consoles one administrator session may have at once (default 4).

DETACHED_TIMEOUT

How long a detached console waits to be attached again before it is ended (default 2 min). A page change in the browser detaches a console for a moment, so keep this above a few seconds.

SCROLLBACK

How much recent output a console keeps for an attach, as a size such as 256K (the default); at most 16 MiB.

IDLE_TIMEOUT

How long a console may go without input before it is ended (default 15 min).

[pepsi-admin] CLI (auto, yes or no) decides whether pepsi-httpd offers the console at all; see pepsi.conf(5).

96.1.67.1.10. Global Options

-c FILE, –config FILE

Read the configuration from FILE instead of searching the default locations. The shell passes the same file to every program that it starts.

-L LOGLEVEL, –log LOGLEVEL

Set the logging verbosity. LOGLEVEL is one of error, warn, info, debug or trace (default: [pepsi] LOG, else info).

-v, –verbose

Show log messages from all sources, including third-party libraries.

-h, –help

Print a usage summary and exit.

-V, –version

Print the version and exit.

96.1.67.1.11. Files

/run/pepsi/console.sock

The daemon’s socket (root:pepsi-httpd, 0660).

/usr/lib/systemd/system/pepsi-console.socket, pepsi-console.service

The units, in the package pepsi-httpd-admin. Without them the console offers no CLI windows.

96.1.67.1.12. Exit Status

0

The daemon exited after its idle time, or the shell ended normally.

1

The configuration could not be read, the socket could not be bound, or the database could not be reached.

78

The database schema belongs to another Pepsi release; run pepsi-setup schema (see pepsi-setup(1)).

96.1.67.1.13. Examples

Arm the CLI console on this host (it ships disabled):

systemctl enable --now pepsi-console.socket

Turn it off again, without removing a package:

systemctl disable --now pepsi-console.socket

See which consoles were opened and what they ran:

sudo -u pepsi-owner psql -d pepsi -c \
    "SELECT at, actor, kind, detail FROM pepsi.event_log
      WHERE kind LIKE 'cli.%' ORDER BY at DESC LIMIT 50"

96.1.67.1.14. See Also

pepsi-httpd(1), pepsi-setup(1), pepsi-config(1), pepsi-keys(1), pepsi.conf(5)

96.1.67.1.15. Bugs

Report bugs to the Pepsi issue tracker.