accesstoken

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package accesstoken mints the per-sandbox tokens that secure the data plane, and names the headers and envd control paths that go with them.

Two separate secrets protect two separate surfaces of a sandbox:

  • the envd token guards envd itself (port 49983): the file API and the process/filesystem RPCs. envd enforces it natively once it is set — every RPC must carry X-Access-Token, and the signing-based /files paths need the same token to produce a valid signature.
  • the traffic token guards the user's own service ports when the sandbox was created without public access. The gateway enforces it: a request to a non-envd port must carry e2b-traffic-access-token.

Both are a deterministic HMAC-SHA256 over the sandbox's raw UUID, so the operator (which delivers the envd token to envd via /init), the E2B API (which returns both tokens to the SDK), and the gateway (which validates the traffic token) all derive the same value from the shared secret with nothing stored and nothing to synchronise. The formulas match upstream e2b-dev/infra (packages/api/internal/sandbox/sandbox_envd_secret.go) so the stock E2B SDK, which simply echoes whatever tokens the create/connect response gave it, works unmodified.

The canonical input is always the RAW sandbox UUID, never a cluster-prefixed ID: the pod annotation and the gateway (after it strips its local prefix) both use the raw UUID, so any minter that hashes a prefixed ID would silently disagree with the other two for cross-cluster sandboxes.

Index

Constants

View Source
const (
	// EnvdHeader is the header envd checks for its access token.
	EnvdHeader = "X-Access-Token"
	// TrafficHeader is the header the gateway checks for the traffic token on
	// non-envd ports.
	TrafficHeader = "e2b-traffic-access-token"
	// EnvdPort is the in-sandbox envd listener. Traffic to it is authenticated
	// by envd itself (EnvdHeader); every other port is a user service guarded by
	// the traffic token.
	EnvdPort int32 = 49983
)

Variables

This section is empty.

Functions

func IsInternalEnvdPath

func IsInternalEnvdPath(requestPath string) bool

IsInternalEnvdPath reports whether requestPath addresses an envd control route. requestPath MUST be the decoded path (http.Request.URL.Path), never RawPath/EscapedPath/RequestURI: passing a still-escaped path would let "/%69nit" slip past this check and reach /init. Cleaning the decoded path before the lookup makes the answer a superset of what envd itself would route, so "/init/", "//init" and "/files/../init" are refused here too.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator mints access tokens from a shared secret. A nil *Generator mints nothing (Enabled reports false), so a deployment without the secret wired in degrades to the previous unauthenticated behaviour rather than panicking.

func New

func New(secret string) *Generator

New returns a Generator over secret, or nil when secret is empty. Callers treat a nil Generator as "secured access disabled" via Enabled.

func (*Generator) Enabled

func (g *Generator) Enabled() bool

Enabled reports whether g can mint tokens. Safe on a nil receiver.

func (*Generator) EnvdToken

func (g *Generator) EnvdToken(rawSandboxID string) string

EnvdToken returns the hex HMAC-SHA256 envd access token for the raw sandbox UUID. Empty when the generator is disabled.

func (*Generator) TrafficToken

func (g *Generator) TrafficToken(rawSandboxID string) string

TrafficToken returns the hex HMAC-SHA256 traffic access token for the raw sandbox UUID. Empty when the generator is disabled.

func (*Generator) ValidateTraffic

func (g *Generator) ValidateTraffic(rawSandboxID, provided string) bool

ValidateTraffic reports whether provided matches the traffic token for the raw sandbox UUID, using a constant-time comparison. False when the generator is disabled or provided is empty.

Jump to

Keyboard shortcuts

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