Documentation
¶
Overview ¶
Package app is the composition root of `bubbles serve`: it opens the store, loads the TLS material, builds the HTTPS and onboarding handlers, binds both listeners, runs the background jobs and shuts everything down gracefully.
Index ¶
- Constants
- func CertManager(cfg config.Config, logger *slog.Logger, opts Options) (*tlsca.Manager, error)
- func DefaultLANAddrs() ([]netip.Addr, error)
- func SANSource(cfg config.Config, lanAddrs func() ([]netip.Addr, error), ...) func() (tlsca.SANs, error)
- func SANSourceWith(cfg config.Config, lanAddrs func() ([]netip.Addr, error), ...) func() (tlsca.SANs, error)
- type App
- func (a *App) Certs() *tlsca.Manager
- func (a *App) HTTPAddr() net.Addr
- func (a *App) HTTPSAddr() net.Addr
- func (a *App) HTTPSPort() int
- func (a *App) OnboardingURLs() []string
- func (a *App) RefreshMDNS()
- func (a *App) Reset(ctx context.Context, req reset.Request) (*reset.Result, error)
- func (a *App) Run(ctx context.Context) error
- func (a *App) Shutdown(ctx context.Context) error
- func (a *App) Tailscale(ctx context.Context) TailscaleStatus
- func (a *App) URLs() []string
- type Job
- type LogFiles
- type Options
- type TailnetClient
- type TailscaleStatus
- type Ticker
Constants ¶
const ( SANWatchInterval = 5 * time.Minute RenewCheckInterval = 12 * time.Hour // SessionPurgeInterval is how often expired sessions and old password // reset rows are deleted. SessionPurgeInterval = time.Hour )
Job intervals (pipeline step 18).
const DefaultShutdownTimeout = 10 * time.Second
DefaultShutdownTimeout bounds the graceful drain on shutdown.
const DrainTimeout = 3 * time.Second
DrainTimeout bounds how long a reset waits for requests in flight (after closing the gate and the WebSockets) before it deletes anything anyway.
const MaintenanceRetryAfter = "5"
MaintenanceRetryAfter is the Retry-After (seconds) of a maintenance 503.
const TailscaleCertInterval = 6 * time.Hour
TailscaleCertInterval is how often the Tailscale certificate is renewed (tailscale cert only asks for a new one when the old one nears expiry).
Variables ¶
This section is empty.
Functions ¶
func CertManager ¶
CertManager builds the TLS certificate manager for cfg: bring-your-own files when --tls-cert/--tls-key are set, else the local CA in <data>/tls with the leaf SANs discovered from the LAN addresses, host name, mDNS name and --tls-extra-dns. `bubbles cert reissue` uses it too.
func DefaultLANAddrs ¶
DefaultLANAddrs returns the host's ranked private LAN addresses.
func SANSource ¶
func SANSource(cfg config.Config, lanAddrs func() ([]netip.Addr, error), hostname func() (string, error)) func() (tlsca.SANs, error)
SANSource returns the leaf SAN discovery function for cfg.
func SANSourceWith ¶ added in v0.4.0
func SANSourceWith(cfg config.Config, lanAddrs func() ([]netip.Addr, error), hostname func() (string, error), tailnetName func() string) func() (tlsca.SANs, error)
SANSourceWith is SANSource that also adds the name tailnetName returns (the Tailscale MagicDNS name; nil or "" adds nothing).
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is a running bubbles server.
func New ¶
func New(ctx context.Context, cfg config.Config, logger *slog.Logger, opts Options) (_ *App, err error)
New wires the server for cfg. The data directory must have been prepared with config.EnsureDataDir and locked by the caller. Both listeners are bound before New returns (see HTTPSAddr and HTTPAddr), but nothing is served until Run.
func (*App) Certs ¶
Certs is the TLS certificate manager (a factory reset that rotates the CA replaces it).
func (*App) OnboardingURLs ¶
OnboardingURLs returns the onboarding base URLs, best first.
func (*App) RefreshMDNS ¶
func (a *App) RefreshMDNS()
RefreshMDNS re-announces the TXT record after the CA fingerprint changed.
func (*App) Reset ¶
Reset runs req on the live server (pipeline steps 19 and 20): the steps of internal/reset with hooks that enter maintenance mode, close every WebSocket with 4011 (content) or 4010 (factory), wait for requests in flight, and for a factory reset tear the services down, swap the CA when asked and rebuild everything on the new database. Confirmation and password checks are the caller's. If a step fails after maintenance mode began, the server stays in maintenance: a restart completes the reset.
func (*App) Run ¶
Run serves both listeners and runs the jobs until ctx is done or a listener fails, then shuts down gracefully within the shutdown timeout.
func (*App) Shutdown ¶
Shutdown stops accepting connections, drains in-flight requests until ctx expires (then closes them), and closes the database. It is idempotent.
type LogFiles ¶
type LogFiles interface {
// Reopen closes the live file, runs clear, then opens a fresh file.
Reopen(clear func() error) error
}
LogFiles is a log file writer a factory reset can wipe while the server runs (logging.RotatingWriter).
type Options ¶
type Options struct {
// Stderr receives the startup banner; nil discards it.
Stderr io.Writer
// Now is the clock; nil means time.Now.
Now func() time.Time
// NewTicker creates job tickers; nil means time.NewTicker.
NewTicker func(time.Duration) Ticker
// LANAddrs returns the ranked private LAN addresses; nil means
// DefaultLANAddrs.
LANAddrs func() ([]netip.Addr, error)
// Hostname returns the OS host name; nil means os.Hostname.
Hostname func() (string, error)
// ShutdownTimeout bounds the graceful drain; 0 means DefaultShutdownTimeout.
ShutdownTimeout time.Duration
// AuthParams are the argon2id parameters for new password hashes; the
// zero value means auth.DefaultParams (tests pass cheap ones).
AuthParams auth.Params
// BackupWorkFactor is the scrypt work factor (log2 N) for admin backups;
// 0 means age's default (tests pass a cheap one).
BackupWorkFactor int
// AdminPassword fixes the password of the bootstrapped admin instead of a
// generated one (tests).
AdminPassword string
// Tailnet asks Tailscale about this machine; nil means the tailscale
// command line (tailnet.Client).
Tailnet TailnetClient
// LogFiles is the writer behind the server log; a factory reset wipes
// the log directory through it. Nil: the directory is wiped directly.
LogFiles LogFiles
}
Options are the injectable dependencies of App. The zero value uses the real clock, tickers, network interfaces and host name.
type TailnetClient ¶ added in v0.4.0
type TailnetClient interface {
Status(ctx context.Context) (tailnet.Info, error)
Cert(ctx context.Context, domain, certFile, keyFile string) error
}
TailnetClient is the part of tailnet.Client the server uses; tests fake it.
type TailscaleStatus ¶ added in v0.4.0
type TailscaleStatus struct {
// Info is what Tailscale reports about this machine.
tailnet.Info
// URL is the HTTPS address on the MagicDNS name, "" without one.
URL string
// CertEnabled is --tailscale-cert.
CertEnabled bool
// CertActive is true while the Tailscale certificate is being served.
CertActive bool
// CertNotAfter is when the served Tailscale certificate expires.
CertNotAfter time.Time
// CertError says why the Tailscale certificate is not served, when
// CertEnabled and not CertActive.
CertError string
// CACoversName is true when the local CA may sign the MagicDNS name,
// so the name works with the local CA too.
CACoversName bool
}
TailscaleStatus is what the admin page and the banner show about Tailscale.