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 ¶
- type Config
- type Fleet
- type RecoveryPreparer
- type Resolver
- type Service
- func (s *Service) ActivateInstalled(ctx context.Context, actor, nodeID, domain, siteName, path, pin string) error
- func (s *Service) CheckInstallDNS(ctx context.Context, sshHost, domain, siteName string, ipv6 []netip.Addr) error
- func (s *Service) Close()
- func (s *Service) DeactivateInstalled(ctx context.Context, actor, nodeID string) error
- func (s *Service) Handler(opts ...connect.HandlerOption) (string, http.Handler)
- func (s *Service) Load(ctx context.Context) error
- func (s *Service) PrepareInstall(ctx context.Context, sshHost, domain, siteName string, skipDNS bool) (string, error)
- func (s *Service) PublicListener() net.Listener
- func (s *Service) PublicTLS() *tls.Config
- func (s *Service) PublicTunnelReady() <-chan struct{}
- func (s *Service) RoleOf(nodeID string) (plugin.SubHostRole, bool)
- func (s *Service) Run(ctx context.Context)
- func (s *Service) SetRecoveryPreparer(prepare RecoveryPreparer)
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 (*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 ¶
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) Load ¶
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 ¶
PublicListener yields the connections of the subdomain the hosts carry: the public server serves them with PublicTLS.
func (*Service) PublicTLS ¶
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 ¶
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.