meshforward

package
v0.0.0-...-0b698e0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0, MIT Imports: 22 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 meshforward contains the separately reviewed authority and bounded byte-stream machinery for the ARM mesh TCP service route. Nothing in this package treats SSH, sync or workspace membership as a TCP grant.

Index

Constants

View Source
const (
	MaxNodes       = 8
	MaxLifetime    = 15 * time.Minute
	MaxConnections = 8
	MaxBytes       = 8 << 30
	MaxRate        = 1 << 30
	MaxGrantBytes  = 8 << 30
)

Variables

View Source
var ErrClosed = errors.New("TCP forward proxy stopped")

Functions

func AuthenticateLocal

func AuthenticateLocal(c net.Conn, digest string) (io.Reader, []byte, bool, error)

AuthenticateLocal consumes only the first bounded local authentication record. HTTP is handled as one request per connection so a later header cannot leak the token through a persistent connection.

func NewCreditNonce

func NewCreditNonce() (string, error)

func ReadAccepted

func ReadAccepted(r io.Reader, q Request) error

func ServeLocal

func ServeLocal(ctx context.Context, local net.Conn, digest string, open func(context.Context) (net.Conn, error)) error

ServeLocal connects one authenticated local user to one already reviewed destination stream. open must finish exact remote control admission before returning. No redirect, DNS lookup or alternate target is performed here.

func ServeLocalCompatibleTLS

func ServeLocalCompatibleTLS(ctx context.Context, local net.Conn, serverTLS *tls.Config, digest string, open func(context.Context) (net.Conn, error)) error

ServeLocalCompatibleTLS keeps already-reviewed plaintext local modes usable while a fenced rollout migrates them. A TLS ClientHello is never retried as plaintext, so the updated CLI cannot downgrade after authentication fails. Plaintext callers still carry their existing bearer risk on port handoff; they must not be presented as source-authenticated clients.

func ServeLocalTLS

func ServeLocalTLS(ctx context.Context, local net.Conn, serverTLS *tls.Config, digest string, open func(context.Context) (net.Conn, error)) error

ServeLocalTLS presents the existing local mesh identity before reading a bearer or application byte. The client pins that identity; the destination still performs its normal grant admission.

func TokenDigest

func TokenDigest(token string) (string, error)

TokenDigest accepts only the digest of a 256-bit random hex token. The backend keeps this digest, never the bearer secret or a logged URL copy.

func WriteAccepted

func WriteAccepted(w io.Writer, q Request) error

func WriteRequest

func WriteRequest(w io.Writer, q Request) error

Types

type AdmittedRoute

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

AdmittedRoute owns an original inner TLS connection only after the exact destination ACK has been read on a pinned forwarding channel. Its fields are private so an arbitrary opener cannot return a raw connection as admission.

func ReadAdmittedRoute

func ReadAdmittedRoute(conn *tls.Conn, q Request) (*AdmittedRoute, error)

ReadAdmittedRoute is called only after WriteRequest on the same original inner TLS connection. The caller owns conn on every failure.

func (*AdmittedRoute) Conn

func (a *AdmittedRoute) Conn() *tls.Conn

func (*AdmittedRoute) Request

func (a *AdmittedRoute) Request() Request

type Endpoint

type Endpoint struct {
	Name    string `json:"name"`
	Network string `json:"network"`
	Address string `json:"address"`
}

Endpoint names one destination-local service. The address is installed by that destination's operator; no route request can supply or replace it. Literal loopback IPs avoid DNS rebinding and accidental LAN exposure.

func (Endpoint) Validate

func (e Endpoint) Validate() error

type Grant

type Grant struct {
	Workspace          string          `json:"workspace"`
	Generation         string          `json:"generation"`
	Source             string          `json:"source"`
	Target             string          `json:"target"`
	SourceGeneration   int64           `json:"source_generation"`
	TargetGeneration   int64           `json:"target_generation"`
	DirectoryPin       string          `json:"directory_pin"`
	DirectorySPKI      string          `json:"directory_spki"`
	SourcePin          string          `json:"source_pin"`
	SourceSPKI         string          `json:"source_spki"`
	TargetPin          string          `json:"target_pin"`
	TargetSPKI         string          `json:"target_spki"`
	Account            string          `json:"account"`
	Endpoint           Endpoint        `json:"endpoint"`
	Revision           int64           `json:"revision"`
	MaxConnections     int             `json:"max_connections"`
	BytesPerConnection int64           `json:"bytes_per_connection"`
	BytesPerSecond     int64           `json:"bytes_per_second"`
	TotalBytes         int64           `json:"total_bytes,omitempty"`
	CreditNonce        string          `json:"credit_nonce,omitempty"`
	Transit            model.Resources `json:"transit_resources"`
	MaxTTL             time.Duration   `json:"max_ttl_ns"`
	Expires            time.Time       `json:"expires_at"`
}

Grant is destination-local TCP authority for one original source and one exact installed service. A relay's own grant cannot be substituted.

func (Grant) Authorize

func (g Grant) Authorize(now time.Time, originalSource, originalSPKI, localTarget, localSPKI, account string, q Request) error

func (Grant) Digest

func (g Grant) Digest() (string, error)

Digest binds the installed endpoint and limits to the local review record.

func (Grant) Validate

func (g Grant) Validate() error

func (Grant) ValidateCredit

func (g Grant) ValidateCredit() error

ValidateCredit distinguishes readable legacy policy records from grants that can open a new stream. A lifetime limit is never inferred from other limits.

type Identity

type Identity struct {
	SourcePin, SourceSPKI, TargetPin, TargetSPKI, Account string
}

Identity must come from the checked, pinned inner TLS peer certificate and current destination service binding, never from a route header or relay.

type Proxy

type Proxy struct {
	Dial        func(context.Context, string, string) (net.Conn, error) // nil uses net.Dialer
	CheckCredit func(context.Context, Grant) error
	Credit      func(context.Context, Grant, int) (int, error) // required durable destination-local prepayment
	// contains filtered or unexported fields
}

Proxy owns final destination TCP streams. Grant must read the current local grant on every call; a missing grant denies by default. The caller owns the authenticated carrier and must join this Open before settling its lease.

func (*Proxy) Active

func (p *Proxy) Active() int

func (*Proxy) Open

func (p *Proxy) Open(ctx context.Context, q Request, who Identity, stream net.Conn, grantNow func(context.Context) (Grant, error), ready func() error) error

Open returns only after both copy workers, the revocation watcher, and the final socket have joined. The caller's route and Manager holds remain live until it returns. Any transfer failure is an unknown application outcome.

func (*Proxy) Stop

func (p *Proxy) Stop()

type Request

type Request struct {
	Version          int           `json:"schema_version"`
	Workspace        string        `json:"workspace"`
	Generation       string        `json:"generation"`
	Source           string        `json:"source"`
	Target           string        `json:"target"`
	SourcePin        string        `json:"source_pin"`
	TargetPin        string        `json:"target_pin"`
	Service          string        `json:"service"`
	GrantRevision    int64         `json:"grant_revision"`
	ConnectionID     string        `json:"connection_id"`
	TTL              time.Duration `json:"ttl_ns"`
	RouteBindingHash string        `json:"route_binding_sha256"`
}

Request is authenticated by the pinned inner TLS channel. It has no dial address and no SSH or sync selector.

func ReadRequest

func ReadRequest(r io.Reader) (Request, error)

func (Request) Validate

func (q Request) Validate() error

Jump to

Keyboard shortcuts

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