egress

package
v0.9.13 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 18 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 egress runs backd's egress role: the only way a function process reaches the network. It is an HTTP forward/CONNECT proxy that resolves every target itself and refuses loopback, private, link-local (metadata), CGNAT, multicast and unspecified addresses, with backd's callback listener as its only exception. Each function process authenticates with a token scoped to its own invocation, naming the hosts it may reach, so the proxy enforces that allowlist too, in addition to the per-process --allow-net the executor already sets.

Index

Constants

View Source
const TokenPrefix = "bdg_"

TokenPrefix starts every egress credential.

Variables

View Source
var ErrInvalidToken = errors.New("invalid or expired egress token")

ErrInvalidToken means an egress token is malformed, forged or expired.

Functions

func Sign

func Sign(key []byte, c Claims) string

Sign returns an egress token for c, signed with key.

Types

type Claims

type Claims struct {
	Hosts   []string  `json:"h"`
	Expires time.Time `json:"e"`
}

Claims are what an egress token carries: the hosts (as function.yaml's network list, plus backd's callback address) the process may reach through the proxy, and when the token expires.

func Verify

func Verify(key []byte, token string, now time.Time) (Claims, error)

Verify checks an egress token's signature and expiry.

func (Claims) Allows

func (c Claims) Allows(hostport string) bool

Allows reports whether c's hosts include hostport: an exact host:port entry matches only that port, a bare host entry (as Deno's --allow-net treats it) matches hostport on any port.

type Proxy

type Proxy struct {
	Key          []byte
	AllowPrivate []string // host:port exceptions to the private-address block
	Log          *slog.Logger
	Now          func() time.Time // for tests; defaults to time.Now
	Metrics      *metrics.Metrics // counts decisions; nil turns it off
}

Proxy is backd's egress role. Every function process is given its own token (Sign), naming the hosts it may reach; the proxy checks that, and separately resolves each target itself and refuses the addresses blocked reports, except the hosts listed in AllowPrivate (backd's callback listener).

func (*Proxy) Handler

func (p *Proxy) Handler() http.Handler

Handler serves the proxy: HTTP forward requests and CONNECT tunnels.

Jump to

Keyboard shortcuts

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