Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
3c1c527
feat: add isomorphic crypto primitives and message protocol
codebyant Nov 22, 2026
35066d5
Merge feat/agent--T10 into feat/agent
codebyant Nov 22, 2026
b4ead1a
feat: add agent runtime, state store, websocket client, command queue…
codebyant Nov 22, 2026
0c53e4c
feat: add account vault, recovery codes, password policy, and sessions
codebyant Nov 22, 2026
108868a
Merge feat/agent--T11 into feat/agent
codebyant Nov 22, 2026
111c727
Merge feat/agent--T13 into feat/agent
codebyant Nov 22, 2026
071e7fe
feat: add agent pairing, account trust persistence, and session revoc…
codebyant Nov 22, 2026
77bfbe1
Merge feat/agent--T12 into feat/agent
codebyant Nov 22, 2026
9d54423
feat: add Linux installer, systemd units, polkit rule, network isolat…
codebyant Nov 22, 2026
11cf17a
fix: use valid shellcheck directive syntax in installer
codebyant Nov 22, 2026
44c9287
feat: add confined server file manager and safe zip implementation
codebyant Nov 22, 2026
08b07b5
feat: add Minecraft server runtime, managed Java, loaders, and console
codebyant Nov 22, 2026
3c1bdb4
feat: add Ed25519 signed auto-updater, systemd apply units, and relea…
codebyant Nov 22, 2026
ed4b3c8
fix: harden update staging against dangling symlinks, redirect bypass…
codebyant Nov 22, 2026
76ca9ac
fix: harden file confinement, upload staging isolation, and archive v…
codebyant Nov 22, 2026
17db9f0
fix: harden server runtime inputs, console streaming and static invar…
codebyant Nov 22, 2026
eb8b27d
Merge feat/agent--T17 into feat/agent
codebyant Nov 22, 2026
a704021
Merge feat/agent--T20 into feat/agent
codebyant Nov 22, 2026
c44ab33
Merge feat/agent--T15 into feat/agent
codebyant Nov 22, 2026
7572b65
ci: run systemd-analyze verify with sudo so it can read the servers d…
codebyant Nov 22, 2026
90f3ddc
feat: wire files command handlers into agent runtime
codebyant Nov 22, 2026
9d7aff5
feat: add server state, mod management, origin 3-way sync, and server…
codebyant Nov 22, 2026
bf15357
feat: add backup destinations, world consistency, and protocol commands
codebyant Nov 22, 2026
86f6b2c
feat: add playit headless tunnel manager and protocol commands
codebyant Nov 22, 2026
8ba5690
feat: wire backup hook, backup handlers, and playit tunnel into agent…
codebyant Nov 22, 2026
9dc3046
fix: harden state, backup, and tunnel security boundaries
codebyant Nov 23, 2026
9cfb0e9
feat: build the protocol, crypto and vault libraries for consumption …
codebyant Nov 23, 2026
cbc4602
ci: smoke-test the built library instead of diffing generated output
codebyant Nov 23, 2026
f1a07be
feat: reply_to, event envelope, subscriptions, agent auth, signed req…
codebyant Nov 23, 2026
8577053
feat: chunked blob crypto, world import, encrypted serverpacks, backu…
codebyant Nov 23, 2026
5d88c77
feat: session commands reply to the session key by default and accept…
codebyant Nov 23, 2026
d0ea320
test: open session replies with the session key in the pairing e2e
codebyant Nov 23, 2026
e478883
fix: server file permissions, installer service restart, exec cwd and…
codebyant Nov 23, 2026
747aee4
fix: create the server console log as the agent so it stays readable;…
codebyant Nov 23, 2026
36cf1c3
feat: add tegrad-perms@.service unit to make 0600 server files group-…
codebyant Nov 23, 2026
5f67001
feat: reject placeholder release key and add active network isolation…
codebyant Nov 23, 2026
ea2e482
fix: silence shellcheck SC2016 for intentional inner bash arg expansion
codebyant Nov 23, 2026
1103bc5
feat: add host.info read command and export protocol schemas
codebyant Nov 24, 2026
53960fd
feat: report the host's external IPv4 addresses in host.info
codebyant Nov 26, 2026
bf7e252
fix: read the host addresses from the routing table when the sandbox …
codebyant Nov 26, 2026
2472544
fix: keep host.info working when the sandbox makes the interface look…
codebyant Nov 26, 2026
9701549
feat: add the server.stats read command
codebyant Nov 26, 2026
4a34dc5
feat: add server.change_runtime command to switch version and loader
codebyant Nov 26, 2026
62aeb07
feat: upload secondary backups in background with progress events and…
codebyant Nov 26, 2026
faa64f6
feat: add background server.install_modpack command with progress eve…
codebyant Nov 26, 2026
e325167
fix: refuse a modpack built for another Minecraft version or loader t…
codebyant Nov 27, 2026
09531c6
fix: install modpacks without losing what already landed, take Tegra …
codebyant Nov 27, 2026
c2a0b9c
fix(security): keep permission changes inside the server folder
codebyant Nov 28, 2026
43f8313
fix(files): reach server folders only through open descriptors
codebyant Nov 28, 2026
d1e7c36
feat(protocol): signing levels and the elevated session
codebyant Nov 28, 2026
b772990
build(lib): rebuild for signing levels
codebyant Nov 28, 2026
ad2d54d
feat(agent): run commands per server lane so one slow task no longer …
codebyant Nov 28, 2026
6d8b924
feat(state): read the server mods folder into a Tegra mods manifest, …
codebyant Nov 28, 2026
3dbddb3
fix(state): read mod metadata from real jars
codebyant Nov 28, 2026
d3c9370
feat(state): identify server mods by hash and record their project
codebyant Nov 28, 2026
5e28a6b
build(lib): rebuild for server mods toggle, replace and identify
codebyant Nov 28, 2026
dd69a3e
feat(tunnel): start playit on key save and resume it at boot
codebyant Nov 29, 2026
fe6f471
feat(tunnel): link playit by claim and create server tunnels
codebyant Nov 29, 2026
e610f44
build(lib): rebuild for playit claim and server tunnels
codebyant Nov 29, 2026
1c4f2ac
fix(tunnel): create playit tunnels with the current API; console tail…
codebyant Nov 29, 2026
835b883
build(lib): rebuild for playit tunnel fix and console history
codebyant Nov 29, 2026
09c407e
fix(tunnel): give each server its own playit tunnel when ports are sh…
codebyant Nov 29, 2026
ac1174c
feat(server): pick a free port for new servers, name the clash on start
codebyant Nov 29, 2026
6d2b528
build(lib): rebuild for port_in_use
codebyant Nov 29, 2026
f161af9
feat(server): start servers with the machine (on, off, or as they wer…
codebyant Nov 30, 2026
2529b14
feat(tunnel): give a server its own port before its tunnel and report…
codebyant Nov 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
* text=auto eol=lf
# Generated by `bun run build:lib`; consumed through git tags.
lib/** linguist-generated=true
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,37 @@ jobs:
- run: bun run lint
- run: bun run typecheck
- run: bun run test
- run: bun run check:lib

install-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lint installer with shellcheck
run: shellcheck install/install.sh
- name: Verify systemd units
run: |
set -eu
sudo groupadd --system tegrad-srv
sudo useradd --system --gid tegrad-srv --home-dir /nonexistent --no-create-home --shell /usr/sbin/nologin tegrad-srv
sudo groupadd --system tegrad
sudo useradd --system --gid tegrad --home-dir /var/lib/tegrad --no-create-home --shell /usr/sbin/nologin tegrad
sudo usermod -aG tegrad-srv tegrad
sudo install -d -o root -g root -m 0755 /opt/tegrad/bin
sudo install -d -o tegrad -g tegrad -m 0700 /var/lib/tegrad /var/lib/tegrad/update /var/lib/tegrad-backups
sudo install -d -o tegrad-srv -g tegrad-srv -m 2770 /var/lib/tegrad-servers /var/lib/tegrad-servers/test
sudo install -d -o root -g tegrad -m 0750 /run/tegrad-server
printf '#!/bin/sh\nexit 0\n' | sudo tee /opt/tegrad/bin/tegrad /var/lib/tegrad-servers/test/start.sh >/dev/null
sudo chmod 0755 /opt/tegrad/bin/tegrad /var/lib/tegrad-servers/test/start.sh
tmp_dir=$(mktemp -d)
for unit in tegrad.service tegrad-update.service tegrad-update.path tegrad-server@.service tegrad-server@.socket tegrad-perms@.service; do
sed \
-e 's|@TEGRAD_BIN_DIR@|/opt/tegrad/bin|g' \
-e 's|@TEGRAD_BIN@|/opt/tegrad/bin/tegrad|g' \
-e 's|@TEGRAD_STATE_DIR@|/var/lib/tegrad|g' \
-e 's|@TEGRAD_SERVERS_DIR@|/var/lib/tegrad-servers|g' \
-e 's|@TEGRAD_BACKUPS_DIR@|/var/lib/tegrad-backups|g' \
-e 's|@TEGRAD_RUN_DIR@|/run/tegrad-server|g' \
"install/units/${unit}" > "${tmp_dir}/${unit}"
done
sudo systemd-analyze verify "${tmp_dir}/tegrad.service" "${tmp_dir}/tegrad-update.service" "${tmp_dir}/tegrad-update.path" "${tmp_dir}/tegrad-server@test.service" "${tmp_dir}/tegrad-server@test.socket" "${tmp_dir}/tegrad-perms@test.service"
134 changes: 134 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Release

on:
release:
types: [published]
schedule:
- cron: "0 6 * * *"
workflow_dispatch:

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- run: bun install --frozen-lockfile
- run: bun run lint
- run: bun run typecheck
- run: bun run test

- name: Determine release tag and channel
id: meta
env:
EVENT_NAME: ${{ github.event_name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
set -eu
if [ "$EVENT_NAME" = "release" ]; then
TAG="$RELEASE_TAG"
else
BASE_VERSION=$(bun -e 'import pkg from "./package.json"; process.stdout.write(pkg.version.split("-")[0] ?? "0.0.0")')
STAMP=$(date -u +%Y%m%d%H%M)
TAG="v${BASE_VERSION}-nightly.${STAMP}"
fi
CHANNEL=$(bun -e 'import { parseReleaseTag } from "./src/update/channels"; process.stdout.write(parseReleaseTag(process.argv[1] ?? "").channel)' -- "$TAG")
VERSION=$(bun -e 'import { parseReleaseTag } from "./src/update/channels"; process.stdout.write(parseReleaseTag(process.argv[1] ?? "").raw)' -- "$TAG")
printf 'tag=%s\n' "$TAG" >> "$GITHUB_OUTPUT"
printf 'version=%s\n' "$VERSION" >> "$GITHUB_OUTPUT"
printf 'channel=%s\n' "$CHANNEL" >> "$GITHUB_OUTPUT"

- name: Verify production release key
env:
RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }}
run: |
set -eu
bun -e '
import { ready, toBase64Url } from "./src/crypto";
import {
getReleasePublicKey,
isPlaceholderReleaseKey,
parseReleaseSigningKey,
} from "./src/update";

await ready();
const embedded = getReleasePublicKey();
if (isPlaceholderReleaseKey(embedded)) {
throw new Error(
"Refusing to publish release: src/update/release-key.ts still embeds the public test release key.",
);
}

const rawSecret = process.env.RELEASE_SIGNING_KEY;
if (!rawSecret || rawSecret.trim().length === 0) {
throw new Error("RELEASE_SIGNING_KEY secret is required for release builds.");
}
const derived = parseReleaseSigningKey(rawSecret);
if (isPlaceholderReleaseKey(derived.publicKey)) {
throw new Error(
"Refusing to publish release: RELEASE_SIGNING_KEY secret is the public test release key.",
);
}
if (toBase64Url(derived.publicKey) !== toBase64Url(embedded)) {
throw new Error(
"Refusing to publish release: RELEASE_SIGNING_KEY public key does not match embedded RELEASE_PUBLIC_KEY_BASE64URL.",
);
}
'

- name: Build Linux release binaries
env:
RELEASE_VERSION: ${{ steps.meta.outputs.version }}
run: |
set -eu
bun -e '
import { readFileSync, writeFileSync } from "node:fs";
const ver = process.env.RELEASE_VERSION;
if (!ver) throw new Error("Missing RELEASE_VERSION");
const src = readFileSync("src/version.ts", "utf8");
const updated = src.replace(/export const VERSION = "[^"]+";/, `export const VERSION = "${ver}";`);
if (updated === src && !src.includes(`"${ver}"`)) throw new Error("Failed to stamp src/version.ts");
writeFileSync("src/version.ts", updated, "utf8");
'
mkdir -p dist
bun build --compile src/index.ts --target=bun-linux-x64 --outfile dist/tegrad-linux-x64
bun build --compile src/index.ts --target=bun-linux-arm64 --outfile dist/tegrad-linux-arm64

- name: Sign checksums and channel manifest
env:
RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }}
TAG: ${{ steps.meta.outputs.tag }}
REPO: ${{ github.repository }}
run: |
set -eu
bun scripts/sign-release.ts \
--tag "$TAG" \
--assets-dir dist \
--base-url "https://github.com/${REPO}/releases/download/${TAG}"

- name: Publish release assets
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
TAG: ${{ steps.meta.outputs.tag }}
CHANNEL: ${{ steps.meta.outputs.channel }}
run: |
set -eu
ASSETS="dist/tegrad-linux-x64 dist/tegrad-linux-arm64 dist/SHA256SUMS dist/SHA256SUMS.sig dist/${CHANNEL}.json"
if [ "$EVENT_NAME" = "release" ]; then
# shellcheck disable=SC2086
gh release upload "$TAG" $ASSETS --clobber
else
# shellcheck disable=SC2086
gh release create "$TAG" $ASSETS \
--prerelease \
--title "$TAG" \
--notes "Automated nightly build ${TAG}"
fi
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://biomejs.dev/schemas/2.6.8/schema.json",
"files": { "includes": ["**", "!dist", "!node_modules"] },
"files": { "includes": ["**", "!dist", "!lib", "!node_modules"] },
"formatter": { "indentStyle": "space", "indentWidth": 2, "lineWidth": 100 },
"linter": {
"enabled": true,
Expand Down
29 changes: 29 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Installing `tegrad` on Linux

`install.sh` sets up `tegrad` as an unprivileged systemd service with isolated Minecraft server units and LAN network isolation enabled by default.

## Requirements

- Linux (`x86_64` or `aarch64`)
- `systemd` running as PID 1
- `polkit` with JavaScript rules support (`/etc/polkit-1/rules.d`)
- `sudo` (or root) for the initial installation
- `openssl` (1.1.1+ / 3.x) and `sha256sum` for verifying Ed25519 release signatures (`SHA256SUMS.sig`) on fresh `--version` installs

## Install or update

From a release tag (downloads the binary, verifies the Ed25519 signature of `SHA256SUMS` via `SHA256SUMS.sig`, and checks the SHA-256 digest before executing or installing):

```sh
./install/install.sh --version v0.1.0
```

From a locally built binary:

```sh
./install/install.sh --binary ./dist/tegrad
```

Optional flags:

- `--api-url https://...`: writes `api_url` to `/var/lib/tegrad/config.json` (otherwise created once with `https://api.tegramc.com` and preserved on updates).
- `--allow-lan <cidr>`: allows a private/LAN CIDR in the server network drop-in (can be repeated).
- `--require-network-isolation`: fail the installation with a non-zero exit code if the active `IPAddressDeny` self-test detects that cgroup BPF filtering is not enforced (or cannot run).

The installer is idempotent: re-running it updates the binary, units (`tegrad.service`, `tegrad-update.path`, `tegrad-update.service`, `tegrad-server@.service`, `tegrad-server@.socket`), polkit rule, and network drop-in without resetting `/var/lib/tegrad`.

## Signed auto-updates

`tegrad` checks its configured release channel (`stable`, `beta`, or `nightly`) and stages verified updates into `/var/lib/tegrad/update` (`0700`, owned by `tegrad`). The agent itself never has write access to `/opt/tegrad/bin`. When `/var/lib/tegrad/update/ready.json` appears, `tegrad-update.path` activates the sandboxed `tegrad-update.service`, which runs `/opt/tegrad/bin/tegrad apply-update` as `root`:

1. Copies the staged binary and manifest into a private root-owned temporary directory inside `/opt/tegrad/bin`.
2. Re-verifies the Ed25519 manifest signature and SHA-256 hash on the root-owned copy (preventing TOCTOU tampering).
3. Backs up the existing binary to `/opt/tegrad/bin/tegrad.prev`, swaps the new binary atomically, restarts `tegrad.service`, and automatically rolls back if the service fails to become active.

### Replacing the release signing key (before public release)

Development builds embed a well-known test public key (`TEST_RELEASE_PUBLIC_KEY_BASE64URL`). Auto-update, `verify-update`, and `apply-update` fail closed (`placeholder_release_key`) on test-key builds unless `TEGRAD_ALLOW_TEST_RELEASE_KEY=1` is set in the environment, and the release workflow blocks publishing with the test key.

To switch to the production offline Ed25519 release key:

1. Generate a 32-byte Ed25519 seed offline and store its base64url encoding in the `RELEASE_SIGNING_KEY` GitHub Actions secret.
2. Replace `RELEASE_PUBLIC_KEY_BASE64URL` in `src/update/release-key.ts` with the corresponding base64url public key (removing the `TODO(release-key)` comment).
3. Replace `RELEASE_PUBLIC_KEY_PEM` in `install/install.sh` with the matching Ed25519 SPKI PEM (you can format it with `ed25519PublicKeyToPem`).
4. Run `bun run test` to verify `install/install.sh` and `src/update/release-key.ts` match.

After installation, link the agent and verify the setup:

```sh
tegrad link
tegrad doctor
```

## Network isolation and LAN access

By default, `/etc/systemd/system/tegrad-server@.service.d/10-network.conf` denies private, link-local, CGNAT, and loopback address ranges (`IPAddressDeny`) on `tegrad-server@.service`, and only allows private/loopback DNS resolvers detected on the host.

- **Active self-test**: at the end of installation, `install.sh` opens a temporary local TCP listener on `127.0.0.1` and runs a transient `systemd-run` unit with `IPAddressDeny=any` to confirm the kernel enforces cgroup BPF IP filtering. On LXC containers or kernels without `CONFIG_CGROUP_BPF`, `IPAddressDeny` is silently ignored by systemd; `install.sh` prints a warning to stderr (or fails if `--require-network-isolation` was passed) and records the result in `/var/lib/tegrad/network-isolation.json` (`0600`, owned by `tegrad`).
- **`tegrad doctor` check**: `tegrad doctor` reads `/var/lib/tegrad/network-isolation.json` without root and reports `network_isolation` as `OK` (verified within the last 30 days), `FALHA` (not effective), or `INCONCLUSIVO` (never tested, skipped, or older than 30 days). Re-run `install.sh` to refresh the check.
- **LAN players are blocked by default**: systemd's `IPAddressDeny` applies to both inbound and outbound traffic on the server's sockets. If players on your local network need to connect directly, pass `--allow-lan <cidr>` (for example `--allow-lan 192.168.1.0/24`).
- **Changing DNS resolvers later**: if the host's DNS configuration changes after installation, re-run `install.sh` (with your previous flags) to regenerate `10-network.conf` and reload systemd.

## Uninstall

Remove services, units, polkit rule, wrapper, and binary while keeping `/var/lib/tegrad`, `/var/lib/tegrad-servers`, and system users:

```sh
./install/install.sh --uninstall
```

Remove everything including data and system users (prompts for `yes` unless `--yes` is passed):

```sh
./install/install.sh --uninstall --purge
```
Loading
Loading