Skip to main content

CLI

selvara is a command line for the work that belongs in a terminal: listing the hosts you look after, reaching a host over SSH without a VPN, and opening a local port that leads to a service inside a customer's network. It signs in to one or more dashboards and acts as you, with exactly the customers and the role your account has.

It is a single file with no installer. The same binary is built for Linux (amd64, arm64), Windows (amd64) and macOS (amd64, arm64), and it carries the version of the agent it ships with.

Getting it​

Every dashboard serves it, the way it serves the agent:

# Linux and macOS: pick the right os and arch
curl -fsSL "https://monitoring.example.de/api/cli/download?os=linux&arch=amd64" -o selvara
chmod +x selvara && sudo mv selvara /usr/local/bin/
Invoke-WebRequest "https://monitoring.example.de/api/cli/download?os=windows&arch=amd64" -OutFile selvara.exe

os is linux, windows or darwin; arch is amd64 or arm64 (Windows has amd64 only). Names as uname -m and PowerShell print them (x86_64, aarch64) work too. A platform without a binary gets a 404 rather than the nearest match, because a binary for the wrong host only fails when it is started.

In a local checkout the binaries are not part of the repository: build them with npm run cli:build. The Docker image builds them in its agent-builder stage.

Signing in​

selvara login https://monitoring.example.de

The command prints a link and a short code, and opens the link in your browser. On that page, signed in as yourself, check that the program name and address are what you just started, and confirm. If your account has a second factor (an authenticator app, or a code by email), the page asks for a fresh code, even on a device you have told the dashboard to trust: the sign-in becomes a credential that outlives your browser session, so it is not enough that the browser was verified some days ago.

The code is valid for ten minutes and for one sign-in. On a machine without a browser (an SSH session, say) use --no-browser and open the link on any device where you are signed in.

What you get is an ordinary API token, marked Command line, that runs for 90 days. It is listed under Profile → API tokens with the computer's name and when it was last used, and revoking it there signs that computer out at once. selvara logout revokes it from the computer's side.

Where the token is kept on the computer:

  • in the operating system's credential store (Credential Manager, Keychain, Secret Service) when there is one;
  • otherwise in ~/.config/selvara/credentials.json, readable by your account only. The command says so when it falls back, and SELVARA_NO_KEYRING=1 forces the file.

SELVARA_CONFIG_DIR moves the whole folder.

More than one dashboard​

Signing in to a second address makes a second profile; it never replaces the first.

selvara profiles # list, with the current one marked
selvara profiles use acme # make one the default
selvara --profile acme ls # or choose per command
SELVARA_PROFILE=acme selvara ls # or per shell
selvara profiles rm acme # sign out and forget it

For scripts and programs that already hold a token, SELVARA_URL together with SELVARA_TOKEN bypasses the profiles altogether. The Remote Connection Manager starts the command line this way.

Listing​

selvara ls # every system you reach
selvara ls acme # one customer's
selvara ls --targets # named tunnel targets instead
selvara ls --json

Hosts are addressed as customer/host: the customer's code (or its name, written in lower case with dashes) and the host's name written the same way, for example acme/web-01. The host half also accepts the reported hostname or the host's id. An address that fits two hosts is refused rather than guessed; use the id for the host part.

SSH without a VPN​

selvara ssh-config >> ~/.ssh/config
ssh root@acme/web-01

ssh-config prints one block that covers every customer you reach:

Match host "acme/*,globex/*" exec "selvara --profile default cert %h"
Host acme/* globex/*
ProxyCommand selvara --profile default proxy %h %p
IdentityFile ~/.config/selvara/profiles/default/id_ed25519
CertificateFile ~/.config/selvara/profiles/default/certs/%h-cert.pub
IdentitiesOnly yes

Each connection then does three things, invisibly:

  1. selvara cert, run by the Match exec line while ssh reads its configuration, makes sure an Ed25519 key exists under the profile's folder (it creates one on first use), asks the dashboard to sign that key for the one host, which returns a short-lived SSH certificate, and writes it where CertificateFile points. It must come first because ssh loads the certificate before it starts the ProxyCommand; a certificate written by the proxy would only serve the next login. It prints nothing when it cannot get one;
  2. selvara proxy does the same if the certificate is still missing, and says why when it cannot;
  3. it opens a relayed connection to the host's SSH port and hands it to ssh on stdin and stdout.

The host must trust the dashboard's SSH certificate authority, and an access policy must allow your account on it; see SSH CA. Because the certificate is short-lived and issued to your account, there is nothing to revoke on the host when somebody leaves: their token stops working and the last certificate runs out.

Re-run selvara ssh-config after a customer is added; the block lists customers, not individual hosts, so a new host at a known customer needs nothing.

Tunnels​

selvara tunnel acme/database # a named target, on a free local port
selvara tunnel acme/database -L 5432 # a fixed local port
selvara tunnel acme/web-01:3389 -L 13389 # a port of the host itself
selvara tunnel acme/database --reason "Ticket 4711"
selvara tunnel --entry <id> --path tunnel # choose the path: agent or tunnel (only with --entry)
selvara tunnel --entry <id> -L 23389 # an access entry that opens through the agent or a tunnel host

A named target is a service inside a customer's network that a manager has given a name, such as a database or a printer's web page; its address and port are fixed on the server, so a tunnel can only lead where it was defined. For a host itself, give the port after a colon; that reaches the host the agent runs on and nothing else. Which tunnels are allowed, how RDP and VNC are used through one, and the limits are on the Tunnels page.

Customers can ask for a reason with every tunnel, or for another person to approve it first. --reason TEXT (or SELVARA_REASON in the environment, which is also how a ProxyCommand line gets one) supplies the reason. When approval is required the command fails with a message that a request is waiting; ask a manager to approve it under Access → Tunnels → Requests and run it again.

The command prints the local address and keeps running; point your client at it (psql -h 127.0.0.1 -p 5432) and press Ctrl+C when finished. Every connection through the port gets its own relay session. The local port listens on the loopback interface only, unless you pass an address (-L 0.0.0.0:5432), which you should do only on purpose.

--entry ID opens the tunnel of an access entry instead of a target (--web-address ID, the older spelling for the web pages of a host, still works: they are web entries now and keep their ids): the destination is the one saved on the host, and every socket of the launch after the first reuses its approval. If the customer requires approval the command waits (up to 15 minutes, printing that it does) and goes on once it is granted; interrupting it withdraws the request. With either, a -L port that is already in use falls back to a free port on the same address instead of failing, and the printed address says which.

--path agent or --path tunnel (with --entry only) forces the route of the launch: through the host's own agent, or through its tunnel host. Without it the dashboard picks the route: the tunnel host when the host's tunnel switch is on, else the agent when it has one. It is sent with every socket of the launch. A route the host does not have is answered with the dashboard's error, and the desktop app uses the flag for its "connect via agent" and "connect via tunnel host" menu items. The flag needs CLI 3.3.0 or newer; older helpers reject the unknown flag.

--json prints one JSON object per line for programs; the desktop app reads that: listening (with address and port), pending_approval (with requestId) and approved while a launch waits, ready once a --warm launch is open, error (with the dashboard's code, and reason where it gives one) and closed. selvara version --json prints {"version": ...}.

Three more flags exist for programs that start the command and look after it, as the desktop app does:

  • --warm (with --entry) opens the launch at once instead of at the first socket, so the reason and the approval are settled before a client connects. It reports ready when the launch is open. If the dashboard refuses it, the command prints the error and exits with a failure instead of waiting for a client.
  • --idle-timeout 15m stops the command after that long with no socket open. The last event is closed with code idle.
  • --stdin-lifetime stops the command when its standard input is closed, which is how it notices that the program that started it has gone, and how that program asks it to stop cleanly: a request that is still waiting is withdrawn. The last event is closed with code parent_gone.

Exit codes and errors​

0 on success, 1 for a failure (the message says what), 2 for a mistake in the command line, 130 when interrupted. A rejected or expired token ends with a reminder to run selvara login again.

What the server side offers​

The command line talks to these endpoints of the dashboard:

EndpointUsed for
POST /api/cli/devicestarts a sign-in; answers with a device code, the short user code and the page to confirm it on
POST /api/cli/tokenthe poll; answers authorization_pending, slow_down, access_denied, expired_token or the token
POST /api/cli/logoutrevokes the calling command-line token
GET /api/systemsls, ssh-config, alias resolution
GET /api/access/targetsnamed tunnel targets
POST /api/access/ssh-certthe SSH certificate for one host
POST /api/access/tunnelsa relay session for a target or a host port; see Tunnels
GET /api/cli/downloadthe binaries

The sign-in endpoints are open, because there is nothing to authenticate with yet; they are rate limited per address, and what they hand out does nothing until a signed-in person confirms the code. Confirming is done in the browser only: a token cannot confirm a sign-in, so a stolen token cannot mint successors. Signing in, confirming and signing out are written to the audit log as cli.login, cli.authorize and cli.logout.

Against a dashboard that does not offer the tunnel and target endpoints, ls still works and proxy and tunnel fail with the server's answer (an HTTP 404) instead of connecting.

Troubleshooting​

  • "The code is unknown or has expired": codes last ten minutes; run selvara login again.
  • The browser page shows a different program or address than you started: refuse it. Someone may be trying to get you to confirm their sign-in.
  • selvara asks to sign in again after a while: the token ran its 90 days, or was revoked in the profile. The list under Profile → API tokens shows which.
  • No credential store on Linux: the token is in ~/.config/selvara/credentials.json; keep that file out of backups you share.