netaccess

package
v0.1.0-alpha.46 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: GPL-3.0 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 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 (
	// 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 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 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"`
}

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 {
	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"`
}

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 Policy

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

Policy is an immutable, validated listener and origin policy.

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.

Jump to

Keyboard shortcuts

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