host

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 37 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AdminSockExt = ".sock"
)

Variables

This section is empty.

Functions

func AdminClient

func AdminClient(socket string) (api.AdminServiceClient, error)

func AdminSocketFile

func AdminSocketFile(sessionID string) string

func NewAutoAcceptingHostKeyCallback added in v0.19.0

func NewAutoAcceptingHostKeyCallback(stdout io.Writer, knownHostsFilename string) (ssh.HostKeyCallback, error)

NewAutoAcceptingHostKeyCallback creates a host key callback that automatically accepts unknown host keys and adds them to the known_hosts file without prompting. This is similar to SSH's StrictHostKeyChecking=accept-new behavior: - Unknown host keys are automatically accepted and added to known_hosts - Known host keys are still validated (preventing MITM attacks on subsequent connections)

func NewPromptingHostKeyCallback

func NewPromptingHostKeyCallback(stdin io.Reader, stdout io.Writer, knownHostsFilename string) (ssh.HostKeyCallback, error)

func ProviderList added in v0.27.0

func ProviderList() string

ProviderList names every supported provider and marks the ones that need an explicit host. It is the single source for both parse errors and the --authorized-user flag's help text, so the two cannot drift apart.

func Signers

func Signers(privateKeys []string) ([]ssh.Signer, func(), error)

Signers return signers based on the following conditions: If SSH agent is running and has keys, it returns signers from SSH agent, otherwise return signers from private keys; If neither works, it generates a signer on the fly.

func SignersFromFiles

func SignersFromFiles(privateKeys []string) ([]ssh.Signer, error)

Types

type AuthorizedKey added in v0.13.0

type AuthorizedKey struct {
	PublicKeys []ssh.PublicKey
	Comment    string
}

func AuthorizedKeysFromFile added in v0.13.0

func AuthorizedKeysFromFile(file string) (*AuthorizedKey, error)

func AuthorizedKeysFromUserRefs added in v0.27.0

func AuthorizedKeysFromUserRefs(ctx context.Context, refs []UserRef, logger *slog.Logger) ([]*AuthorizedKey, error)

AuthorizedKeysFromUserRefs resolves refs using a default Fetcher.

type CredentialMode added in v0.27.0

type CredentialMode int

CredentialMode describes how a reference selects an authentication token.

const (
	// CredentialNone never sends a credential. Every provider but GitHub.
	CredentialNone CredentialMode = iota
	// CredentialDefault defers to go-gh's own host and token resolution,
	// preserving GH_HOST and the enterprise environment variables. Used when a
	// GitHub reference names no explicit host.
	CredentialDefault
	// CredentialHostScoped uses only credentials stored for the named host.
	// GH_ENTERPRISE_TOKEN and GITHUB_ENTERPRISE_TOKEN are not host-scoped, so
	// honoring them here would send one instance's token to another.
	CredentialHostScoped
)

type Fetcher added in v0.27.0

type Fetcher struct {
	Logger *slog.Logger
	// Transport, when set, is the base round tripper for every request. Tests
	// use it to trust httptest certificates; production leaves it nil.
	Transport http.RoundTripper
}

Fetcher resolves user references to authorized keys.

func (*Fetcher) AuthorizedKeys added in v0.27.0

func (f *Fetcher) AuthorizedKeys(ctx context.Context, refs []UserRef) ([]*AuthorizedKey, error)

AuthorizedKeys fetches every reference, reporting all failures together. Any failure fails the whole call: continuing with a partial set can, in the limit, degrade "only alice may join" into "anyone may join".

type Host

type Host struct {
	Host                           string
	KeepAliveDuration              time.Duration
	Command                        []string
	ForceCommand                   []string
	Signers                        []ssh.Signer
	HostKeyCallback                ssh.HostKeyCallback
	AuthorizedKeys                 []*AuthorizedKey
	AdminSocketFile                string
	SessionCreatedCallback         func(context.Context, *api.GetSessionResponse) error
	ClientJoinedCallback           func(*api.Client)
	ClientLeftCallback             func(*api.Client)
	Logger                         *slog.Logger
	Stdin                          *os.File
	Stdout                         *os.File
	ReadOnly                       bool
	AllowLocalTCPForwarding        bool
	ForceForwardingInputForTesting bool

	// SFTP configuration
	SFTPDisabled          bool                   // Disable SFTP subsystem entirely (--no-sftp)
	SFTPPermissionChecker sftp.PermissionChecker // Optional: prompts user for SFTP permissions (nil = auto-allow)
}

func (*Host) Run

func (c *Host) Run(ctx context.Context) error

type UserRef added in v0.27.0

type UserRef struct {
	Provider string // "" for the raw-URL form
	User     string
	Host     string // host[:port] as written; "" means "provider default"
	URL      string // raw-URL form only: the complete .keys URL
	Raw      string // the original string, for error messages
	Mode     CredentialMode
}

UserRef is one parsed --authorized-user value.

func ParseUserRef added in v0.27.0

func ParseUserRef(s string) (UserRef, error)

ParseUserRef parses a reference of the form provider:user, provider:user@host, or an https:// URL. It performs no I/O.

func (UserRef) Display added in v0.27.0

func (r UserRef) Display() string

Display is the resolved identity used as AuthorizedKey.Comment. It names the host actually contacted, which the verbatim input does not when GH_HOST is in play.

func (UserRef) KeysURL added in v0.27.0

func (r UserRef) KeysURL() string

KeysURL returns the endpoint serving this user's authorized_keys body.

func (UserRef) ResolveHost added in v0.27.0

func (r UserRef) ResolveHost() string

ResolveHost returns the host[:port] this reference targets.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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