Documentation
¶
Overview ¶
Package share publishes apps of this box on the internet through the relay.
Index ¶
- Constants
- Variables
- func Label(composeName string) (string, error)
- func Serve(ctx context.Context, s *Session, shareAddr func() (string, error)) int
- func ValidName(name string) error
- type ACME
- type App
- type AppStatus
- type Apps
- type BusyError
- type CertStatus
- type CertView
- type DialError
- type ErrLabelTaken
- type Gateway
- type Info
- type Installed
- type Relay
- func (r *Relay) ClaimName(ctx context.Context, name string) (Info, error)
- func (r *Relay) ClearTXT(ctx context.Context) error
- func (r *Relay) ReleaseName(ctx context.Context) error
- func (r *Relay) SetTXT(ctx context.Context, value string) error
- func (r *Relay) Status(ctx context.Context) (Info, error)
- type Service
- func (s *Service) OnAppEvent(name string, properties map[string]string)
- func (s *Service) Reset(ctx context.Context)
- func (s *Service) Run(ctx context.Context)
- func (s *Service) SetName(ctx context.Context, name string, acceptTOS bool) error
- func (s *Service) Share(ctx context.Context, composeName string) error
- func (s *Service) Status(ctx context.Context) Status
- func (s *Service) StopAll(ctx context.Context) error
- func (s *Service) Unshare(ctx context.Context, composeName string) error
- type Session
- type State
- type Status
- type TXT
- type TunnelView
Constants ¶
const ( DefaultACMEDirectory = "https://acme-v02.api.letsencrypt.org/directory" TOSURL = "https://letsencrypt.org/repository/" )
const StateFile = "share.json"
StateFile is kept in the fleet's state directory, under the root.
const TunnelPath = "/v1/share/tunnel"
TunnelPath is the relay route a box dials to publish its apps.
Variables ¶
var ( ErrWaitMaster = errors.New("waiting for the master to register this box at the relay") ErrNoName = errors.New("this box has no public name yet") ErrNameTaken = errors.New("this name is already taken") ErrNameReserved = errors.New("this name is reserved") ErrNameRevoked = errors.New("this name was revoked and cannot be used") ErrNameQuarantine = errors.New("this name was released recently and is not available yet") )
var ( ErrTOS = errors.New("the terms of service of Let's Encrypt must be accepted") ErrNameSet = errors.New("this box already has a public name") ErrUnknownApp = errors.New("this app is not installed") ErrNoRelay = errors.New("remote access is off: public sharing goes through its relay") ErrNoPort = errors.New("this app has no web port to share") )
var ( // ErrBadLabel is Label's error. ErrBadLabel = errors.New("the app's name cannot be made into a DNS label") // ErrBadName is ValidName's error. ErrBadName = errors.New("a box name is 3 to 32 lowercase letters, digits or dashes, not starting or ending with a dash") )
var Default = New("/")
Default is the box's own; main wires its funcs.
ErrGatewayNoShare is what the gateway of a box without public sharing gives.
Functions ¶
Types ¶
type ACME ¶
type ACME struct {
Directory string // "" → CASAOS_SHARE_ACME_DIRECTORY or DefaultACMEDirectory
CAFile string // "" → CASAOS_SHARE_ACME_CA; a PEM root replacing the system pool (tests, Pebble)
AccountFile string // {"key": "<base64url P-256 PKCS8>"}
KeyFile, CertFile string
TXT TXT
Now func() time.Time // nil → time.Now
// contains filtered or unexported fields
}
ACME gets and renews the wildcard certificate of this box from Let's Encrypt by DNS-01.
func (*ACME) Loop ¶
Loop checks every tick and calls Obtain when Needs; after an error it waits an hour (measured with Now), doubling up to a day. An empty wildcard() means nothing is shared: idle.
func (*ACME) Needs ¶
Needs is true when there is no certificate for wildcard, or it expires within renewBefore.
func (*ACME) Obtain ¶
Obtain gets *.<host>: it writes KeyFile, then CertFile, only once the CA has issued.
func (*ACME) Status ¶
func (a *ACME) Status() CertStatus
type Apps ¶
type Apps struct{ RuntimePath func() string }
Apps is AppManagement, reached through the runtime directory.
type CertStatus ¶
CertStatus is what the certificate on disk and the last attempt say.
type DialError ¶
DialError is a refused upgrade (401, 403, 429, 503...). StatusCode is 0 when the relay did not answer; RetryAfter comes from a 429's Retry-After header, 0 otherwise.
type ErrLabelTaken ¶
type ErrLabelTaken struct{ Other string }
ErrLabelTaken is a Share refused because another shared app has the same address.
func (ErrLabelTaken) Error ¶
func (e ErrLabelTaken) Error() string
type Gateway ¶
type Gateway struct{ RuntimePath func() string }
Gateway is the box's gateway, reached through the runtime directory.
func (Gateway) DeleteHost ¶
DeleteHost stops the gateway sending requests for host anywhere.
type Info ¶
type Info struct {
Name string `json:"name"`
Host string `json:"host"`
Domain string `json:"domain"`
TunnelOnline bool `json:"tunnel_online"`
}
Info is a box's public name at the relay.
type Installed ¶
type Installed struct{ Name, Title, Port, Scheme string }
Installed is an installed app, by its compose name.
type Relay ¶
type Relay struct {
// Signed sends a request signed with this box's key (wired by main to the fleet's relay client).
Signed func(ctx context.Context, method, path string, body []byte) (status int, reply []byte, retryAfter time.Duration, err error)
// RegisterSelf links this box's key at the relay (wired to the fleet).
RegisterSelf func(ctx context.Context) error
}
Relay talks to the relay as this box.
func (*Relay) ReleaseName ¶
ReleaseName gives the public name back (also fine when there was none).
type Service ¶
type Service struct {
Root string
RuntimePath func() string
Relay *Relay
Gateway Gateway
Apps Apps
ACME *ACME
BoxKey func() (ed25519.PrivateKey, error)
RelayURL func() (string, bool)
Dialer *websocket.Dialer // nil → Dial's default
Log func(msg string, err error)
Now func() time.Time
// contains filtered or unexported fields
}
Service shares the apps of this box: its name at the relay, the Gateway's host routes, the tunnel and the certificate.
func (*Service) OnAppEvent ¶
OnAppEvent follows AppManagement (Hub.OnAppEvent). It returns at once.
func (*Service) Reset ¶
Reset forgets the sharing of a box leaving its relay: the host routes are deleted first (local and fast), then the name is released, best effort, then the tunnel stopped and the state cleared. The certificate stays. It runs while the fleet holds its relay lock: it only calls the relay's Signed and the Gateway.
func (*Service) Run ¶
Run keeps the host routes, the tunnel and the certificate until ctx is done. Without a name and an app shared, nothing goes out. A second Run while one is under way returns at once.
func (*Service) SetName ¶
SetName claims name at the relay and saves it. The tunnel waits for an app to be shared.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is the box end of a tunnel. The relay opens the streams, so there is no Open: the relay drops the tunnel of a box that opens one.
func Dial ¶
func Dial(ctx context.Context, relayURL string, key ed25519.PrivateKey, d *websocket.Dialer) (*Session, error)
Dial opens the tunnel to relayURL (https://host, or http:// in tests), signing GET TunnelPath with key. d nil means a dialer with a 15 s handshake timeout that honours the proxy environment.
type State ¶
type State struct {
Name string `json:"name"`
Host string `json:"host"`
Domain string `json:"domain"`
TOSAcceptedAt time.Time `json:"tos_accepted_at,omitzero"`
Apps map[string]App `json:"apps"`
}
State is what this box shares, as saved in StateFile.
type Status ¶
type Status struct {
Supported bool `json:"supported"`
Reason string `json:"reason"` // remote-access, gateway, relay, master
Name string `json:"name"`
Host string `json:"host"`
Domain string `json:"domain"`
TOSURL string `json:"tos_url"`
Apps []AppStatus `json:"apps"`
Cert CertView `json:"cert"`
Tunnel TunnelView `json:"tunnel"`
}
Status is what the API answers.
type TXT ¶
type TXT interface {
SetTXT(ctx context.Context, value string) error
ClearTXT(ctx context.Context) error
}
TXT publishes the DNS-01 record through the relay (a *Relay does).