share

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT, MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
var Views = []View{Details, Logs}

Views lists every view, in the order the error messages and the API enumerate them.

Functions

func IsView

func IsView(v string) bool

IsView reports whether v names a known view.

func LooksLikeToken

func LooksLikeToken(v string) bool

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).

func Verify

func Verify(key, token string, now int64) *Claims

Verify returns the claims, or nil for ANY defect — wrong signature, expired, malformed, not ours. One nil rather than a reason: a caller answers 401 either way, and a distinguishable error is an oracle nobody needs. now is epoch milliseconds.

type View

type View string

View is one of the two read-only surfaces a link can open. Defined here (the TypeScript declared it in auth.ts and re-exported it from share.ts) so that auth can import share without a cycle.

const (
	Details View = "details"
	Logs    View = "logs"
)

The views.

Jump to

Keyboard shortcuts

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