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.socketpasses (file descriptor 3). Without socket activation (a host without systemd, or a test) it binds[pepsi-console] SOCKETitself, owned byrootwith grouppepsi-httpdand mode0660. It exits after SECS seconds (default300) 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, aPATHof the installation’s program directory,/usr/binand/bin, andPEPSI_CONSOLE_USERandPEPSI_CONSOLE_IDnaming 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.
helpList the programs that the console runs, one line each.
historyShow the lines entered in this console.
clearClear the screen.
exit,quitEnd 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 |
|---|---|---|
|
|
Validation, checks, DNS records, certificates, the schema, the
interview ( |
|
|
The effective configuration, the overlay, export and import. |
|
|
Identities, correspondents’ keys, trust anchors, second factors, the
managed PKI, the user directory. It runs as root like its timers and
becomes |
|
|
The health report. |
|
|
The queue: list, show, requeue, quarantine. |
|
|
Per-address settings. |
|
|
Whitelists. The program is setuid |
|
|
Mailing lists and their archives. |
|
|
Mailbox quotas (its setgid bit supplies the group |
|
|
IP blocklists and the self-check. |
|
|
TLS reports. |
|
|
DKIM keys: status, records, rotation. |
|
|
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.
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.sessionis the value of the administrator’s session cookie, andclientthe browser’s address as pepsi-httpd saw it.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 isforbidden,no_such_console,busy(the console is attached elsewhere),limit,bad_requestorinternal.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
1is input, type2a new window size (four bytes: rows and columns, each a big-endian 16-bit number) and type3ends the console. From the daemon: type1is output, and type4the end, with the payload{"reason":…}(exit,expired,revoked,idleorshutdown), 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.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.closeA console was opened, attached, detached or ended (
cli.closewith the reason).cli.commandA program ran: its arguments word for word, the account it ran as and its exit status.
cli.refusedAn 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.
SOCKETThe daemon’s socket (default
/run/pepsi/console.sock).MAX_CONSOLESHow many consoles may exist on the host at once, attached or detached (default
16). One more is refused withlimit.MAX_PER_SESSIONHow many consoles one administrator session may have at once (default
4).DETACHED_TIMEOUTHow 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.SCROLLBACKHow much recent output a console keeps for an attach, as a size such as
256K(the default); at most 16 MiB.IDLE_TIMEOUTHow 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,debugortrace(default:[pepsi] LOG, elseinfo).- -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.sockThe daemon’s socket (
root:pepsi-httpd,0660)./usr/lib/systemd/system/pepsi-console.socket,pepsi-console.serviceThe 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.