auth

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package auth diagnoses and repairs how repositories authenticate against their remotes: SSH key checks, known hosts, stored credentials and remote URL rewrites.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddKnownHost

func AddKnownHost(ctx context.Context, env []string, u model.RemoteURL) error

AddKnownHost appends the host's keys to known_hosts.

func AddSSHConfigHost added in v0.1.12

func AddSSHConfigHost(host, keyPath, port string) error

AddSSHConfigHost appends a Host block to ~/.ssh/config that makes ssh use keyPath for host, for every repository on this machine and regardless of any per-repository pin (IdentitiesOnly keeps command-line -i keys and config IdentityFile entries both in play). It refuses to touch a host that already has a block.

func AgentKeys

func AgentKeys(ctx context.Context, env []string) (keys []string, running bool)

AgentKeys returns the fingerprints the running ssh-agent holds.

func CopyToClipboard

func CopyToClipboard(text string) error

CopyToClipboard puts text on the system clipboard.

func KeyFromSSHCommand added in v0.1.3

func KeyFromSSHCommand(cmd string) string

KeyFromSSHCommand returns the -i key path inside a core.sshCommand value.

func KnownHost added in v0.1.3

func KnownHost(host string) bool

KnownHost reports whether known_hosts has an entry for the host. Hashed entries cannot be matched by name, so ssh-keygen -F is used.

func OpenURL

func OpenURL(url string) error

OpenURL opens a URL in the default browser.

func SSHConfigHost added in v0.1.12

func SSHConfigHost(host string) string

SSHConfigHost returns the Host block in ~/.ssh/config whose pattern list names host exactly, or "" when there is none. Wildcard patterns are not matched; they are left for the user to judge.

func SSHConfigPath added in v0.1.12

func SSHConfigPath() string

SSHConfigPath is the user's ssh client configuration file.

func SSHDir

func SSHDir() string

SSHDir returns the user's ssh directory.

func SplitArgs added in v0.1.3

func SplitArgs(s string) []string

SplitArgs splits a command line on whitespace, honouring double quotes.

Types

type Diagnosis added in v0.1.11

type Diagnosis struct {
	// Summary is one or two sentences naming the cause.
	Summary string
	// Why lists supporting facts: what else worked, why a shell behaves
	// differently, what other repositories on this machine do.
	Why []string
	// Fixes lists remediations, most likely first. Each is a short
	// imperative matching an action in the auth doctor or remotes screen.
	Fixes []string
	// SSHPeers is how many other repositories reach the same host over
	// SSH successfully; it drives the "switch to SSH" recommendation.
	SSHPeers int
}

Diagnosis explains, in plain language, why one remote cannot be reached and what would fix it.

func Diagnose added in v0.1.11

func Diagnose(r *model.Repo, rm *model.Remote, peers []*model.Repo) Diagnosis

Diagnose explains the last fetch outcome of one remote. peers is every repository on this machine, used to spot a transport that already works for the same host. It returns a zero Diagnosis when the remote fetched fine or was never fetched.

type Doctor

type Doctor struct {
	In *gitx.Inspector
}

Doctor performs auth operations using the git runner.

func (*Doctor) Apply

func (d *Doctor) Apply(ctx context.Context, plans []RewritePlan, timeout time.Duration, progress func(i int, p RewritePlan, ok bool, msg string)) (applied, failed int)

Apply verifies each target URL with ls-remote, then rewrites the remote. Repos whose target cannot be reached are left untouched.

func (*Doctor) StoreEmbedded

func (d *Doctor) StoreEmbedded(ctx context.Context, r *model.Repo, remote string) error

StoreEmbedded moves credentials embedded in a remote URL into the credential helper. The real URL is re-read from git config because the in-memory model only ever holds a redacted copy.

type Key

type Key struct {
	Path    string // private key path
	PubPath string
	Type    string
	Comment string
	Public  string
}

Key is a public key found in ~/.ssh.

func GenerateKey

func GenerateKey(ctx context.Context, env []string, name, comment string) (Key, error)

GenerateKey creates a new ed25519 key pair without a passphrase prompt.

func Keys

func Keys() []Key

Keys lists key pairs in ~/.ssh.

type RemoteFilter added in v0.1.11

type RemoteFilter func(r *model.Repo, rm model.Remote) bool

RemoteFilter selects which remotes a rewrite plan covers. A nil filter means every remote of every repository.

func OnlyHost added in v0.1.11

func OnlyHost(host string) RemoteFilter

OnlyHost selects remotes on one host, so a bulk rewrite never touches a repository's other remotes on other hosts.

func OnlyRemote added in v0.1.11

func OnlyRemote(name string) RemoteFilter

OnlyRemote selects one named remote.

type RewritePlan

type RewritePlan struct {
	Repo   *model.Repo
	Remote string
	From   string
	To     string
	Err    error
}

RewritePlan is a proposed remote change on one repo.

func PlanStrip

func PlanStrip(repos []*model.Repo) []RewritePlan

PlanStrip builds rewrites that remove embedded credentials.

func PlanToHTTPS

func PlanToHTTPS(repos []*model.Repo, only RemoteFilter) []RewritePlan

PlanToHTTPS builds SSH-to-HTTPS rewrites for the selected remotes.

func PlanToSSH

func PlanToSSH(repos []*model.Repo, opts giturl.ConvertOptions, only RemoteFilter) []RewritePlan

PlanToSSH builds HTTPS-to-SSH rewrites for the selected remotes.

type SSHCheck added in v0.1.12

type SSHCheck struct {
	Pinned   string     // key path from core.sshCommand, or ""
	Res      SSHResult  // the test git would make (pin honoured)
	Unpinned *SSHResult // the retry without the pin, when one was made
}

SSHCheck is an SSH login test that, when the repository pins a key and the host refuses it, tries again without the pin so the user learns whether the pin itself is the problem.

func CheckSSH added in v0.1.12

func CheckSSH(ctx context.Context, env []string, u model.RemoteURL, sshCommand string) SSHCheck

CheckSSH runs TestSSH with the repository's ssh command and, on failure with a pinned key, once more with ssh's own key selection.

func (SSHCheck) Explain added in v0.1.12

func (c SSHCheck) Explain(u model.RemoteURL) []string

Explain describes a pin that blocks a host, in plain language, with the remedies in order of preference. Empty when the pin is not the problem.

func (SSHCheck) OK added in v0.1.12

func (c SSHCheck) OK() bool

OK reports whether the login git would make succeeds.

func (SSHCheck) PinBlocks added in v0.1.12

func (c SSHCheck) PinBlocks() bool

PinBlocks reports whether the host refused the pinned key but accepts one of the keys ssh picks on its own.

func (SSHCheck) WorkingKey added in v0.1.12

func (c SSHCheck) WorkingKey() string

WorkingKey is the key the host accepted without the pin, or "".

type SSHResult

type SSHResult struct {
	OK         bool
	Class      model.ErrorClass
	Message    string
	KeyUsed    string
	Offered    []string
	Greeting   string
	Transcript string
}

SSHResult is the outcome of an SSH login test.

func TestSSH

func TestSSH(ctx context.Context, env []string, u model.RemoteURL, sshCommand string) SSHResult

TestSSH tries a non-interactive login to the host as the git user. sshCommand, when non-empty, is the repository's core.sshCommand and its options (such as -i key) are applied so the test matches what git does.

Jump to

Keyboard shortcuts

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