remote

package
v0.68.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 35 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 remote serves the daemon's API to other devices on the tailnet: the listener setting, device tokens and their scopes, the check every remote call passes, and the launchd or systemd service that keeps the daemon up.

Index

Constants

View Source
const (
	ServiceLabel = "io.github.amberpixels.f10.daemon"
	ServiceUnit  = "f10-daemon.service"
)

ServiceLabel names the launchd agent; ServiceUnit the systemd user unit.

View Source
const DefaultPort = 7410

DefaultPort is the listener's port when the setting names none.

View Source
const MCPPath = "/mcp"

MCPPath is where the listener serves the API as MCP tools while the setting has MCP on.

Variables

View Source
var ErrNoService = errors.New("f10 remote install supports macOS (launchd) and Linux (systemd)")

ErrNoService is a platform with neither launchd nor systemd.

Scopes is every scope, in the order help lists them.

View Source
var ServiceEnv = []string{"PATH", "HOME", "F10_RUN_DIR", "XDG_RUNTIME_DIR", "F10_USER_DIR"}

ServiceEnv is the environment the service carries from the shell that installed it: launchd starts a process with almost none, and without these the daemon would land in another run dir and find none of the user's tools.

Functions

func Allows

func Allows(scopes []Scope) func(procedure string) bool

Allows reports whether scopes reach a procedure as an operation: placed in the table under one of them. Socket-only procedures and those any token may call (Hello) are plumbing, so never allowed here.

func Auth

func Auth(store *Store, next http.Handler) http.Handler

Auth refuses every remote call that does not carry a valid token with the scope its procedure needs, before any handler runs. It writes Connect errors, so a Connect client reads the refusal as one.

func Dir

func Dir() (string, error)

Dir holds the setting and the tokens. It lives in the user's f10 dir, not the run dir, because the run dir may be a tmpfs a reboot empties.

func InTailnet

func InTailnet(ip netip.Addr) bool

InTailnet reports an address Tailscale could have assigned.

func Procedures

func Procedures(tok Token) []string

Procedures is every procedure tok may call on the tailnet, sorted, so a client hides what it cannot call without a scope table of its own.

func Route

func Route(api, app http.Handler) http.Handler

Route sends every Connect procedure to api, a GET or HEAD of anything else to app, and refuses the rest.

func ScopeList

func ScopeList() string

ScopeList is the scope names joined for a message.

func TailnetAddr

func TailnetAddr(ifaces func() ([]Iface, error)) (netip.Addr, bool)

TailnetAddr is this machine's Tailscale IPv4 address, read from its interfaces, so no tailscale CLI is needed; false when Tailscale is down.

func WriteConfig

func WriteConfig(dir string, c Config) error

WriteConfig replaces the setting in dir.

Types

type Certs

type Certs struct {
	Dir  string
	Run  Runner           // exec by default
	CLI  func() string    // the tailscale CLI's path, "" for none
	Now  func() time.Time // time.Now by default
	Wait bool             // fetch in the caller, for tests
	// contains filtered or unexported fields
}

Certs is the machine's Tailscale HTTPS certificate, fetched with the tailscale CLI into Dir and renewed in the background before it expires.

func (*Certs) Config

func (c *Certs) Config() (*tls.Config, string, string)

Config is the TLS config to serve with and the host its certificate names. With no usable certificate the config is nil and why says what is missing; a fetch then runs in the background, at most once an hour.

type Config

type Config struct {
	Enabled bool `json:"enabled"`
	Port    int  `json:"port,omitempty"`
	// MCP serves the API as MCP tools at MCPPath on the listener.
	MCP bool `json:"mcp,omitempty"`
}

A Config is the listener setting: off unless enabled.

func ReadConfig

func ReadConfig(dir string) (Config, error)

ReadConfig is the setting in dir; a missing file reads as off.

func (Config) ListenPort

func (c Config) ListenPort() int

ListenPort is the port the listener binds.

type Iface

type Iface struct {
	Name  string
	Addrs []net.Addr
}

An Iface is one network interface that is up, with its addresses.

func Interfaces

func Interfaces() ([]Iface, error)

Interfaces lists the machine's interfaces that are up.

type Listener

type Listener struct {
	Dir    string                  // the setting's and the tokens' dir
	Ifaces func() ([]Iface, error) // the machine's interfaces; Interfaces by default
	Peer   func(netip.Addr) bool   // the peers accepted; InTailnet by default
	App    http.Handler            // the web client's files, nil for none
	Certs  *Certs                  // the HTTPS certificate, nil for plain HTTP
	// Version is the daemon's release, reported to MCP clients.
	Version string
	// contains filtered or unexported fields
}

A Listener is what the daemon asks of the tailnet listener: where to bind, which peers to accept, and the check in front of the API.

func (*Listener) Addr

func (l *Listener) Addr() (string, bool, string)

Addr is the address to bind and whether the setting is on; with no address, the third value says why none is wanted or none can be bound.

func (*Listener) Handler

func (l *Listener) Handler(h http.Handler) http.Handler

Handler puts the token check in front of h, and serves the web client's files beside it without one: they hold no data, and the page that asks for the token must load before it has one. While the setting has MCP on, it also serves MCPPath, each request's tools built from its own token.

func (*Listener) Listen

func (l *Listener) Listen(ln net.Listener) net.Listener

Listen wraps ln so only allowed peers reach the API.

func (*Listener) TLS

func (l *Listener) TLS() (*tls.Config, string, string)

TLS is the HTTPS config from Certs; with none, the listener serves plain HTTP and why says so.

type Runner

type Runner func(ctx context.Context, name string, args ...string) ([]byte, error)

Runner runs a command and returns its stdout.

type Scope

type Scope string

A Scope is what a token lets a device do.

const (
	ScopeRead   Scope = "read"   // status, board, tasks, events, asks and agents
	ScopeAnswer Scope = "answer" // answer an ask
	ScopeSteer  Scope = "steer"  // send text to an agent
	ScopeStart  Scope = "start"  // start, drive or cancel one, create a task
	ScopeFinish Scope = "finish" // finish a task, close its workspace
)

The scopes a token can carry.

func ParseScopes

func ParseScopes(values []string) ([]Scope, error)

ParseScopes reads `--scope` values, each one name or a comma list.

type Service

type Service struct {
	GOOS    string
	Home    string
	UID     int
	Program string   // the f10 the service runs
	Env     []string // KEY=VALUE pairs it carries
	Log     string   // where its output goes
	// Run runs launchctl or systemctl.
	Run func(ctx context.Context, name string, args ...string) error
	// Drain hands the running daemon's drives to the next one before the
	// service restarts, so reinstalling never drops them; nil skips it.
	Drain func(ctx context.Context) error
}

A Service is the daemon's launchd agent or systemd user unit.

func (*Service) Describe

func (s *Service) Describe() string

Describe is the service's state in one line, for install's report.

func (*Service) Install

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

Install writes the service file and loads it, replacing a loaded one.

func (*Service) InstalledProgram

func (s *Service) InstalledProgram() (string, bool)

InstalledProgram is the program an installed service file runs; "" when the file is missing or names none.

func (*Service) Path

func (s *Service) Path() (string, error)

Path is the service file.

func (*Service) Render

func (s *Service) Render() (string, error)

Render is the service file's text.

func (*Service) Supported

func (s *Service) Supported() bool

Supported reports a platform with a service manager f10 installs into.

func (*Service) Uninstall

func (s *Service) Uninstall(ctx context.Context) (bool, error)

Uninstall unloads the service and removes its file; false when none was installed.

type Store

type Store struct {
	Path string
	// contains filtered or unexported fields
}

A Store is the tokens file. Verify rereads it only when it changed, so a revoke takes effect on the next call without a restart.

func NewStore

func NewStore(dir string) *Store

NewStore is the tokens file in dir.

func (*Store) Add

func (s *Store) Add(name string, scopes []Scope, now time.Time) (string, error)

Add issues a token for name with scopes and returns its secret, which is shown once and never stored.

func (*Store) List

func (s *Store) List() ([]Token, error)

List is every token, in the order they were added.

func (*Store) Revoke

func (s *Store) Revoke(name string) (bool, error)

Revoke deletes the token named name; false when none is.

func (*Store) Verify

func (s *Store) Verify(secret string) (Token, bool)

Verify is the token whose secret this is; false for none, and for a file that does not read, so a broken file refuses every call.

type Token

type Token struct {
	Name    string    `json:"name"`
	Hash    string    `json:"hash"`
	Scopes  []Scope   `json:"scopes"`
	Created time.Time `json:"created"`
}

A Token is one device's access: its name, the hash of its secret and the scopes it carries. The secret itself is never stored.

func (Token) Has

func (t Token) Has(scope Scope) bool

Has reports whether the token carries scope.

Jump to

Keyboard shortcuts

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