Documentation
¶
Overview ¶
Package hostd is the controlled side of RemoHop: the daemon behind `remohop host`. It owns the machine's identity, keeps it registered with the rendezvous server, answers hole-punch introductions, authenticates incoming P2P connections and hands each authenticated one to the session layer with peer.HostServices.
It also owns two small services every host offers, with their client APIs: "pair" (mint a pairing token so the client can come back without the password) and "ping" (round-trip probe over the session).
Index ¶
- Constants
- Variables
- func Allowed(c *peer.Conn, feature perm.Feature) bool
- func AuthorizerScope(name string) string
- func CheckOwnPassword(pw string) error
- func ConfiguredDeviceName() string
- func ControlCall(dir, op string, args, out any) error
- func ControlDisconnect(dir string, id int) (int, error)
- func DeviceName() string
- func DisableTOTP(dir string) error
- func FeatureSetting(f perm.Feature) string
- func GrantsHeld(dir string) bool
- func HoldGrants(dir string, hold bool) (bool, error)
- func IssueGrant(dir string, req GrantRequest) (grant.Grant, string, error)
- func LoginRefusal(err error) *auth.Error
- func OwnerEnded(reason string) bool
- func Recordings(dir, name string) ([]string, error)
- func RegisterAuditSink(fn AuditSink)
- func RegisterAuthorizer(a Authorizer)
- func RegisterControl(op string, fn ControlFunc)
- func RegisterExtension(fn func(ctx context.Context, h *Host))
- func RegisterRecordingSink(fn RecordingSink)
- func RegisterScope(s Scope)
- func RegisterSubcommand(name string, run func(ctx context.Context, env *cli.Env, args []string) int)
- func RevokeGrant(dir, name string) (bool, error)
- func RunTOTPConfig(ctx context.Context, env *cli.Env, args []string) int
- func SetDefaultDeviceName(name string)
- func SuspendGrants(dir string, suspend bool, names ...string) ([]string, error)
- func TOTPLabel(dir string) string
- func TOTPStatus(dir string) (on bool, since time.Time, err error)
- func WatchFeature(c *peer.Conn, f perm.Feature, fn func(allowed bool)) (stop func())
- type AccessReply
- type AccessRequest
- type AlreadyRunningError
- type Approval
- type AuditEntry
- type AuditSink
- type Authorizer
- type Config
- type ControlFunc
- type ControlSession
- type GrantRequest
- type GrantStatus
- type GrantStore
- type Host
- func (h *Host) Addr() net.Addr
- func (h *Host) Decide(n int, allow bool) error
- func (h *Host) DecideShown(n int, allow bool) (Approval, error)
- func (h *Host) DecideWith(n int, allow bool, features []perm.Feature) error
- func (h *Host) Dir() string
- func (h *Host) DirectAddrs() []netip.AddrPort
- func (h *Host) Disconnect(id int, reason string) error
- func (h *Host) ExtendApproval(n int, d time.Duration) (time.Time, error)
- func (h *Host) ID() string
- func (h *Host) Logger() *slog.Logger
- func (h *Host) OnChange(fn func())
- func (h *Host) Password() string
- func (h *Host) PasswordMode() string
- func (h *Host) Pending() []Approval
- func (h *Host) PolicyChanged()
- func (h *Host) PublicKey() ed25519.PublicKey
- func (h *Host) Registered() <-chan struct{}
- func (h *Host) RotatePassword() error
- func (h *Host) Run(ctx context.Context) error
- func (h *Host) Sessions() []*Session
- func (h *Host) SetFixedPassword(pw string) error
- func (h *Host) SetSessionFeatures(id int, all bool, features []perm.Feature) error
- func (h *Host) SetTempPassword(pw string) error
- func (h *Host) Signal() (string, signal.Options)
- func (h *Host) SignalExt(ctx context.Context, typ string, payload any) (json.RawMessage, error)
- func (h *Host) SignalServer() string
- func (h *Host) Status() Status
- func (h *Host) TempPassword() (password, mode string)
- func (h *Host) Tokens() *auth.TokenStore
- type Limits
- type Overrides
- type PairRequest
- type Pairing
- type PingInfo
- type PingOptions
- type PingResult
- type PortMapStatus
- type Recording
- type RecordingSink
- type RestartError
- type RestartInfo
- type RestartNotice
- type RestartOutcome
- type RestartPlan
- type Restarter
- type Scope
- type Session
- type SessionStatus
- type Status
- type TOTPSetup
Constants ¶
const ( // AuditFile is the host's audit log inside the config directory: one // JSON object per line, mode 0600. It holds the records: accepted // logins, approvals, feature use, grant actions, session ends. AuditFile = "audit.jsonl" // AuditRefusedFile holds refused logins and grant refusals, which // anyone who can reach the host (or a granted session) can produce in // bulk. Kept apart so that they cannot push the records out. AuditRefusedFile = "audit-refused.jsonl" )
const ( SettingPassword = "host-password" SettingListen = "host-listen" )
Config keys.
const ( SettingName = "name" SettingTermKeep = "term-keep" )
Config keys for the device name and the shell keep-alive.
const ( ReasonDisconnectedAtHost = "disconnected at the host" // the desktop app, quick assist ReasonDisconnectedByOwner = "disconnected by the host's owner" // remohop host disconnect ReasonDisconnectedOnPhone = "disconnected on the phone" // a phone sharing its screen ReasonPhoneLocked = "the phone was locked" // a phone sharing its screen was locked ReasonPairingRevoked = "pairing revoked" )
The reasons a host gives when a person at it ends a session on purpose. A client that would otherwise reconnect by itself (the phone apps' persistent sessions) must not log straight back in after one of them: OwnerEnded. Older hosts send the same words, so the strings stay.
const ( SettingAsk = "ask" SettingAskPaired = "ask-paired" SettingOTP = "otp" )
Config keys the host reads while it runs.
const ( RestartNoControl = "no_control" // the session may not control the host RestartNotPermitted = "not_permitted" // the host's account may not restart the computer RestartUnsupported = "unsupported" // not on this system, or an older host RestartBusy = "busy" // a restart is already scheduled RestartChanged = "changed" // the computer locked or unlocked since the controller confirmed RestartFailed = "failed" // anything else )
Restart error codes, as the client reports them (RestartError.Code).
const ( HintPolkit = "polkit" // Linux: a polkit rule must allow this user to reboot HintAutomation = "automation" // macOS: allow RemoHop to control System Events HintPrivilege = "privilege" // Windows: the account lacks the shutdown privilege )
Hints name what an owner can do about not_permitted, so that the page can say it in its own words (RestartError.Hint).
const ( ServicePair = "pair" ServicePing = "ping" )
Service names.
const ( // DefaultAskTimeout is how long a login waits for the owner's answer // before it is refused. DefaultAskTimeout = 30 * time.Second )
const DefaultRestartDelay = 5 * time.Second
DefaultRestartDelay is how long after its answer the host restarts the computer, so that the answer reaches the controller first.
const GrantsFile = "grants.json"
GrantsFile holds the host's grants (internal/grant) in the config directory, mode 0600. Their credentials are entries of the pairing-token store marked with the grant's name.
const PanicFile = "panic.json"
PanicFile, in the config directory, holds every grant while it exists: `remohop host panic` writes it and `remohop host resume` (of all grants) removes it. It covers what the grants file cannot: the grants that authorizers (RegisterAuthorizer) give keys the owner never paired. While it exists no such grant admits a login or keeps a session. It survives a restart of the host.
const RecordingsDir = "recordings"
RecordingsDir is where recordings of granted sessions are kept, one subdirectory per grant, inside the config directory.
const RestartPairingLife = 11 * time.Minute
RestartPairingLife is how long a restart pairing (PairForRestart) is valid: the controller's 10-minute wait for the computer to come back, plus the delay before the restart and a margin for clocks.
const ServiceAccess = "access"
ServiceAccess is the service a session uses to ask the host's owner for features its limit does not include.
const ServiceLimits = "limits"
ServiceLimits tells a client what its session may do. Every session may ask; it is how an agent learns its grant's limits from the host that enforces them.
const ServiceRestart = "restart"
ServiceRestart restarts the host's computer (docs/design/restart-reconnect.md). It is in the input feature: only a session that may control the host may ask.
Variables ¶
var ErrNotRegistered = errors.New("hostd: not registered with the rendezvous server")
ErrNotRegistered is returned by SignalExt while the host is not registered with its rendezvous server.
var SavedPeers func() (int, error)
SavedPeers, if set, reports how many hosts this machine has saved as a client, for `remohop status`. internal/dial, which owns that store, sets it.
Functions ¶
func Allowed ¶
Allowed reports whether the host's owner currently allows feature for the session behind c. Services that offer more than their own feature covers ask it for the rest: the desktop service is in "screen" and calls Allowed(c, perm.Input) before it injects keyboard or mouse events, so that a host with input off still shows its screen, and WatchFeature to learn when the answer changes while its stream is open. A connection that is not a session of a running Host is restricted as grant.Of says: not at all if it was marked as having full access (grant.AttachFull, as test sessions are), entirely if nothing was set up for it.
func AuthorizerScope ¶
AuthorizerScope is the auth.Result.Scope of the sessions an authorizer admitted.
func CheckOwnPassword ¶
CheckOwnPassword is the rule for a fixed password the owner chooses in a front end (the desktop app, a phone's host mode), where every login still waits for the owner's answer: at least 8 characters with two of letters, digits and other characters, so that it is not a word or a date.
func ConfiguredDeviceName ¶
func ConfiguredDeviceName() string
ConfiguredDeviceName is the "name" setting alone, cleaned: empty when the user has not chosen one.
func ControlCall ¶ added in v1.0.12
ControlCall sends a request for a registered control operation to the host running on dir and decodes its result into out (which may be nil).
func ControlDisconnect ¶
ControlDisconnect ends session id (0: every session) of the host running on dir and reports how many it ended.
func DeviceName ¶
func DeviceName() string
DeviceName is this machine's device name: the "name" setting, cleaned, or else the default the program set (SetDefaultDeviceName), or else the computer's host name, so that a host's approval prompt always has something to show.
func DisableTOTP ¶ added in v1.0.12
DisableTOTP switches the check off in dir and deletes the secret.
func FeatureSetting ¶
FeatureSetting is the config key of a feature switch.
func GrantsHeld ¶
GrantsHeld reports whether the host-wide suspension of PanicFile is in force. A file that cannot be looked at counts as there: a broken config directory never opens anything up.
func HoldGrants ¶
HoldGrants sets (hold true) or lifts the host-wide suspension of PanicFile, and reports whether that changed anything.
func IssueGrant ¶
IssueGrant creates (or replaces) a grant in the host config directory dir and returns it with the credential its holder redeems (`remohop peers redeem TARGET CODE`). Reissuing a name replaces the grant and its credential; sessions on the old credential are closed.
func LoginRefusal ¶
LoginRefusal recovers the reason a host closed a connection during login from the error a client got on it, or returns nil if the error is something else. A host refuses on the login stream and in the close frame; whichever the client sees first tells it the same thing. Like everything a host says before it has authenticated, the reason is taken from a fixed vocabulary and its retry time is clamped.
func OwnerEnded ¶
OwnerEnded reports whether reason, given by a host closing a session, says a person there ended it (rather than the host stopping or the network failing), so the client must not reconnect.
func Recordings ¶
Recordings lists the recording files of a grant, oldest first.
func RegisterAuditSink ¶
func RegisterAuditSink(fn AuditSink)
RegisterAuditSink adds an audit sink. Call it from init().
func RegisterAuthorizer ¶
func RegisterAuthorizer(a Authorizer)
RegisterAuthorizer adds an authorizer. Call it from init(). Keys the owner authorised, and scopes, are consulted first.
func RegisterControl ¶ added in v1.0.12
func RegisterControl(op string, fn ControlFunc)
RegisterControl adds an operation to the running host's control channel, for a feature built on top of the host (it cannot be imported here) that a local command talks to: see ControlCall. Call it from init(). The channel is open only to the user the host runs as.
func RegisterExtension ¶
RegisterExtension adds a function that runs beside every Host for as long as Run runs; it must return when ctx ends. Call it from init().
func RegisterRecordingSink ¶
func RegisterRecordingSink(fn RecordingSink)
RegisterRecordingSink adds a recording sink. Call it from init().
func RegisterSubcommand ¶ added in v1.0.12
func RegisterSubcommand(name string, run func(ctx context.Context, env *cli.Env, args []string) int)
RegisterSubcommand adds `remohop host NAME ...`, for a feature built on top of the host that cannot be imported here (`remohop host chat`). Call it from init().
func RevokeGrant ¶
RevokeGrant deletes a grant and its credential. It reports whether there was such a grant (or credential).
func RunTOTPConfig ¶ added in v1.0.12
RunTOTPConfig is `remohop config totp on|off|status`. Cancelling ctx (an interrupt) ends the wait for the setup code.
func SetDefaultDeviceName ¶
func SetDefaultDeviceName(name string)
SetDefaultDeviceName sets the name DeviceName gives when the user has not chosen one, in place of the host name: for a program that knows a better one, such as a phone's model (a phone's host name is "localhost" or nothing at all). An empty name goes back to the host name.
func SuspendGrants ¶
SuspendGrants suspends (or with suspend false, resumes) the named grants, or all of them when names is empty, and returns the names changed. With no names it also sets or lifts the host-wide suspension (PanicFile), which holds the grants authorizers give as well.
func TOTPLabel ¶ added in v1.0.12
TOTPLabel is the name an authenticator app shows for this host: its device name, else an ID it was given, else "host".
func TOTPStatus ¶ added in v1.0.12
TOTPStatus reports whether the check is on in dir; err is set when it is on but its file cannot be used (password logins are then refused).
func WatchFeature ¶
WatchFeature calls fn(false) as soon as the host's owner no longer allows feature f for the session behind c (Allowed(c, f) turns false) and fn(true) when it is allowed again. If f is not allowed when WatchFeature is called, fn(false) runs before it returns. Changes made in the config file are noticed within a fraction of a second, and a front end's own switches at once (Host.PolicyChanged).
Calls to fn for one session never overlap. fn runs on the host's watcher, so it must be quick and must not call WatchFeature or PolicyChanged itself. stop ends the watch; a call to fn that was already under way may still finish after stop returns. For a connection that is not a session of a Host, fn is never called.
Types ¶
type AccessReply ¶
type AccessReply struct {
Error string `json:"error,omitempty"`
All bool `json:"all,omitempty"`
Features []string `json:"features,omitempty"`
}
AccessReply answers an AccessRequest. Features is what the session may use now; All means it has no limit.
func RequestAccess ¶
func RequestAccess(ctx context.Context, c *peer.Conn, features []perm.Feature) (*AccessReply, error)
RequestAccess asks the host of c for features the session's limit does not include, waiting for its owner's answer. It returns what the session may use afterwards.
type AccessRequest ¶
type AccessRequest struct {
Features []string `json:"features"`
}
AccessRequest asks for features ("input", "file", ...).
type AlreadyRunningError ¶
type AlreadyRunningError struct{ Status *Status }
AlreadyRunningError is returned by StartExclusive when another host process is serving the same identity.
func (*AlreadyRunningError) Error ¶
func (e *AlreadyRunningError) Error() string
type Approval ¶
type Approval struct {
N int `json:"n"`
From netip.AddrPort `json:"from"`
Identity string `json:"identity"` // fingerprint of the client's key
Name string `json:"name,omitempty"` // pairing or authorised-key name
// Device is the name the client gave itself (`remohop config name`): a
// claim, unverified; Identity is what identifies it.
Device string `json:"device,omitempty"`
Auth auth.Kind `json:"auth"`
Since time.Time `json:"since"`
// Deadline is when the request is refused if nobody has answered it:
// the host's AskTimeout after it started waiting, or later when its
// owner asked for a little more time (ExtendApproval).
Deadline time.Time `json:"deadline"`
// Grant and Action are set when an action of a granted session (not a
// login) waits for approval: the grant's name and what is asked, e.g.
// "exec: git push".
Grant string `json:"grant,omitempty"`
Action string `json:"action,omitempty"`
// Access is set when a connected session asks for more of what its
// owner limited it to (see Host.SetSessionFeatures): the features it
// asks for; Session is its ID.
Access []perm.Feature `json:"access,omitempty"`
Session int `json:"session,omitempty"`
// contains filtered or unexported fields
}
Approval is a login that has presented a valid credential and is waiting for the host's owner to allow it.
type AuditEntry ¶
type AuditEntry struct {
Time time.Time `json:"time"`
Event string `json:"event"`
// Fields are the event's details. Values that came from the client
// were cleaned (auth.CleanText) when written. A summary of refused
// entries that were not written one by one has "suppressed" (their
// number) and "since" (the start of the window).
Fields map[string]string `json:"fields,omitempty"`
}
AuditEntry is one line of the audit log.
func GrantAudit ¶
func GrantAudit(dir, name string, n int) ([]AuditEntry, error)
GrantAudit returns the last n audit entries of the grant called name (every entry when name is empty), oldest first.
type AuditSink ¶
type AuditSink func(dir string, e AuditEntry, refused bool)
AuditSink receives one audit entry. dir is the config directory of the host that wrote it (one process can run several hosts, in tests). refused is true for entries of the refused log (AuditRefusedFile), including the summaries of suppressed ones.
type Authorizer ¶
type Authorizer struct {
// Name identifies the authorizer; its sessions' scope is
// AuthorizerScope(Name).
Name string
// Grant returns the grant key may use now, and a display name for the
// session. g.Name must pass grant.ValidName. Expires and Suspended are
// honoured; TokenID, Created and the other bookkeeping fields are not
// used.
Grant func(h *Host, key ed25519.PublicKey) (g grant.Grant, name string, ok bool)
}
Authorizer lets a feature built on the host vouch for keys the owner never paired, with a grant: a key it admits logs in as if it had redeemed that grant, and the host enforces it as it enforces grants its owner issued (allowed services, file roots, commands, approvals, recording, session limit, audit). RemoHop Teams uses it for its team policy.
Grant is asked at login and again at every permission check of the session, so a withdrawn or changed grant ends the session at its next stream, command or file operation, and within seconds otherwise (enforceGrants). It must be quick and must not block.
type Config ¶
type Config struct {
// Dir holds the identity key, pairing tokens and the status file.
// Empty means the remohop config directory.
Dir string
// Signal is the rendezvous server ("host[:port]"). Empty runs without
// one: the host is then reachable only by direct address.
Signal string
SignalOptions signal.Options
// Listen is the UDP address to bind, default ":0".
Listen string
// Password fixes the login password for this run. Empty means the
// fixed password from the config file, if any, and otherwise only the
// generated temporary one.
Password string
// AskTimeout is how long a login waits for the owner's approval when
// the "ask" setting is on. Default DefaultAskTimeout.
AskTimeout time.Duration
// OnApproval is called (from other goroutines) for each login that
// starts waiting for approval; answer with Host.Decide.
OnApproval func(Approval)
// Control makes Run serve the local control socket in Dir, which
// `remohop host approve`, `remohop host otp` and `remohop status` talk to.
Control bool
// NoPairing refuses requests to mint pairing tokens.
NoPairing bool
// Services is what authenticated clients may open; nil means
// peer.HostServices.
Services *peer.Registry
// Logger receives connection and rendezvous events; nil discards them.
Logger *slog.Logger
// Limiter tunes brute-force protection; the zero value is the default
// policy.
Limiter auth.LimiterConfig
// Overrides tighten the config file's access settings for this run;
// nil leaves them as they are.
Overrides *Overrides
// NoPortMap keeps the host from asking the router to forward its UDP
// port (internal/portmap), as the portmap setting and REMOHOP_PORTMAP=0
// do. A host without a rendezvous server, or on a PacketConn, never
// asks.
NoPortMap bool
// NoLANDiscovery keeps the host from answering discovery on the local
// network (internal/lan), as the lan-discovery setting and
// REMOHOP_LAN_DISCOVERY=0 do. A host on a PacketConn, or bound to a
// loopback or IPv6 address, never answers.
NoLANDiscovery bool
// Restarter restarts the computer when a controller asks (restart.go);
// nil means the system's. RestartDelay is how long after its answer
// (default DefaultRestartDelay). OnRestart, if set, is called once a
// restart is accepted, before the delay runs: the desktop app shows a
// notice with it.
Restarter Restarter
RestartDelay time.Duration
OnRestart func(RestartNotice)
// BootID, if set, replaces the name of the computer's boot that
// clients compare to tell that it restarted (PingInfo.Boot). Tests
// that stand a new host in for a restarted one set it.
BootID string
// PacketConn, if set, is used instead of opening a socket on Listen,
// and Locals replaces interface enumeration. Tests on a virtual
// network use both. Mapped, if set, replaces the router port mapping
// as the source of the address offered for a forwarded port (see
// nat.Socket.Mapped); tests give the address of a forward they set up.
PacketConn net.PacketConn
Locals func() []netip.Addr
Mapped func() netip.AddrPort
}
Config configures a Host.
type ControlFunc ¶ added in v1.0.12
type ControlFunc func(h *Host, args json.RawMessage) (any, error)
ControlFunc serves a control operation registered with RegisterControl: args are the request's arguments as the caller sent them, and the result is sent back as JSON.
type ControlSession ¶
type ControlSession struct {
ID int `json:"id"`
Peer string `json:"peer"` // pairing name or key fingerprint
Device string `json:"device,omitempty"` // the name the client gave itself
Identity string `json:"identity"`
From string `json:"from"`
Path string `json:"path"`
Since time.Time `json:"since"`
// Authorizer and Grant are set for sessions an Authorizer admitted.
Authorizer string `json:"authorizer,omitempty"`
Grant string `json:"grant,omitempty"`
}
ControlSession is a live session as the control channel reports it (the desktop app shows the RemoHop service's sessions with it, and can end them).
func ControlSessions ¶
func ControlSessions(dir string) ([]ControlSession, error)
ControlSessions lists the sessions of the host running on dir.
type GrantRequest ¶
type GrantRequest struct {
Name string
For time.Duration // how long it is valid
Allow []string // allow-list items (see grant.Parse)
Commands []string // command allow-list
Approve string // grant.ApproveNone, ApproveFirst or ApproveEach
// MaxSessions bounds concurrent sessions; 0 means
// grant.DefaultMaxSessions.
MaxSessions int
Record bool
// ClientKey, if set, binds the credential to that client identity;
// otherwise the first client to log in with it is bound.
ClientKey ed25519.PublicKey
}
GrantRequest describes a grant to issue.
type GrantStatus ¶
type GrantStatus struct {
Name string `json:"name"`
State grant.State `json:"state"`
Created time.Time `json:"created"`
Expires time.Time `json:"expires"`
Allow []string `json:"allow"`
Commands []string `json:"commands,omitempty"`
Summary []string `json:"summary"`
Approve string `json:"approve"`
MaxSessions int `json:"max_sessions"`
Record bool `json:"record,omitempty"`
// Identity is the fingerprint of the client the credential is bound
// to; empty until it is redeemed.
Identity string `json:"identity,omitempty"`
// Sessions is the number of live sessions, when a host is running.
Sessions int `json:"sessions"`
}
GrantStatus is a grant as listed by `remohop host grants --json`.
type GrantStore ¶
type GrantStore struct {
// contains filtered or unexported fields
}
GrantStore is the host's grants file. Like the token store, every operation goes to the file, under a cross-process lock for changes, so `remohop host grant`, `revoke` and `panic` run from another process apply to a running host at once.
func OpenGrantStore ¶
func OpenGrantStore(dir string) *GrantStore
OpenGrantStore returns the grant store in dir.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host is a running (or ready to run) host daemon.
func New ¶
New prepares a host: loads or creates the identity, picks the password, binds the socket and starts listening. Call Run to serve.
func StartExclusive ¶
StartExclusive is New for a process that is the machine's host: it refuses to start while another host runs on the same identity (the two would keep taking the ID away from each other; *AlreadyRunningError), records the new host in the status file and keeps that file current. Call stop after Run returns; it removes the file. `remohop host` does the same by hand.
func (*Host) Decide ¶
Decide answers pending approval n. n == 0 answers the one request that is waiting, and is refused when more than one is: an answer must not land on a request other than the one its giver read.
func (*Host) DecideShown ¶
DecideShown is Decide, and returns the request it answered, so that the answer can be confirmed with its number and what it was about.
func (*Host) DecideWith ¶
DecideWith answers pending approval n like Decide, and an allowed login gets only the features listed, on top of what the host allows anyway: the owner's choice for this one client. The session can ask for more later (ServiceAccess), and the owner can change it with SetSessionFeatures. For an approval that is not a login, features are ignored.
func (*Host) DirectAddrs ¶
DirectAddrs lists the addresses at which the host can be dialled directly (`remohop ADDR:PORT ...`) by machines that can route to them.
func (*Host) Disconnect ¶
Disconnect ends the session with the given ID, telling the client why.
func (*Host) ExtendApproval ¶
ExtendApproval gives pending request n at least d more before it is refused for want of an answer, and returns its new deadline. It is for an owner who has started to answer and needs a moment longer: a phone asks its owner to allow screen recording in a system prompt of its own after they tapped Allow. A wait never grows beyond the host's AskTimeout plus DefaultAskTimeout from when it started.
func (*Host) OnChange ¶
func (h *Host) OnChange(fn func())
OnChange registers fn to be called (from other goroutines) whenever the host's registration state or password changes.
func (*Host) Password ¶
Password is a password clients can log in with now, in canonical form: the temporary one if it is accepted, else the fixed one.
func (*Host) PasswordMode ¶
PasswordMode names what Password is: "temporary" (one per run of the host), "one-time" (replaced after every login), "fixed", or "fixed+one-time".
func (*Host) PolicyChanged ¶
func (h *Host) PolicyChanged()
PolicyChanged applies a change of what the host allows to the sessions already connected at once, rather than at the next periodic check: streams of a feature that is now off end, and a desktop stream stops taking input when input is off. It returns once that has been set in motion (streams that do not end by themselves are reset shortly after). A front end calls it after changing what its Overrides.Features returns.
func (*Host) Registered ¶
func (h *Host) Registered() <-chan struct{}
Registered is closed once the host has registered with the rendezvous server for the first time.
func (*Host) RotatePassword ¶
RotatePassword replaces the temporary password.
func (*Host) Run ¶
Run serves until ctx is cancelled, then closes every session and the socket. A Host cannot be restarted.
func (*Host) SetFixedPassword ¶
SetFixedPassword changes the password given for this run (Config.Password) while the host runs: the owner chose their own password in a front end, or went back to the temporary one (""). Sessions already open stay; logins from now on need the new password.
func (*Host) SetSessionFeatures ¶
SetSessionFeatures replaces the limit of session id: nil features with all true lifts it, otherwise the session may use only features. What it has open with a feature it loses ends at once.
func (*Host) SetTempPassword ¶
SetTempPassword replaces the temporary password with pw, given in the internal form or the displayed form ("abcd-efgh"). An empty or malformed pw is an error and leaves the current password in place. Setting the password it already has changes nothing, so a login proving it meanwhile still succeeds.
func (*Host) Signal ¶
Signal is the rendezvous server the host registers with (empty without one) and its options, for extensions that dial other hosts through it.
func (*Host) SignalExt ¶
SignalExt sends an extension request (signal.RegisterRequest's x-NAME types) to the host's rendezvous server, over the connection the host is registered on and with the host's identity key proven for it. Code built on the host (an extension registered with RegisterExtension) uses it to talk to a service on the same server without a connection of its own: a second connection per host would count against the server's per-address limit. It returns ErrNotRegistered while the host is not registered; callers wait for the next registration or dial on their own.
func (*Host) SignalServer ¶
SignalServer is the rendezvous server the host registers with, as configured ("" for none).
func (*Host) TempPassword ¶
TempPassword returns the temporary password if one is accepted (formatted for display), and the password mode.
func (*Host) Tokens ¶
func (h *Host) Tokens() *auth.TokenStore
Tokens is the host's pairing-token store.
type Limits ¶
type Limits struct {
// Grant is the grant the session stands on; empty means full access
// within the host's feature switches.
Grant string `json:"grant,omitempty"`
// Expires is when the grant ends (and the session with it).
Expires *time.Time `json:"expires,omitempty"`
// Allowed and Denied list capabilities in the allow-list vocabulary
// (shell:run-only, files:read under ..., screenshot, ...).
Allowed []string `json:"allowed"`
Denied []string `json:"denied,omitempty"`
// Shell is "none", "run-only" or "full".
Shell string `json:"shell"`
// Commands, if any, are the only commands that may run.
Commands []string `json:"commands,omitempty"`
// ReadRoots and WriteRoots confine file access; ReadAll and WriteAll
// mean anywhere the host's user can.
ReadAll bool `json:"read_all,omitempty"`
WriteAll bool `json:"write_all,omitempty"`
ReadRoots []string `json:"read_roots,omitempty"`
WriteRoots []string `json:"write_roots,omitempty"`
// Approve is "none", "first" or "each": whether the host's owner is
// asked before commands and file changes.
Approve string `json:"approve,omitempty"`
// Recorded says command and terminal output is recorded on the host.
Recorded bool `json:"recorded,omitempty"`
MaxSessions int `json:"max_sessions,omitempty"`
// FeaturesOff are the host's own feature switches that are off; they
// apply on top of any grant.
FeaturesOff []string `json:"features_off,omitempty"`
Error string `json:"error,omitempty"`
}
Limits describes what a session may do on its host.
type Overrides ¶
type Overrides struct {
// AskAll makes every login wait for approval at the host, pairings
// and authorised keys included.
AskAll bool
// TempPasswordOnly ignores a fixed password in the config file: only
// the generated temporary password logs in.
TempPasswordOnly bool
// Features, if set, is asked which features are allowed right now;
// a feature missing from the answer (or false) is off. It is called
// often and from many goroutines.
Features func() map[perm.Feature]bool
}
Overrides tighten, for one run of a host, what its config file allows. A front end that runs the host for a single sitting (`remohop quick`) sets them so that its promises ("you approve every connection") hold whatever `remohop config` says. An override can only take away: nothing the config file forbids becomes allowed.
type PairRequest ¶
type PairRequest struct {
// Name labels the pairing on the host (`remohop host paired`), typically
// the client's hostname.
Name string `json:"name"`
}
PairRequest asks the host to mint a pairing token for the calling client.
type Pairing ¶
Pairing is a minted token: a credential the client stores and later presents instead of the password.
type PingInfo ¶
type PingInfo struct {
// Observed is the client's address as the host sees it on the P2P
// path: the client's public address when a NAT is in between.
Observed string `json:"observed"`
// Version is the host's remohop version.
Version string `json:"version"`
// Name is the host's device name (`remohop config name`), if it has one.
Name string `json:"name,omitempty"`
// Boot names the computer's current boot (it changes when the
// computer restarts), and Restart is the host's last restart that did
// not happen, if any (restart.go): a controller that had the host
// restart reads them when it logs in again.
Boot string `json:"boot,omitempty"`
Restart *RestartOutcome `json:"restart,omitempty"`
}
PingInfo is what the host reports when a ping stream opens.
type PingOptions ¶
type PingOptions struct {
// Count is the number of probes, default 4.
Count int
// Interval is the pause between probes, default 200 ms.
Interval time.Duration
// OnReply, if set, is called after each probe's reply.
OnReply func(seq int, rtt time.Duration)
}
PingOptions configures Ping.
type PingResult ¶
PingResult is the outcome of Ping.
func Ping ¶
func Ping(ctx context.Context, c *peer.Conn, opts PingOptions) (*PingResult, error)
Ping measures round-trip times over the session by echoing small probes on one stream. It measures the path the session really uses, including QUIC's processing on both ends.
type PortMapStatus ¶
type PortMapStatus struct {
Protocol string `json:"protocol"` // PCP, NAT-PMP or UPnP
External string `json:"external"` // the router's public addr:port
// Offered is false when the router is behind another NAT, so its
// address is not given to clients.
Offered bool `json:"offered"`
}
PortMapStatus describes the router port mapping (UPnP, NAT-PMP or PCP).
type Recording ¶
type Recording struct {
Dir string // the host's config directory
Path string // the file, absolute; it is complete and closed
Grant string // the grant the session stood on
Kind string // "terminal" or "exec"
Title string
Exit string // how the session ended, as written into the recording
}
Recording describes a finished session recording (an asciicast v2 file).
type RecordingSink ¶
type RecordingSink func(Recording)
RecordingSink is told about each recording when it is closed.
type RestartError ¶ added in v1.0.12
RestartError is a refused or failed restart: Code is one of the Restart* codes, Message the host's own words (English, cleaned), Hint one of the Hint* names or empty.
func (*RestartError) Error ¶ added in v1.0.12
func (e *RestartError) Error() string
type RestartInfo ¶ added in v1.0.12
type RestartInfo struct {
// OK: the restart is scheduled (restart requests only), DelayMS from
// the answer.
OK bool `json:"ok,omitempty"`
DelayMS int `json:"delay_ms,omitempty"`
// Supported: this host can restart its computer as it runs now; when
// false, Code and Error say why.
Supported bool `json:"supported"`
// Unattended: the host comes back with the computer by itself (a
// system service). False: someone must log in and start the app.
Unattended bool `json:"unattended"`
// Force: open applications will be closed without saving.
Force bool `json:"force,omitempty"`
// Relogin: this session's login still works after the restart (a
// pairing, a key, a fixed password). False for the temporary or
// one-time password, which the host replaces when it starts, and for a
// restart pairing, which its login used up. Pairable: the host would
// give this session a restart pairing now (PairForRestart), so that it
// can log in again, once, after the restart.
Relogin bool `json:"relogin"`
Pairable bool `json:"pairable,omitempty"`
// Boot names the computer's current boot: it changes when the computer
// has restarted (PingInfo.Boot). ID names this restart, as the host's
// last restart outcome does (PingInfo.Restart).
Boot string `json:"boot,omitempty"`
ID string `json:"id,omitempty"`
Code string `json:"code,omitempty"`
Error string `json:"error,omitempty"`
Hint string `json:"hint,omitempty"`
}
RestartInfo is the host's answer to a restart request or query.
func QueryRestart ¶ added in v1.0.12
QueryRestart asks the host on c whether it can restart its computer, and whether it would come back by itself.
func Restart ¶ added in v1.0.12
Restart asks the host on c to restart its computer. allowForce says the user agreed that open applications may be closed without saving (the query said Force); without it a host that would force refuses with RestartChanged. On success the host restarts DelayMS after answering. A refusal is a *RestartError.
type RestartNotice ¶ added in v1.0.12
RestartNotice is what Config.OnRestart learns of a restart the host has accepted: who asked, and when the restart starts.
type RestartOutcome ¶ added in v1.0.12
type RestartOutcome struct {
ID string `json:"id"`
Code string `json:"code"`
Error string `json:"error,omitempty"`
Hint string `json:"hint,omitempty"`
}
RestartOutcome is how the host's last restart went when it did not happen: the controller, logged in again to the same boot, learns why.
type RestartPlan ¶ added in v1.0.12
type RestartPlan struct {
// Force: open applications are closed without saving (Windows, when
// the session is locked: nobody can answer them, and Windows refuses
// a gentle restart then).
Force bool
}
RestartPlan is how a restart would go, for the controller to confirm.
type Restarter ¶ added in v1.0.12
type Restarter interface {
// Check reports whether Restart can work here, as far as can be known
// before trying, and how it would go: a *RestartError (not_permitted,
// unsupported) when it cannot. ctx bounds what it asks the system.
Check(ctx context.Context) (RestartPlan, error)
// Unattended reports whether the host starts again with the computer,
// without anyone logging in: it runs as a system service.
Unattended() bool
// Restart asks the system to restart the computer now, as plan (from
// Check, confirmed by the controller) says. ctx bounds a program that
// may wait for a person (a macOS permission prompt); the restart
// itself is not cancelled with it.
Restart(ctx context.Context, plan RestartPlan) error
}
Restarter restarts the computer a host runs on. The system's is used unless Config.Restarter sets another; tests always set a fake, so that no test can restart a machine.
type Scope ¶
type Scope struct {
// Name is the scope's name, recorded in the session (auth.Result.Scope).
Name string
// Services the session may open.
Services []string
// Admit decides about a key: ok, and a display name for the session.
// It runs during the login handshake and must be quick.
Admit func(h *Host, key ed25519.PublicKey) (name string, ok bool)
}
Scope is a limited kind of login: a key the host's owner never authorised with `remohop authorize`, but that a feature vouches for, may log in and use exactly the listed services, nothing else. Owner approval (`remohop config ask`) does not apply; the feature itself is what the owner switched on.
type Session ¶
type Session struct {
// Auth says how the client authenticated and who it is.
Auth *auth.Result
// Remote is the client's address on the P2P path.
Remote netip.AddrPort
Started time.Time
// contains filtered or unexported fields
}
Session is one authenticated client connection, as seen by host-side service handlers.
func SessionOf ¶
SessionOf returns the host-side session behind c, or nil if c is not a connection accepted by a Host (for example a client-side connection).
func (*Session) Features ¶
Features reports the session's limit: all is true when it has none, else allowed lists the features it may use (the host's policy still applies on top).
func (*Session) Grant ¶
Grant is the name of the grant the session stands on, or "" for a session with full access.
func (*Session) ID ¶
ID numbers the session within its host, from 1 in the order sessions opened; a front end names a session by it (see Host.Disconnect).
type SessionStatus ¶
type SessionStatus struct {
Peer string `json:"peer"` // pairing name or key fingerprint
Device string `json:"device,omitempty"` // the name the client gave itself
Identity string `json:"identity"`
From string `json:"from"`
Path string `json:"path"` // lan, direct, punched, relayed or "relayed (websocket)"
Auth auth.Kind `json:"auth"`
Since time.Time `json:"since"`
// Grant is the grant the session stands on; empty for full access.
Grant string `json:"grant,omitempty"`
// Authorizer names the Authorizer that admitted the session; empty
// for paired and password sessions.
Authorizer string `json:"authorizer,omitempty"`
}
SessionStatus describes one live session.
type Status ¶
type Status struct {
PID int `json:"pid"`
// ID is the 9-digit ID, empty until the first registration.
ID string `json:"id,omitempty"`
// Name is this machine's device name (`remohop config name`).
Name string `json:"name,omitempty"`
// Online reports whether the host is currently connected to the
// rendezvous server.
Online bool `json:"online"`
// Password is the temporary password, formatted; empty when only a
// fixed password is accepted. A fixed password is never reported.
Password string `json:"password,omitempty"`
// PasswordMode is "temporary", "one-time", "fixed" or "fixed+one-time".
PasswordMode string `json:"password_mode"`
// Temporary is true when Password is set.
Temporary bool `json:"temporary_password"`
Listen string `json:"listen"`
Direct []string `json:"direct,omitempty"`
Identity string `json:"identity"`
Signal string `json:"signal,omitempty"`
// Transport is how the host is registered: "udp", or "websocket"
// through the rendezvous server's websocket bridge (clients then
// arrive relayed); empty while offline.
Transport string `json:"transport,omitempty"`
NAT string `json:"nat,omitempty"`
// PortMap is the router port forwarding in force, if any.
PortMap *PortMapStatus `json:"port_map,omitempty"`
// FeaturesOff lists the features the owner has switched off.
FeaturesOff []string `json:"features_off,omitempty"`
// TOTP is true when password logins need a code from an
// authenticator app as well (`remohop config totp`).
TOTP bool `json:"totp,omitempty"`
// Ask is "off", "on" (password logins need approval) or "all"
// (paired clients too).
Ask string `json:"ask"`
Pending int `json:"pending_approvals"`
Sessions int `json:"sessions"`
Clients []SessionStatus `json:"clients,omitempty"`
Started time.Time `json:"started"`
// Version is the program's version (cli.Version); hosts before
// v1.0.11 leave it out. The desktop app restarts a background
// service that runs another version of its own program file.
Version string `json:"version,omitempty"`
}
Status describes a host process.
func LiveStatus ¶
LiveStatus asks the host running on dir for its current status. It returns (nil, nil) when none is running.
func ReadStatus ¶
ReadStatus returns the status of the host running on dir's identity, or (nil, nil) if none is running. A file left behind by a host that died is removed.
type TOTPSetup ¶ added in v1.0.12
type TOTPSetup struct {
// URI is the otpauth:// URI the app scans; Secret the same secret in
// base32 for typing; QR the URI's QR code as rows of '1' and '0'.
URI string
Secret string
QR []string
// contains filtered or unexported fields
}
TOTPSetup is a secret being set up: shown to the owner, saved only once they have typed a code from their app (Confirm).
func NewTOTPSetup ¶ added in v1.0.12
NewTOTPSetup starts setting the check up for the config directory dir. Nothing is saved yet.
Source Files
¶
- approve.go
- audit.go
- authorizer.go
- boot_linux.go
- cmd.go
- cmd_admin.go
- control.go
- control_unix.go
- device.go
- embed.go
- extend.go
- gate.go
- grants.go
- grants_cmd.go
- hostd.go
- idmemory.go
- limits.go
- notify.go
- policy.go
- proc_unix.go
- restart.go
- restart_linux.go
- restart_plan.go
- restart_unix.go
- revoke.go
- services.go
- sessionlimit.go
- signalext.go
- sinks.go
- status.go
- totp.go