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 ¶
- func AddKnownHost(ctx context.Context, env []string, u model.RemoteURL) error
- func AddSSHConfigHost(host, keyPath, port string) error
- func AgentKeys(ctx context.Context, env []string) (keys []string, running bool)
- func CopyToClipboard(text string) error
- func KeyFromSSHCommand(cmd string) string
- func KnownHost(host string) bool
- func OpenURL(url string) error
- func SSHConfigHost(host string) string
- func SSHConfigPath() string
- func SSHDir() string
- func SplitArgs(s string) []string
- type Diagnosis
- type Doctor
- type Key
- type RemoteFilter
- type RewritePlan
- type SSHCheck
- type SSHResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddKnownHost ¶
AddKnownHost appends the host's keys to known_hosts.
func AddSSHConfigHost ¶ added in v0.1.12
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 CopyToClipboard ¶
CopyToClipboard puts text on the system clipboard.
func KeyFromSSHCommand ¶ added in v0.1.3
KeyFromSSHCommand returns the -i key path inside a core.sshCommand value.
func KnownHost ¶ added in v0.1.3
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 SSHConfigHost ¶ added in v0.1.12
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.
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.
type Doctor ¶
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 ¶
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 ¶
GenerateKey creates a new ed25519 key pair without a passphrase prompt.
type RemoteFilter ¶ added in v0.1.11
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 ¶
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
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
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) PinBlocks ¶ added in v0.1.12
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
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.