Help us shape the future of Go! Take the 2026 Go Developer Survey

ssh

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

SSH host entries parse from a pasted ssh command restricted to connection options and allowlisted directives, and render to one OpenSSH stanza. The parsed value is both the wire shape and the stored payload. An SSH host's only credential is the stored key its keyId names, so the command takes no -i and no identity option; the key's path is supplied at render time and never stored or returned.

SSH key handling validates names and private-key material before writing metadata and protected bytes. A staged filename binds an interrupted write to committed metadata so startup can promote or discard it without reading key contents. API responses expose only public metadata; deletion also clears SSH host references and rerenders config.

SSH host persistence coordinates SQL metadata with rendered per-principal config and protected key files. SSH host and key tables remain private to this subsystem; a process-wide database lock encloses each compensated flow, and only its metadata mutation runs in a transaction. Queries in query.sql are generated into query.sql.go by sqlc. The real OpenSSH config is never read or changed.

Package ssh owns principal-scoped SSH hosts, keys, rendered configuration, live probes, and authentication. The database stores SSH host and key metadata while private keys and generated configs remain protected files. SSH host and key mutations coordinate database, config, and file effects as compensated flows; OpenSSH execution and control-master mechanics remain in internal/ssh. Health only opens a TCP connection to the first hop, and only to public addresses, so it cannot probe cs-plane's own network.

Index

Constants

This section is empty.

Variables

View Source
var Schema string

Functions

func SubprotocolAuthRoute added in v0.4.2

func SubprotocolAuthRoute(request *http.Request) bool

SubprotocolAuthRoute reports the SSH authentication WebSocket, whose browser client offers its bearer as a subprotocol.

Types

type AddHostRequest

type AddHostRequest struct {
	Alias   string `json:"alias"`
	Command string `json:"command"`
	Key     string `json:"keyId"`
}

type DBTX

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

type DeleteHostParams

type DeleteHostParams struct {
	Principal string
	Host      string
}

type DeleteKeyParams

type DeleteKeyParams struct {
	Principal string
	Name      string
}

type GetKeyParams

type GetKeyParams struct {
	Principal string
	Name      string
}

type GetKeyRow

type GetKeyRow struct {
	Name        string
	Type        string
	Fingerprint string
}

type HostEntry

type HostEntry struct {
	Alias           string   `json:"alias"`
	Hostname        string   `json:"hostname,omitempty"`
	User            string   `json:"user,omitempty"`
	Port            int      `json:"port,omitempty"`
	Key             string   `json:"keyId,omitempty"`
	ExtraDirectives []string `json:"extraDirectives"`
	Managed         bool     `json:"managed"`
}

type HostHealth

type HostHealth struct {
	Alias   string `json:"alias"`
	OK      bool   `json:"ok"`
	Message string `json:"message"`
}

type HostList

type HostList struct {
	Hosts []HostEntry `json:"hosts"`
}

type InsertHostParams

type InsertHostParams struct {
	Principal string
	Host      string
	Payload   string
}

type InsertKeyParams

type InsertKeyParams struct {
	Principal   string
	Name        string
	Type        string
	Fingerprint string
}

type ListHostsRow

type ListHostsRow struct {
	Host    string
	Payload string
}

type ListKeysRow

type ListKeysRow struct {
	Name        string
	Type        string
	Fingerprint string
}

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db DBTX) *Queries

func (*Queries) DeleteHost

func (q *Queries) DeleteHost(ctx context.Context, arg DeleteHostParams) (int64, error)

func (*Queries) DeleteKey

func (q *Queries) DeleteKey(ctx context.Context, arg DeleteKeyParams) (int64, error)

func (*Queries) GetKey

func (q *Queries) GetKey(ctx context.Context, arg GetKeyParams) (GetKeyRow, error)

func (*Queries) InsertHost

func (q *Queries) InsertHost(ctx context.Context, arg InsertHostParams) error

func (*Queries) InsertKey

func (q *Queries) InsertKey(ctx context.Context, arg InsertKeyParams) error

func (*Queries) ListHostPrincipals

func (q *Queries) ListHostPrincipals(ctx context.Context) ([]string, error)

func (*Queries) ListHosts

func (q *Queries) ListHosts(ctx context.Context, principal string) ([]ListHostsRow, error)

func (*Queries) ListKeys

func (q *Queries) ListKeys(ctx context.Context, principal string) ([]ListKeysRow, error)

func (*Queries) UpdateHost

func (q *Queries) UpdateHost(ctx context.Context, arg UpdateHostParams) (int64, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx *sql.Tx) *Queries

type SSHKey

type SSHKey struct {
	Name        string `json:"id"`
	Type        string `json:"type"`
	Fingerprint string `json:"fingerprint"`
}

type SSHKeyList

type SSHKeyList struct {
	Keys []SSHKey `json:"keys"`
}

type SSHKeyRequest

type SSHKeyRequest struct {
	Name       string `json:"id"`
	PrivateKey string `json:"privateKey"`
}

type Service

type Service struct {
	Store   Store
	Configs internalssh.Configurations
	Control *internalssh.ControlManager
}

func NewService

func NewService(database *db.DB, configs internalssh.Configurations, control *internalssh.ControlManager) (*Service, error)

func (Service) Routes

func (s Service) Routes() router.Routes

type Store

type Store struct {
	Database     *db.DB
	PrincipalDir string
}

type UpdateHostParams

type UpdateHostParams struct {
	Payload   string
	Principal string
	Host      string
}

type UpdateHostRequest

type UpdateHostRequest struct {
	Command string `json:"command"`
	Key     string `json:"keyId"`
}

Jump to

Keyboard shortcuts

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