subhost

package
v0.2.2-dev.6 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 37 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 subhost is the panel's side of the subscription host (design/adr/0018-panel-behind-nat.md): one node serves a subdomain on its 443 and hands its TLS to the panel, which dials the node over the bridge. People's subscriptions and the agents' link then reach a panel that has no public address of its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Store           *store.Store
	Fleet           Fleet
	Addr            *pubaddr.Holder
	StepUp          func(context.Context) error // auth.Service.RequireStepUp; nil denies every change
	PrepareRecovery RecoveryPreparer            // saved pinned SSH access; attached before serving owner RPCs
	// LinkPrefix is the secret path prefix of the agent link ("/<secret>/").
	LinkPrefix string
	// ACMEDir is the autocert cache directory (the account key for the CAA record); "" = no account yet.
	ACMEDir string
	// Test seams.
	HostPort    uint16                                               // the hosts' port; 0 = 443
	ACMEClient  *acme.Client                                         // nil = Let's Encrypt
	Certificate func(*tls.ClientHelloInfo) (*tls.Certificate, error) // the subdomain's certificate instead of ACME's
	Resolver    Resolver
	CAA         func(ctx context.Context, name string) (issue []string, found bool, err error)
	Now         func() time.Time
	Log         *slog.Logger
}

type Fleet

type Fleet interface {
	HasSession(nodeID string) bool
	SessionOnReturn(nodeID, authority string) bool
	HasSubHostMoveReceipt(nodeID, receipt string) bool
	InboundSpecs(ctx context.Context, nodeID string) ([]plugin.InboundSpec, error)
	SetSubHostSettings(roles map[string]*agentv1.SubHostRole, access *agentv1.SubHostAccess)
	SetPanelLink(linkURL string)
	SetLinkEnrollment(on bool)
	SetReturnEnrollment(on bool)
	StateChanged()
	PanelIdentity(now time.Time) ([]byte, *ecdsa.PrivateKey, error)
	SubHostTarget(ctx context.Context, nodeID, siteName, bootstrapPin string) (host, sni, pin string, public, ok bool)
	SubHostStatus(nodeID string) *agentv1.SubHostStatus
}

Fleet is what the service needs of the fleet (*fleet.Fleet).

type RecoveryPreparer

type RecoveryPreparer func(ctx context.Context, nodeID, changeID string, role *agentv1.SubHostRole, access *agentv1.SubHostAccess, action string) (apply func(context.Context) error, close func(), err error)

RecoveryPreparer checks the saved SSH login without writes. The returned apply operation uses that connection to recheck and update the enrolled agent; close releases it whether apply ran or not.

type Resolver

type Resolver interface {
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}

Resolver looks up the addresses of a host (net.DefaultResolver).

type Service

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

Service is the subscription host: the owner's RPCs and the routing the panel follows.

func New

func New(cfg Config) *Service

New builds the service; Load applies the stored state.

func (*Service) ActivateInstalled

func (s *Service) ActivateInstalled(ctx context.Context, actor, nodeID, domain, siteName, path, pin string) error

ActivateInstalled turns the role on for the node the install enrolled: off -> on, not ready. Running it again for the same install (the panel died in it, or its undo was refused) finds the role on for that node, domain and path, and is no change.

func (*Service) CheckInstallDNS

func (s *Service) CheckInstallDNS(ctx context.Context, sshHost, domain, siteName string, ipv6 []netip.Addr) error

CheckInstallDNS checks, once the install read the server's global IPv6 addresses, that both names point at the server: the A records at sshHost, the AAAA records (when there are any) at one of ipv6.

func (*Service) Close

func (s *Service) Close()

Close stops dialling the hosts and closes the listener.

func (*Service) DeactivateInstalled

func (s *Service) DeactivateInstalled(ctx context.Context, actor, nodeID string) error

DeactivateInstalled turns the role off again after an install that did not complete. A host that is ready is in use: it is left alone (sub_host_in_use).

func (*Service) Handler

func (s *Service) Handler(opts ...connect.HandlerOption) (string, http.Handler)

Handler is the SubscriptionHostService mount.

func (*Service) Load

func (s *Service) Load(ctx context.Context) error

Load reads the stored state and applies it (the public address, the fleet's settings). The app calls it at start, so the first request already sees the right address. While the host is off the panel keeps the address it started with.

func (*Service) PrepareInstall

func (s *Service) PrepareInstall(ctx context.Context, sshHost, domain, siteName string, skipDNS bool) (string, error)

PrepareInstall checks that a first host may be installed for domain (and siteName) on the server sshHost: the role is off, the names are host names, every node can follow the panel to a new link address, and both names point at the server unless skipDNS. It returns the bridge path the install gives the node; nothing is stored.

func (*Service) PublicListener

func (s *Service) PublicListener() net.Listener

PublicListener yields the connections of the subdomain the hosts carry: the public server serves them with PublicTLS.

func (*Service) PublicTLS

func (s *Service) PublicTLS() *tls.Config

PublicTLS is the TLS of the subdomain: its Let's Encrypt certificate, and the TLS-ALPN-01 answers for it.

func (*Service) PublicTunnelReady

func (s *Service) PublicTunnelReady() <-chan struct{}

PublicTunnelReady closes once a host was set: the public server starts serving the tunnel's connections then.

func (*Service) RoleOf

func (s *Service) RoleOf(nodeID string) (plugin.SubHostRole, bool)

RoleOf is the subscription host role of a node now (the host, and the next one while moving): what its inbounds must fit.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run retries loading the initial state, keeps the bridge dialers current, and rechecks readiness until ctx ends. Once an off state is known it only waits for a host to be set.

func (*Service) SetRecoveryPreparer

func (s *Service) SetRecoveryPreparer(prepare RecoveryPreparer)

SetRecoveryPreparer attaches the admin surface's provisioner before serving requests.

Jump to

Keyboard shortcuts

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