netaccess

package
v0.1.0-alpha.86 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: GPL-3.0 Imports: 32 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 netaccess validates the installation's explicit network boundary. It has no authority to start motion, launch processes, or change a firewall.

Index

Constants

View Source
const (
	// AutomaticPublic obtains and renews a public certificate using TLS-ALPN-01.
	AutomaticPublic = "automatic_public"
	// LocalCA uses this installation's private CA; clients explicitly enroll trust.
	LocalCA = "local_ca"
)
View Source
const (
	// Local keeps remote exposure disabled.
	Local = "local"
	// DirectHTTPS terminates client TLS in MagicHandy.
	DirectHTTPS = "direct_https"
	// TrustedProxy accepts HTTPS metadata only from explicitly configured peers.
	TrustedProxy = "trusted_proxy"
)

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

ClientIP is for throttling and diagnostics, never local privilege decisions.

func HasForwardingHeaders

func HasForwardingHeaders(r *http.Request) bool

HasForwardingHeaders also blocks accidental forwarding to local-only routes.

func IsForwarded

func IsForwarded(r *http.Request) bool

IsForwarded preserves the trust boundary independently of a claimed client IP.

func ParseOrigin

func ParseOrigin(value string) (*url.URL, error)

ParseOrigin accepts one canonical HTTPS origin, with no credentials or path.

func RemoteEndpoint

func RemoteEndpoint(address, baseURL string, port int, publicURL string) (string, string, error)

RemoteEndpoint derives a second origin without widening the bind interface, TLS policy or trusted proxy peers. A remote port of -1 disables the listener; zero selects the port after the main listener. Public origin overrides are useful for a trusted proxy. Direct HTTPS reuses the main host's certificate.

func Save

func Save(ctx context.Context, db *appstore.DB, config Config) error

Save persists a previously validated configuration atomically in the shared DB.

func SaveTx

func SaveTx(ctx context.Context, tx *sql.Tx, config Config) error

SaveTx validates and persists configuration inside the caller's transaction, allowing the HTTP edge to bind the write to current account authority.

Types

type Automation

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

Automation owns certificate work, never account authority or app listeners. Initial public issuance opens a temporary challenge-only socket. Saving the network configuration is a separate password-confirmed transaction, after a valid certificate exists. Renewal uses the already-authorized TLS listener.

func NewAutomation

func NewAutomation(dataDir string) *Automation

NewAutomation does not create files, contact services, or open sockets.

func (*Automation) Close

func (a *Automation) Close()

Close cancels network operations and joins every job before storage teardown.

func (*Automation) Discover

func (a *Automation) Discover(ctx context.Context) (InternetDiscovery, error)

Discover coalesces repeated UI clicks and bounds provider traffic per process.

func (*Automation) LoadManaged

func (a *Automation) LoadManaged(policy *Policy) (CertificateProvider, error)

LoadManaged fails closed if setup has not yet produced a valid certificate.

func (*Automation) LocalTrustCertificate

func (a *Automation) LocalTrustCertificate() ([]byte, error)

LocalTrustCertificate downloads only the public root, never its signing key.

func (*Automation) Prepare

func (a *Automation) Prepare(policy *Policy) (PreparationStatus, error)

Prepare starts at most one job and limits repeated public validation attempts.

func (*Automation) Snapshot

func (a *Automation) Snapshot() PreparationStatus

Snapshot never includes keys, certificate paths, or provider error bodies.

func (*Automation) StartRenewal

func (a *Automation) StartRenewal()

StartRenewal is called once the app owns the selected TLS listener. Issuance is scheduled independently of browser requests, preventing handshake abuse.

func (*Automation) ValidatePrepared

func (a *Automation) ValidatePrepared(policy *Policy) error

ValidatePrepared only reads the saved chain; it cannot cause issuance.

type CertificateProvider

type CertificateProvider interface {
	TLSConfig() *tls.Config
	Status() CertificateStatus
}

CertificateProvider is the common listener contract for file and managed TLS.

type CertificateStatus

type CertificateStatus struct {
	NotBefore   time.Time `json:"not_before"`
	NotAfter    time.Time `json:"not_after"`
	Fingerprint string    `json:"sha256"`
	DNSNames    []string  `json:"dns_names"`
	RenewalDue  bool      `json:"renewal_due"`
	ReloadError bool      `json:"reload_error"`
	Managed     bool      `json:"managed,omitempty"`
}

CertificateStatus contains public certificate metadata, never file paths/key data.

type Certificates

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

Certificates retains the last valid chain during a failed file replacement. An expired chain is never offered. Replacements are checked at most every 30s on a handshake; the operator's CA/ACME client owns issuance and file writes.

func LoadCertificates

func LoadCertificates(policy *Policy) (*Certificates, error)

LoadCertificates validates the configured identity before a listener starts.

func (*Certificates) Status

func (c *Certificates) Status() CertificateStatus

Status snapshots certificate metadata without touching key files.

func (*Certificates) TLSConfig

func (c *Certificates) TLSConfig() *tls.Config

TLSConfig returns a TLS 1.2+ configuration with bounded renewal checks.

type Config

type Config struct {
	RemotePort      int      `json:"remote_port,omitempty"`
	RemotePublicURL string   `json:"remote_public_url,omitempty"`
	Mode            string   `json:"mode"`
	ListenAddress   string   `json:"listen_address"`
	PublicURL       string   `json:"public_url"`
	TrustedProxies  []string `json:"trusted_proxies"`
	TLSCertificate  string   `json:"tls_certificate"`
	TLSPrivateKey   string   `json:"tls_private_key"`
	Scope           string   `json:"scope,omitempty"`
	CertificateMode string   `json:"certificate_mode,omitempty"`
	AcceptedTerms   string   `json:"accepted_terms,omitempty"`
}

Config is persisted separately from live settings: changes apply on restart. Certificate paths belong to the host. Private-key contents never enter JSON.

func Load

func Load(ctx context.Context, db *appstore.DB) (*Config, error)

Load returns nil for an installation that still uses legacy startup flags. A malformed saved policy fails closed instead of falling back to local HTTP.

type InternetDiscovery

type InternetDiscovery struct {
	PublicIP     string `json:"public_ip"`
	TermsURL     string `json:"terms_url"`
	IPError      bool   `json:"ip_error"`
	CAError      bool   `json:"ca_error"`
	ExternalPort int    `json:"external_port"`
}

InternetDiscovery describes observations, never a claim of inbound reachability.

func DiscoverInternet

func DiscoverInternet(ctx context.Context) InternetDiscovery

DiscoverInternet contacts only fixed services, when explicitly requested from setup. No URL from a browser is fetched. Private worker addresses stay private.

type Policy

type Policy struct {
	Config Config
	Origin *url.URL
	Peers  []netip.Prefix
}

Policy is an immutable, validated listener and origin policy.

func RemotePolicy

func RemotePolicy(parent *Policy, address, publicURL string) (*Policy, error)

RemotePolicy reuses a validated policy and its certificate provider. ACME issuance remains on the main public 443 listener; serving the resulting certificate on the remote port does not request a second certificate.

func Validate

func Validate(config Config) (*Policy, error)

Validate rejects ambiguous origins, wildcard trust and insecure remote modes. It does not bind a socket, resolve DNS or read certificate/key files.

func (*Policy) Accept

func (p *Policy) Accept(r *http.Request) (*http.Request, error)

Accept checks the actual peer before interpreting any proxy metadata. It never rewrites RemoteAddr or fakes a TLS connection state.

type PreparationStatus

type PreparationStatus struct {
	State       string             `json:"state"`
	Config      *Config            `json:"config,omitempty"`
	Message     string             `json:"message,omitempty"`
	Certificate *CertificateStatus `json:"certificate,omitempty"`
}

PreparationStatus is a bounded, public snapshot of one explicit setup action.

Jump to

Keyboard shortcuts

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