tunnel

package
v0.0.0-...-ad01dd7 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BootstrapProbeMarker     = "rdev-bootstrap-probe-v1"
	TicketCodeSHA256Header   = "X-Rdev-Ticket-Code-SHA256"
	BootstrapProbePowerShell = `$ErrorActionPreference = 'Stop'
# rdev-bootstrap-probe-v1
Write-Output 'rdev-bootstrap-probe-v1'
`
)
View Source
const (
	ProviderCloudflareQuick = "cloudflare-quick"
	ProviderLocalhostRun    = "localhost-run"
	ProviderPinggy          = "pinggy"
	ProviderTunn3l          = "tunn3l"
)
View Source
const AvailabilitySchemaVersion = "rdev.tunnel-availability.v1"
View Source
const MaxProtectedJSONBytes = 1 << 20
View Source
const MaxRegionalEvidenceTTL = 7 * 24 * time.Hour
View Source
const ReadinessSchemaVersion = "rdev.connection-readiness.v2"

Variables

This section is empty.

Functions

func CandidateID

func CandidateID(providerID, rawURL string) string

CandidateID returns the deterministic, redaction-safe correlation ID used for a provider candidate throughout availability diagnostics.

func CanonicalProviderIDs

func CanonicalProviderIDs() []string

func IsCanonicalProviderID

func IsCanonicalProviderID(id string) bool

func OpenVerifiedProtectedExecutableSHA256

func OpenVerifiedProtectedExecutableSHA256(path string, maxBytes int64, expected [sha256.Size]byte) (*os.File, error)

OpenVerifiedProtectedExecutableSHA256 returns a verified private executable handle rewound to offset zero. Unix executables must have exactly 0700 mode.

func OpenVerifiedProtectedRegularFileSHA256

func OpenVerifiedProtectedRegularFileSHA256(path string, maxBytes int64, expected [sha256.Size]byte) (*os.File, error)

OpenVerifiedProtectedRegularFileSHA256 returns the verified confidential file handle rewound to offset zero. The caller owns the handle and must close it.

func ReadProtectedJSONFile

func ReadProtectedJSONFile(path string, destination any) error

ReadProtectedJSONFile opens path before validating and strictly decoding it. Platform-specific permission checks inspect the same opened file handle that is later decoded.

func ReadProtectedRegularFile

func ReadProtectedRegularFile(path string, maxBytes int64) ([]byte, error)

ReadProtectedRegularFile reads a local confidential regular file through the same handle used for path, type, identity, and permission validation.

func TicketCodeSHA256

func TicketCodeSHA256(ticketCode string) string

func ValidateAvailabilitySet

func ValidateAvailabilitySet(set AvailabilitySet) error

func ValidateProtectedDirectory

func ValidateProtectedDirectory(path string) error

func ValidateProtectedParentChain

func ValidateProtectedParentChain(path string) error

ValidateProtectedParentChain verifies that untrusted local users cannot replace path through a writable ancestor after the file itself is checked.

func ValidateProtectedRegularFileIfExists

func ValidateProtectedRegularFileIfExists(path string) error

func ValidatePublicCandidate

func ValidatePublicCandidate(candidate Candidate) error

func VerifyProtectedRegularFileSHA256

func VerifyProtectedRegularFileSHA256(path string, maxBytes int64, expected [sha256.Size]byte) error

VerifyProtectedRegularFileSHA256 streams a confidential protected file through the same handle used for path, type, identity, and permission checks.

Types

type Attempt

type Attempt struct {
	ProviderID  string        `json:"provider_id"`
	CandidateID string        `json:"candidate_id,omitempty"`
	Status      AttemptStatus `json:"status"`
	ErrorClass  string        `json:"error_class,omitempty"`
	Probe       ProbeEvidence `json:"probe"`
}

type AttemptStatus

type AttemptStatus string
const (
	AttemptStarting AttemptStatus = "starting"
	AttemptHealthy  AttemptStatus = "healthy"
	AttemptDegraded AttemptStatus = "degraded"
	AttemptExited   AttemptStatus = "exited"
	AttemptStopped  AttemptStatus = "stopped"
	AttemptSkipped  AttemptStatus = "skipped"
)

type AvailabilitySet

type AvailabilitySet struct {
	SchemaVersion string        `json:"schema_version"`
	Region        RegionProfile `json:"region"`
	Candidates    []Candidate   `json:"candidates"`
	Attempts      []Attempt     `json:"attempts"`
}

type Candidate

type Candidate struct {
	ProviderID     string         `json:"provider_id"`
	URL            string         `json:"url"`
	FailureDomains FailureDomains `json:"failure_domains"`
}

type Eligibility

type Eligibility struct {
	Eligible bool
	Reason   string
	Evidence *RegionalEvidence
}

func EvaluateEligibility

func EvaluateEligibility(meta ProviderMetadata, policy Policy, evidence []RegionalEvidence) Eligibility

type EvidenceStatus

type EvidenceStatus string
const (
	EvidenceUnknown   EvidenceStatus = "unknown"
	EvidenceCandidate EvidenceStatus = "candidate"
	EvidenceVerified  EvidenceStatus = "verified"
	EvidenceDegraded  EvidenceStatus = "degraded"
	EvidenceBlocked   EvidenceStatus = "blocked"
)

type FailureDomains

type FailureDomains struct {
	AuthoritativeDNS      string `json:"authoritative_dns,omitempty"`
	EdgeNetwork           string `json:"edge_network,omitempty"`
	OriginNetwork         string `json:"origin_network,omitempty"`
	ControlPlane          string `json:"control_plane,omitempty"`
	CertificateDependency string `json:"certificate_dependency,omitempty"`
}

type Handle

type Handle interface {
	Candidate() Candidate
	Wait() <-chan error
	Stop(context.Context) error
}

type Manager

type Manager struct {
	Region       RegionProfile
	MaxActive    int
	StartTimeout time.Duration
	ProbeTimeout time.Duration
	Probe        ProbeFunc
}

func (Manager) Start

func (m Manager) Start(ctx context.Context, selections []Selection, request StartRequest) (*Runtime, error)

type NetworkSample

type NetworkSample struct {
	Carrier      string `json:"carrier"`
	Region       string `json:"region"`
	ResolverType string `json:"resolver_type,omitempty"`
	Success      bool   `json:"success"`
	LatencyMS    int64  `json:"latency_ms,omitempty"`
}

type Policy

type Policy struct {
	Region                RegionProfile
	Now                   time.Time
	AllowedProviderIDs    []string
	RestrictProviders     bool
	AllowNonDefault       bool
	AllowUnverifiedGlobal bool
}

type ProbeEvidence

type ProbeEvidence struct {
	DNSOK                  bool          `json:"dns_ok"`
	TCPConnectOK           bool          `json:"tcp_connect_ok"`
	TLSOK                  bool          `json:"tls_ok"`
	HealthOK               bool          `json:"health_ok"`
	BootstrapOK            bool          `json:"bootstrap_ok"`
	StaticBootstrapOK      bool          `json:"static_bootstrap_ok"`
	TicketBoundBootstrapOK bool          `json:"ticket_bound_bootstrap_ok"`
	SmallAssetOK           bool          `json:"small_asset_ok"`
	Latency                time.Duration `json:"latency"`
	InstanceMarker         string        `json:"instance_marker,omitempty"`
}

func ProbeBootstrapAsset

func ProbeBootstrapAsset(ctx context.Context, client *http.Client, candidate Candidate, ticketCode, expectedInstance string) (ProbeEvidence, error)

func ProbeBootstrapTemplate

func ProbeBootstrapTemplate(ctx context.Context, client *http.Client, candidate Candidate, expectedInstance string) (ProbeEvidence, error)

func ProbeGatewayHealth

func ProbeGatewayHealth(ctx context.Context, client *http.Client, candidate Candidate, expectedInstance string) (ProbeEvidence, error)

type ProbeFunc

type ProbeFunc func(context.Context, Candidate) (ProbeEvidence, error)

type Provider

type Provider interface {
	ID() string
	Metadata() ProviderMetadata
	// Start must return promptly after ctx cancellation. The context remains
	// valid for the returned handle's lifetime; Wait signals only after provider
	// resources are reaped. Manager cancels ctx on startup timeout, parent
	// cancellation, handle stop, or handle exit.
	Start(context.Context, StartRequest) (Handle, error)
}

type ProviderMetadata

type ProviderMetadata struct {
	ID                    string         `json:"id"`
	DisplayName           string         `json:"display_name"`
	Protocols             []string       `json:"protocols"`
	Anonymous             bool           `json:"anonymous"`
	CredentialRequirement string         `json:"credential_requirement,omitempty"`
	Executable            string         `json:"executable"`
	DocumentationURL      string         `json:"documentation_url"`
	TermsURL              string         `json:"terms_url,omitempty"`
	DefaultAutomatic      bool           `json:"default_automatic"`
	AutomaticPriority     int            `json:"automatic_priority,omitempty"`
	RequiresSSHPin        bool           `json:"requires_ssh_pin"`
	FailureDomains        FailureDomains `json:"failure_domains"`
}

type RegionProfile

type RegionProfile string
const (
	RegionGlobal     RegionProfile = "global"
	RegionCNMainland RegionProfile = "cn-mainland"
)

type RegionalEvidence

type RegionalEvidence struct {
	ProviderID string          `json:"provider_id"`
	Region     RegionProfile   `json:"region"`
	Status     EvidenceStatus  `json:"status"`
	Issuer     string          `json:"issuer"`
	ObservedAt time.Time       `json:"observed_at"`
	ExpiresAt  time.Time       `json:"expires_at"`
	Samples    []NetworkSample `json:"samples"`
}

func (RegionalEvidence) Validate

func (e RegionalEvidence) Validate() error

type Registry

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

func NewRegistry

func NewRegistry(providers ...Provider) (Registry, error)

func (Registry) Evaluate

func (r Registry) Evaluate(policy Policy, evidence []RegionalEvidence) []Selection

func (Registry) Providers

func (r Registry) Providers() []ProviderMetadata

func (Registry) Select

func (r Registry) Select(policy Policy, evidence []RegionalEvidence) []Selection

type Runtime

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

func (*Runtime) Changes

func (r *Runtime) Changes() <-chan struct{}

func (*Runtime) Snapshot

func (r *Runtime) Snapshot() AvailabilitySet

func (*Runtime) Stop

func (r *Runtime) Stop(ctx context.Context) error

type Selection

type Selection struct {
	Provider    Provider
	Metadata    ProviderMetadata
	Eligibility Eligibility
}

type StartRequest

type StartRequest struct {
	LocalURL       string
	LocalPort      string
	KnownHostsFile string
	ProviderRoot   string
}