Documentation
¶
Overview ¶
Package share is share links: a signed, expiring, READ-ONLY grant to one deployment.
THE PROBLEM. "Can you look at the logs of PR 123?" used to mean creating an account for someone who will sign in once. A share link is the account-free answer: a URL that opens that deployment's details and log view, and nothing else, until it expires.
── WHAT IT IS ───────────────────────────────────────────────────────────────────────────────────
An HS256 JWT, signed with PSTACK_TOKEN. No library: a JWT is base64url(header).base64url(claims) and an HMAC over those bytes, and this package carries no runtime dependencies. The claims are exactly `{ sub: 'share', dep, views, iat, exp }` — which deployment, which views, for how long.
Why PSTACK_TOKEN as the key: it is the one secret the control plane already holds that every host has, it is 192 bits when generated by `init`, and `pstack upgrade` deliberately preserves it, so links survive upgrades. Rotating it (`PSTACK_TOKEN=… pstack init`) invalidates every link — that IS the revocation mechanism, and the only one: nothing about a link is stored (invariant 10 — a table of issued links would be a row describing a credential), so there is no per-link revoke. Keep TTLs short; the default is 7 days and the ceiling 30.
── WHERE IT TRAVELS ─────────────────────────────────────────────────────────────────────────────
`?token=<jwt>` in the query string, by design and not as a convenience: the log view FOLLOWS logs over an EventSource, and a browser cannot put a header on one. The same constraint is why sessions are cookies (api `principal`). The raw PSTACK_TOKEN is never accepted from a query string — a JWT in an access log is a bounded, expiring grant; the bearer would be root.
── WHAT IT MUST NEVER DO ────────────────────────────────────────────────────────────────────────
Act. `principal()` turns a valid token into `{ kind: 'share' }`, and the gate in api allows that principal exactly the GET routes its views name, on its deployment only. Request variables are ignored for it (a `?PR=8` could otherwise resolve the spec to ANOTHER stack's logs), and `mayOpenTerminal` says no by kind before it looks at anything else.
The byte-sensitive part: the HMAC covers `base64url(JSON.stringify(header)).base64url(JSON.stringify(claims))` with the claims keys in the order sub,dep,views,iat,exp — the Claims struct's field order, through jsonx. Verification recomputes the HMAC over the RECEIVED segments, so a token the TypeScript issued verifies here and vice versa.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Views = []View{Details, Logs}
Views lists every view, in the order the error messages and the API enumerate them.
Functions ¶
func LooksLikeToken ¶
LooksLikeToken: does this string have the shape of a JWT this module issued? Cheap, run before any crypto.
Types ¶
type Claims ¶
type Claims struct {
Sub string `json:"sub"`
// Dep is the deployment id (registry's ID alphabet — never a path or a stack name).
Dep string `json:"dep"`
Views []View `json:"views"`
// Iat and Exp are seconds since the epoch, like every JWT.
Iat int64 `json:"iat"`
Exp int64 `json:"exp"`
}
Claims is the JWT payload. Field order is the wire order — the signature covers these bytes.
func Sign ¶
func Sign(key, deployment string, views []View, ttlMs, now int64) (token string, claims *Claims, err error)
Sign mints a token. ttlMs is clamped by the caller (api); this only refuses nonsense. now is epoch milliseconds — the caller passes time.Now().UnixMilli() (the TypeScript defaulted it).