Documentation
¶
Overview ¶
Package web is the `sshmgr serve` command's localhost web UI.
Server-rendered html/template pages over the same services the CLI and the TUI call, with a little vanilla JavaScript and Tabler's CSS, all embedded in the binary: the page makes no network request beyond this server. It never imports internal/cli, which holds the TUI and process-wide state a long-lived server cannot share (imports_test.go holds it to that).
Reading takes no lock. A change takes it only while it is checked and made (see services/change), never while a person reads its preview, so a running server does not hold up a CLI command.
Index ¶
- Constants
- Variables
- func AllowedHosts(bindHost string, port int, extra []string) []string
- func IsAddrInUse(err error) bool
- func IsLoopback(host string) bool
- func Listen(listen ListenFunc, host string, port int, pinned bool, attempts int) (net.Listener, error)
- func NewToken() string
- type AppEngine
- func (e AppEngine) Apply(ch change.Change, hash string) (change.Plan, change.Result, error)
- func (e AppEngine) Audit(now time.Time) (AuditView, error)
- func (e AppEngine) Bundles() ([]BundleView, error)
- func (e AppEngine) Doctor() (doctor.Report, error)
- func (e AppEngine) Export(name string, includeGit bool) (string, error)
- func (e AppEngine) History(f history.Filter) ([]history.Op, error)
- func (e AppEngine) Home() paths.Paths
- func (e AppEngine) Host(alias string) (HostView, error)
- func (e AppEngine) Hosts() ([]query.ProfileGroup, error)
- func (e AppEngine) Key(ref string) (KeyView, error)
- func (e AppEngine) Keys() ([]keysvc.Row, error)
- func (e AppEngine) Op(id string) (OpView, error)
- func (e AppEngine) Overview(now time.Time) (Overview, error)
- func (e AppEngine) Preview(ch change.Change) (change.Plan, error)
- func (e AppEngine) Profiles() ([]ProfileView, error)
- func (e AppEngine) SnapshotDiff(id, against string) (SnapshotDiff, error)
- func (e AppEngine) Snapshots() ([]SnapshotView, error)
- func (e AppEngine) Tokens() (TokensView, error)
- type AuditKey
- type AuditView
- type BundleView
- type Engine
- type FileDiff
- type HostView
- type KeyView
- type ListenFunc
- type OpView
- type Options
- type Overview
- type ProfileView
- type Server
- type SnapshotDiff
- type SnapshotView
- type TokensView
Constants ¶
const ( ExportFlat = "ssh_config" ExportTermius = "termius-hosts.csv" )
Exports a page can download. Each is rendered the way `sshmgr config export --flat` and `sshmgr termius export` render it, and none is written anywhere.
const ContentSecurityPolicy = "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; " +
"connect-src 'self'; font-src 'self'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'"
ContentSecurityPolicy is sent on every response. Everything is same-origin; nothing is inline. img-src allows data: because Tabler's CSS draws its checkboxes and selects with data: SVG URLs.
const DefaultPort = 7822
DefaultPort is where serve listens unless told otherwise.
const DefaultPortAttempts = 20
DefaultPortAttempts bounds how far past a taken default port Listen looks.
const SessionCookie = "authama_session"
SessionCookie is the cookie a valid token is exchanged for.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is a name that matches nothing in the manifest, the snapshots or the history. Handlers turn it into a 404.
Functions ¶
func AllowedHosts ¶
AllowedHosts is the set of Host header values the server answers to.
For a loopback bind that is the three spellings of this machine at the bound port. Anything else is refused, which is the DNS-rebinding defence: a page on evil.example that rebinds its name to 127.0.0.1 still sends Host: evil.example. With a remote bind the bound host and any explicitly allowed names are added.
func IsAddrInUse ¶
IsAddrInUse reports whether a listen error means the port is taken.
func IsLoopback ¶
IsLoopback reports whether host only accepts connections from this machine: localhost, or an address in 127.0.0.0/8 or ::1.
func Listen ¶
func Listen(listen ListenFunc, host string, port int, pinned bool, attempts int) (net.Listener, error)
Listen binds host:port.
When pinned is false and the port is in use, it tries the next port up, up to attempts ports in all, and returns the first that binds: the default port being taken by another process is ordinary, and the caller prints the URL actually bound. When pinned is true -- the user asked for this port -- a taken port is an error, because silently serving elsewhere would leave whatever they pointed at this port talking to something else. Any error other than "address in use" stops the search at once.
Types ¶
type AppEngine ¶
type AppEngine struct {
P paths.Paths
// Retain is how many snapshots a change keeps, as the CLI's
// $AUTHAMA_SNAPSHOT_RETAIN; zero means 10.
Retain int
}
AppEngine reads one sshmgr home through the same services the CLI uses. It loads the manifest and inventory on every call: the CLI may change them at any moment, and a page must show what is there now.
func (AppEngine) Bundles ¶
func (e AppEngine) Bundles() ([]BundleView, error)
Bundles lists the bundles in dist/, newest first.
func (AppEngine) History ¶
History reads the operation history without writing to it: a page view must not create the database or run the first import.
func (AppEngine) Hosts ¶
func (e AppEngine) Hosts() ([]query.ProfileGroup, error)
Hosts lists every host, grouped by profile, as `sshmgr list` does.
func (AppEngine) Overview ¶
Overview reads the banner's rows through overview.Rows, the same function the TUI prints, so the two never disagree.
func (AppEngine) Profiles ¶
func (e AppEngine) Profiles() ([]ProfileView, error)
Profiles lists every profile with its counts.
func (AppEngine) SnapshotDiff ¶
func (e AppEngine) SnapshotDiff(id, against string) (SnapshotDiff, error)
SnapshotDiff compares snapshot id with another snapshot, or with ~/.ssh as it is now when against is "". A snapshot holding key material is refused, not opened: showing a diff would put the key on the page.
func (AppEngine) Snapshots ¶
func (e AppEngine) Snapshots() ([]SnapshotView, error)
Snapshots lists the snapshots, newest first.
func (AppEngine) Tokens ¶
func (e AppEngine) Tokens() (TokensView, error)
Tokens is `authama token list` and `authama token audit` as data. The secrets never leave the service: Inventory is asked not to reveal them, and the view drops them again in case it ever does.
type AuditKey ¶
type AuditKey struct {
Path, Fingerprint, Status string
Deployments []inventory.Deployment
}
AuditKey is one inventory record and where it is deployed.
type BundleView ¶
BundleView is one encrypted bundle in the config home's dist/.
type Engine ¶
type Engine interface {
Home() paths.Paths
Overview(now time.Time) (Overview, error)
Profiles() ([]ProfileView, error)
Hosts() ([]query.ProfileGroup, error)
Host(alias string) (HostView, error)
Keys() ([]keysvc.Row, error)
Key(ref string) (KeyView, error)
Snapshots() ([]SnapshotView, error)
Bundles() ([]BundleView, error)
SnapshotDiff(id, against string) (SnapshotDiff, error)
History(f history.Filter) ([]history.Op, error)
Op(id string) (OpView, error)
Doctor() (doctor.Report, error)
Audit(now time.Time) (AuditView, error)
Export(name string, includeGit bool) (string, error)
Tokens() (TokensView, error)
// Preview runs a change on a private copy of the home; Apply makes it
// if a fresh preview under the lock still has the confirmed hash.
Preview(ch change.Change) (change.Plan, error)
Apply(ch change.Change, hash string) (change.Plan, change.Result, error)
}
Engine is everything the pages read. Every argument is a name - a profile, a host alias, a key, a snapshot id, an operation id - resolved here against what exists, never a filesystem path. AppEngine is the real one; tests pass their own.
type FileDiff ¶
type FileDiff struct {
Path string
State string // added | removed | changed
Lines []history.DiffLine
}
FileDiff is one file's change.
type HostView ¶
type HostView struct {
Detail *query.HostDetail
Block string
Pins []knownhosts.Entry
Token string
VM bool // a VM host, which can have a Docker context
}
HostView is one host: the manifest entry and what it resolves to.
type ListenFunc ¶
ListenFunc is net.Listen's signature, injectable so the port fallback can be tested without binding a socket.
type Options ¶
type Options struct {
// Engine reads the sshmgr home. Required.
Engine Engine
// Token is the launch token printed in the URL. Required.
Token string
// AllowedHosts are the Host header values answered (see AllowedHosts).
AllowedHosts []string
// AllowRemote records that the bind is not loopback; it lets a TLS
// reverse proxy's X-Forwarded-Proto mark the session cookie Secure.
AllowRemote bool
// ReadOnly registers no route that changes anything, and hides the forms.
ReadOnly bool
// Version and BindAddr are shown in the footer.
Version string
BindAddr string
// Retain is how many snapshots a snapshot restore keeps when it snapshots
// first, as AUTHAMA_SNAPSHOT_RETAIN sets for the CLI. 0 means 10.
Retain int
// Now is the clock. Nil means time.Now.
Now func() time.Time
}
Options configures a Server.
type Overview ¶
type Overview struct {
Rows []overview.Row
Problems int
Profiles int
Hosts int
Keys int
Expiry []expiry.Status
Recent []history.Op
DevRoot string
}
Overview is the first page: the banner's rows, and the counts behind them.
type ProfileView ¶
ProfileView is one profile in the profiles list.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the web UI.
func New ¶
New builds a Server. It parses every template once, so a template error is a startup error rather than a 500 on first visit.
type SnapshotDiff ¶
type SnapshotDiff struct {
ID, Against string // Against "" means the current ~/.ssh
Files []FileDiff
Refused string // why the snapshot was not opened
}
SnapshotDiff compares a snapshot with the tree now, or with another snapshot.
type SnapshotView ¶
SnapshotView is one snapshot in the list.
type TokensView ¶
type TokensView struct {
Items []tokens.Installed
Findings []tokensvc.Finding
Failed bool
Config string // the token config `token apply` would read, or "" for the built-in default
Legacy bool
}
TokensView is the token page: what is installed, secrets masked, and the checkup of the files that hold it.