intern

module
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT

README

Intern

Intern is a Go API, internctl CLI, and Next.js authenticated web app in one repository.

The API preserves authentication, authorization, sessions, audit logs, VLAN and network-device CRUD, disabled device state, gizmo kiosk destinations, and RADIUS policy snapshots. The authenticated home route shows live host metrics from Prometheus.

The monitoring page reuses the groups and lanes in the frontend metrics YAML. Electrical lanes support watts, volt-amperes-reactive, volts, amperes, and hertz; use the existing percent format for power factor multiplied by 100. Signed extents such as [-5000, 5000] display imported and exported active power. An optional lane normalRange, such as { min: 210, max: 240 } for voltage or { min: 90 } for power factor, colors only excursions outside those inclusive bounds. Below-range values use blue bands and above-range values use green. For these lanes, extent scales the excursion from the nearest bound, while live and hover readouts retain the actual measurement. Missing samples remain gaps. Lanes without normalRange continue showing measurement magnitude.

Inventory pages use segmented filters. Each text token searches its selected field with literal, case-insensitive substring matching and applies on Enter or focus-out. Names, MACs, VLAN descriptions, and Gizmo URLs accept text fragments; VLAN IDs, colors, status, and destination state remain exact. Tokens combine using AND. Escape cancels an edit; removing or clearing filters discards drafts.

Audit Logs use the same segmented bar. Actor and Metadata tokens use literal, case-insensitive contains matching; Action, Resource Type, and Resource ID match exactly. All filters combine using AND on the server before pagination. The API exposes actor_username_contains and metadata_contains for text tokens; existing exact filters and global q search remain available to API clients. Exact actor restrictions in Activity URLs appear as removable Actor (exact) tokens. Category choices come from filter_options across all records, independent of the current filters or page. Changing a filter resets the page and preserves page size and sort order.

Update both list and count predicates when changing audit search, and regenerate OpenAPI and SQLC output. For a split API/web rollout, update the API first: the web app requires the contains parameters and filter_options response. No database migration is needed for search.

Dashboard layout

Admins can use Sections on Home to show, hide, and reorder whole metric sections for everyone. Save applies the shared layout; Cancel discards edits, and Reset restores the metrics configuration order with all sections visible. New sections appear automatically after the saved order. Other viewers see changes on reload. Hiding sections does not change metric collection or polling.

Shared display preferences use authenticated GET /api/v1/preferences and admin-only PATCH /api/v1/preferences. Patches replace supplied top-level namespaces and preserve others. The first namespace is dashboard, containing section_order and hidden_sections arrays of configured IDs. Storage is generic; there are no per-account overrides. Deploy the additive database migration before the updated API and frontend.

Private Wi-Fi passwords

The device editor can save a private Wi-Fi password or retain the shared-password policy. Generate fills an unsaved four-word EFF passphrase; Save commits it and Cancel discards edits. Blank password fields retain the saved value. Turning private access off retains the encrypted password for later reuse. These are saved policies, not live access-point status. Network policy delivery is described below.

Passwords accept 8 to 63 printable ASCII characters. They are encrypted with AES-256-GCM using random nonces and the immutable device UUID as authenticated data. Ordinary device responses expose only enabled/present metadata. Saved passwords are revealed only through an admin-only, audited POST with Cache-Control: no-store; audit records contain neither plaintext nor ciphertext.

RADIUS needs the original Wi-Fi key. This is the recoverable-secret case described by OWASP. The implementation uses Go's AES-GCM with automatic random nonces and follows OWASP's key separation guidance.

Set WIFI_PASSWORD_ENCRYPTION_KEY to a base64-encoded random 32-byte key in the deployment's encrypted secret. Keep it outside the database. Back up both the encrypted database and this key: restoring one without the other cannot recover passwords. Restore the original device UUIDs with the ciphertext. For SOPS deployments, retain the identity needed to decrypt the secret. Keep the same key across replicas and deployments. Do not regenerate it during startup or development. Rotation requires re-encrypting stored records; replacing the environment value alone makes existing ciphertext unreadable. The backend requires this key at startup, like its existing JWT secret.

Apply the additive database migration, provision the backend key, then deploy the API and frontend. Development against the deployed database uses its deployed key.

# Generate and save through stdin, without password arguments or terminal output.
internctl device password generate |
  internctl device update <id> --private-wifi-password --wifi-password
# Alternatively, prompt without echoing the password.
internctl device update <id> --private-wifi-password --wifi-password
internctl device update <id> --private-wifi-password=false
# These explicit actions print a password to stdout.
internctl device password generate
internctl device password show <id>

Remote desktops

Admins add remote desktops under Remote Desktops, then Connect opens a full-window viewer in a new tab. A host must accept web connections (Bektinet's "Allow web connections", port 3390 by default). Each host stores its address, an account and password, and optionally its certificate's SHA-256 fingerprint. Intern trusts only that certificate; with the fingerprint left empty, the certificate seen on the first successful sign-in is pinned and audited (trust on first use, like SSH). Clearing the fingerprint pins again on the next connect. No certificate authority or public DNS name is involved.

The viewer connects directly when it can: it sends a WebRTC offer with the session request, Intern passes it to the host with the ticket, and the host answers with its own addresses only (no STUN or TURN). If the data channel does not open within two seconds, the viewer uses the relay below with the same ticket. The viewer bar shows Direct or Relayed. Video is HEVC when the browser decodes it, else H.264; the host's sound is Opus. Each host has session defaults: Display (fit the window, a preset or a custom size in points, shown scaled to fit without stretching), Retina (two pixels per point on screens that have them), Quality, Frame rate, Sound (this device, the remote computer, or off) and Clipboard (copied text both ways) and Touch input. The viewer bar changes quality, frame rate, sound and touch input for the session.

Touch input sets what a finger does on a touch screen. Trackpad (the default) works like a laptop's: swipe to move a drawn pointer, scaled to the picture and faster for quick swipes; tap to click, double-tap to double-click, hold to right-click, and tap then touch again and move to drag. Touch makes the finger the pointer: tap clicks there, hold right-clicks, moving drags. In both, two fingers scroll. Mice and pens work as usual. Pasting in the viewer sends the browser's copied text first, from the paste event, so no clipboard permission is needed; a copy on the remote computer reaches the browser's clipboard at once, or at the next click or key press where the browser requires one.

Connect asks the backend for a session. The backend decrypts the saved password, signs in to the host over the pinned TLS WebSocket, and returns the host's single-use stream ticket with a relay token. Both expire after 30 seconds. The browser opens /api/v1/remote_desktops/{id}/stream, sending the relay token as the WebSocket subprotocol bearer.<token> beside intern-relay (never in the URL), and the backend relays messages to the host unchanged; it decodes no video. Passwords never reach the browser and are never returned by the API. Leaving the password empty when editing keeps the saved one. Creating, changing, removing and connecting are audited without passwords. The backend logs which side ended each relayed stream and why.

Passwords are encrypted like Wi-Fi passwords, with their own key: set REMOTE_DESKTOP_PASSWORD_ENCRYPTION_KEY to a base64-encoded random 32-byte key in the deployment's encrypted secret, with the same backup, retention and rotation rules as WIFI_PASSWORD_ENCRYPTION_KEY. Without it, hosts can be listed but not saved or used. The backend must reach each host's port. Apply the additive database migration, provision the key, then deploy the API and frontend.

RADIUS policy delivery

GET /api/v1/radius/policy-snapshot returns a versioned FreeRADIUS users file with active device VLANs and enabled private passwords. It serves wired MAC registration and PPSK from one inventory. Disabled devices and retained passwords with private access off are excluded. Unknown devices use the shared password configured at the RADIUS server.

Configure RADIUS_SNAPSHOT_TOKEN_HASHES as comma-separated site=sha256 entries. Hash the exact opaque bearer token supplied to the router. Each site has its own token for independent attribution and revocation; every authorized site receives the same inventory policy. An empty setting denies all downloads. Reusing a token across sites is rejected. Download tokens cannot access human API routes or password-reveal endpoints.

Set the required RADIUS_SNAPSHOT_MAX_BYTES environment variable to a positive byte limit appropriate for the receiver transport. There is no numeric default in the application. This protects receivers with bounded download or file-reading interfaces: an oversized policy is rejected rather than partially published, so they can retain their last good policy. The device service handles inventory and decryption. The HTTP handler formats the policy and enforces the configured byte limit.

Downloads use Cache-Control: no-store. The private-policy response and its persistent cache, staging file, and rollback copy contain recoverable secrets. Use HTTPS with certificate validation and protected, read-only container mounts. FreeRADIUS holds private passwords in control attributes; only a successful PPSK request copies the selected password into the encrypted Tunnel-Password reply. Wired MAB, Enterprise Wi-Fi, operator authentication, and rejected requests do not receive Wi-Fi passwords. Literal values are escaped for FreeRADIUS before parsing.

Revisions depend on effective policy, not inventory names or encryption nonces. Unchanged polls need no disk write or restart. Policy responses at or above the configured byte limit, unreadable active ciphertext, or unavailable inventory return HTTP 503 without partial policy. The router retains its last-good file. Revoking a download token stops updates; it does not erase already cached policy.

Consumers should retain the last working policy when a download fails. Changes apply at a fresh RADIUS authorization; there is no automatic disconnect or CoA.

The optional integration check below exercises a real API/database policy with an external native FreeRADIUS protocol test. The executable receives the runtime image, policy file, and password file as positional arguments. It inherits the caller's environment. All credentials in this check are synthetic.

RADIUS_NATIVE_TEST_SCRIPT=/path/to/radius-protocol-test \
RADIUS_NATIVE_TEST_IMAGE=<published-runtime-image> \
  go test -tags integration ./internal/httpserver -run TestHandlerIntegrationRADIUSPolicy -v

Development

Intern development connects to the production PostgreSQL and Prometheus services available through the current kubectl context. The API does not migrate or seed the database, but actions in the development UI can still write production data.

Copy the non-secret local configuration:

cp .env.example .env

The defaults work at http://127.0.0.1:3000. To open Intern from another machine, change AUTH_PUBLIC_BASE_URL in .env to the URL used by your browser, such as http://<host-ip>:3000. This is the only host-specific setting.

At startup, the helper reads INTERN_API_DATABASE_URL, the deployed Wi-Fi encryption key, the backend snapshot limit, and the deployed metrics ConfigMap from the current Kubernetes namespace. It rewrites the database host to the local PostgreSQL port-forward and mounts the metrics definition from a temporary file, without storing either value in .env. The temporary metrics file is removed when the helper exits. Fresh local-only JWT and forward-auth secrets are generated for every run. Docker administrators can still inspect container environment variables and bind mounts.

Common commands

Run the helper from the repository root:

# Show the available options.
./scripts/dev.sh --help

# Start as the development user configured in .env.
npm run dev

# Stop the Intern Compose development stack.
npm run dev -- stop

The helper discovers the Docker bridge address, starts both Kubernetes port-forwards, and runs the Compose watch stack. Keep it in the foreground and press Ctrl-C once to stop the stack and both port-forwards. After changing .env, stop and restart the helper so Compose reads the new values. Restart it after a metrics ConfigMap update to load the deployed definition again.

Open the app locally or check that it is responding:

curl --head http://127.0.0.1:3000

The web app listens on 0.0.0.0:3000 by default, so it is also available at http://<host-ip>:3000 when the host firewall allows it. The API has no published host port. Every client that can reach the web app acts as the administrator configured in .env and can modify production-backed data. Run it only on a trusted network and stop the server when you finish.

The stop command is safe to run when no stack is active. A normally running helper exits when its Compose stack stops and cleans up both port-forwards:

npm run dev -- stop

Verification and generation

go generate ./internal/api ./internal/db
go test ./...
go test -race ./internal/authspam

The API contract is api/openapi.yaml. Generated API models/client and SQLC output are derived from that contract and sqlc.yaml. Tool dependencies are isolated in tools/go.mod.

Integration tests use isolated ephemeral PostgreSQL containers and are opt-in with -tags=integration.

Releases

Intern is maintained as one monorepo. The first release merged into this repository is v0.2.0. Releases are tag-driven and use signed tags: push a signed v*.*.* tag to run the release workflow. It validates the Go and web workspaces, then publishes internctl release artifacts and updates sbekti/homebrew-tap/Casks. The Docker workflow signs the published GHCR images.

Before creating a release, configure these repository-scoped GitHub values without committing credentials:

  • Variable: HOMEBREW_PUBLISHER_CLIENT_ID
  • Secret: HOMEBREW_PUBLISHER_PRIVATE_KEY

The workflow exchanges these values for a short-lived GitHub App token scoped to the homebrew-tap repository.

Browser interaction tests

After npm ci, run npm run build, then npx --workspace web playwright install --with-deps chromium webkit and npm --workspace web run test:browser. The suite starts the production frontend with a localhost fixture API and controlled mutation responses. It does not connect to a database or external services. Fixtures contain synthetic identities and passwords. Both complete dialogs and their parent controls are tested.

Directories

Path Synopsis
cmd
intern-api command
internctl command
internal
api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
cli
db
remotedesktops
Package remotedesktops manages Bektinet hosts: their saved Mac passwords, encrypted like Wi-Fi passwords, sessions that exchange a password for a single-use stream ticket, and the WebSocket relay that carries a browser's stream without decoding it.
Package remotedesktops manages Bektinet hosts: their saved Mac passwords, encrypted like Wi-Fi passwords, sessions that exchange a password for a single-use stream ticket, and the WebSocket relay that carries a browser's stream without decoding it.
secretbox
Package secretbox encrypts recoverable secrets stored in the database (Wi-Fi and remote desktop passwords) with AES-256-GCM, random nonces, and the owning record's immutable ID as authenticated data, so a ciphertext cannot be moved to another record.
Package secretbox encrypts recoverable secrets stored in the database (Wi-Fi and remote desktop passwords) with AES-256-GCM, random nonces, and the owning record's immutable ID as authenticated data, so a ciphertext cannot be moved to another record.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL