Running your own server
Connect to a team's virtx-server-tcp, and run one on your own machine, signing users in through your OpenID Connect provider.
virtx-server-tcp is the VirtX server for a team.
It runs continuously on a machine you control, and serves every user that your OpenID Connect (OIDC) provider signs in.
Each user works in their own projects and in projects others share with them; see Managing projects.
If you only need sandboxes for yourself on your own machine, you don’t need this server: Client.spawn() starts a local server for your program. See Quick start.
This page has two parts:
- Connecting to a server, for each user.
- Running the server, for the administrator.
Connecting to a server
Your administrator gives you the server’s URL. These examples use https://virtx.example.
-
Sign in once with the
virtxcommand.uvx(orpipx run) andnpxrun it without installing it; to install it, see Installing. The command asks the server which OIDC provider to use, then shows a code for you to approve in your browser:uvx virtx login https://virtx.example# ornpx -y @brekkylab/virtx login https://virtx.example -
In your program, connect with
CommandAuth. The client runsvirtx tokento get a token, and runs it again whenever the token expires:
from virtx import Client, CommandAuth
client = Client.connect("https://virtx.example", CommandAuth("uvx", ("virtx", "token", "--json")))const client = Client.connect('https://virtx.example', { type: 'command', program: 'npx', args: ['-y', '@brekkylab/virtx', 'token', '--json'],})use virtx::{Auth, Client};
let client = Client::connect( "https://virtx.example", Auth::Command { program: "uvx".into(), args: vec!["virtx".into(), "token".into(), "--json".into()] }, None,)?;Other cases:
- The provider gives its public clients a secret: pass it to
virtx loginwith--client-secret. - Your program gets tokens some other way: pass the token directly with
BearerAuthin Python,{ type: 'bearer', token }in Node.js, orAuth::Bearerin Rust. The client doesn’t refresh a bearer token, so replace it withset_authbefore it expires. - You are signed in to more than one provider: tell
virtx tokenwhich one to use:uvx virtx token --json --issuer https://idp.example --client-id virtx.
uvx virtx whoami shows who is signed in, and uvx virtx logout signs out. See Signing in in the CLI reference.
Running the server
Install
- Check that the machine meets the requirements for running VMs.
- Download
virtx-server-tcp-<os>-<arch>.tar.gzfrom a release. - Unpack it into its own directory, and run
virtx-server-tcpfrom that directory. The server loads the files it needs from the same directory.
Configure
Write a server.json:
{ "listen": "127.0.0.1:8470", "home": "/var/lib/virtx", "oidc": { "issuer": "https://idp.example", "client_id": "virtx" }}Then start the server with it:
virtx-server-tcp serve --config server.json| Field | What it sets |
|---|---|
listen |
The address and port the server listens on. |
home |
The directory where the server stores everything its users create, including sandboxes. When the server restarts with the same home, its sandboxes and their files are still there. Default: $VIRTX_HOME, or a virtx directory in the server user’s cache directory. |
oidc |
The OpenID Connect provider users sign in with; see Add users. |
origins |
The web pages allowed to call the server from a browser, such as ["https://app.example"]. Without it, browsers are refused; programs are not affected. |
private_registries |
Registries on the server’s machine or its private network that image jobs may reach, such as ["registry.internal:5000"]; see Pull and push. Without it, jobs reach only registries on public addresses. |
registry_mirror |
A mirror of Docker Hub, such as "mirror.gcr.io", that pulls of Docker Hub’s images without credentials try first, a build’s base among them; see Pull and push. Without it, they go to Docker Hub. |
share_public_images |
true to share pulls without credentials between the server’s projects; see Share public images. false unless set. |
listen and oidc are required. The server refuses to start if server.json contains a field it doesn’t recognize.
Under home, each project’s images, sandboxes and volumes are stored in project/<id>/.
Serve it over HTTPS
The server speaks plain HTTP. Put a reverse proxy that terminates TLS in front of it, as for any HTTP service:
- Clients send tokens to remote servers only over HTTPS, so users must reach the server at an
https://URL. - The proxy must pass WebSocket connections through, because ports are reached over WebSockets.
- If the proxy runs on the same machine, set
listento127.0.0.1. Listen on another address only when the proxy runs on another machine.
Share public images
Each project keeps its own images, so when two projects pull the same public image, the server downloads it twice.
With "share_public_images": true, an anonymous pull (including a build’s base image) first checks whether another project on the server already pulled the same image, as the registry serves it now. If so, the server reuses that copy, with the layers stored once on disk, and downloads nothing.
Pulls with credentials are never shared, and neither are images a project built or pushed.
Turn it on only when the server’s users may know this about each other, for example on a server for one person or one team. Leave it off when projects belong to people or organizations that must not learn anything about each other.
Add users
The server has no user list of its own. Anyone your OIDC provider signs in to the client you configure is a user, and nobody else can get in. To add or remove a user, allow or deny them access to that client in your provider. Allow only your team.
- In your provider, register a public client that allows the device authorization flow.
- Put the provider and the client in the
oidcfield ofserver.json:
| Field | What it sets |
|---|---|
issuer |
The provider’s issuer URL. |
client_id |
The client you registered. |
username_claim |
The ID token claim used as the user’s name on the server. Default: email, which is accepted only once the provider has verified it. |
jwks_uri |
The URL of the provider’s signing keys, for a provider without a discovery document. Most providers don’t need it. virtx login requires a discovery document, so with such a provider, users must get tokens another way and connect with a bearer token, as Connecting to a server shows. |
Users add each other to projects by user name, so with the default claim, teammates add each other by email address.
- Give your users the server’s URL, and the client’s secret if your provider issued one. Connecting to a server shows what they do next.
Troubleshooting
-
401,unauthorized,no token this server knowsCause: The token was not signed by
oidc.issuerfor itsclient_id, or it expired, or the provider has not verified the user’s email.Fix: Sign in again with
virtx login <url>. With the defaultusername_claim, verify the email at the provider, or set another claim. -
not signed in; run virtx login <the server's URL>Cause:
virtx tokenorvirtx whoamiran with no session.Fix: Run
virtx login <url>. -
… names no provider to sign in toCause: The URL is not a
virtx-server-tcpwithoidcset.Fix: Check the URL, or pass
--issuerand--client-id. -
The client refuses to send a token in the clear
Cause: The URL is
http://to another machine.Fix: Put TLS in front of the server and use
https://. -
403, from a page in a browserCause: The page’s origin is not in
origins.Fix: Add it to
origins. -
The server won’t start, naming an unknown field
Cause: A typo, or a field the server does not have, in
server.json.Fix: Use only the fields listed above.
-
private_registries: "…": a registry is named host or host:portCause: A scheme or a path in a registry, or in
registry_mirror.Fix: Give only
hostorhost:port.
Next
- Managing projects: what your users do on the server, and how they share it.
- CLI: sign in, and manage the server’s images from a shell.