grantwire

package
v0.2.35 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package grantwire is what a command and the chassis agree on when the command exercises a run grant: the variables the command is handed, and the few lines of protocol the launcher (`txco sandbox`) speaks to the chassis over a Unix socket.

It is a leaf: the launcher is a small program that must start fast and import nothing of the server.

The protocol is one request and one response per connection, each a line of JSON. A request opens ONE sandbox, by name; the program never asks for a secret by name:

→ {"v":2,"token":"rg1.…","sandbox":"github"}
← {"ok":true,"env":{"GH_TOKEN":"<base64>"}}
← {"ok":false,"error":"refused"}

A refusal says nothing of why. The reason is in the trace of the tenant's `_grant` run, for whoever may read that; the program that asked may not.

Index

Constants

View Source
const (
	EnvRun    = "TXCO_RUN"        // the run's name
	EnvToken  = "TXCO_RUN_GRANT"  // the token; the launcher presents it
	EnvSocket = "TXCO_GRANT_SOCK" // where the launcher reaches the chassis
	EnvBin    = "TXCO_BIN"        // the txco binary, for `"$TXCO_BIN" sandbox …`
)

The variables a command is handed with its run grant.

View Source
const (
	// Version is the protocol's. A chassis refuses one it does not speak.
	Version = 2
	// MaxRequest bounds one request line; a token is about 350 bytes.
	MaxRequest = 8 << 10
	// MaxResponse bounds one response line: a sandbox's values, base64, and
	// their frame.
	MaxResponse = 16 << 20
	// MaxSocketPath is the longest path the chassis will listen on. A Unix
	// socket's address is a fixed field of the kernel's: 104 bytes on macOS,
	// 108 on Linux, the terminator included.
	MaxSocketPath = 100
)
View Source
const (
	ErrorRefused     = "refused"     // the request was decided, and the answer is no
	ErrorUnavailable = "unavailable" // the chassis could not decide
	ErrorBadRequest  = "bad_request" // not a request this chassis understands
)

The errors a response may carry.

Variables

View Source
var (
	// ErrRefused: the chassis decided, and the answer is no.
	ErrRefused = errors.New("refused")
	// ErrUnavailable: the chassis could not be asked, or could not decide.
	ErrUnavailable = errors.New("unavailable")
)

Env is every one of them. The launcher removes them all from the environment of the program it starts.

Functions

func Open

func Open(ctx context.Context, socket string, req Request) (map[string][]byte, error)

Open asks the chassis listening on socket to open one sandbox and returns what it hands over, variable → value. The error is ErrRefused, or wraps ErrUnavailable with what went wrong between here and the chassis. The caller owns the values and should overwrite them once they are handed on.

func ReadLine

func ReadLine(r *bufio.Reader, max int) ([]byte, error)

ReadLine reads one line of at most max bytes, without its newline. A line that is longer is an error, not a truncation: half a request must never be read as a whole one.

Types

type Request

type Request struct {
	V       int    `json:"v"`
	Token   string `json:"token"`
	Sandbox string `json:"sandbox"`
}

Request is one ask: open a sandbox.

type Response

type Response struct {
	OK    bool              `json:"ok"`
	Env   map[string]string `json:"env,omitempty"` // variable → base64 (standard, padded)
	Error string            `json:"error,omitempty"`
}

Response is the answer.

Jump to

Keyboard shortcuts

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