Documentation
¶
Overview ¶
Package credentials turns the credentials of one request into how git reads a repository.
A credential never reaches the command line or a file: a token travels as an HTTP header in `GIT_CONFIG_*`, scoped to the one repository being read, and a key is the path of one already on this server, handed to ssh through `GIT_SSH_COMMAND`.
The transport follows from the credential: a token reads over HTTPS and a key over SSH, whichever way the address was written. So a private repository somebody is only a collaborator on, which takes no deploy key of theirs, is read with the account's token even when its `.gitmodules` line says `git@`.
Index ¶
- Variables
- func CanonicalPrefix(prefix string) string
- type APIToken
- type Access
- type Credential
- type Keys
- func (keys *Keys) APIToken(ctx context.Context, repository repo.Repo, given []Credential, purpose Purpose) (APIToken, error)
- func (keys *Keys) Access(ctx context.Context, repository repo.Repo, given []Credential, purpose Purpose) (Access, error)
- func (keys *Keys) Address(repository repo.Repo) string
- func (keys *Keys) AlsoKeep(source Source)
- type Minter
- type Purpose
- type Source
Constants ¶
This section is empty.
Variables ¶
var ErrUnreachable = errors.New("this credential cannot reach the repository")
ErrUnreachable is a repository a minted credential cannot reach, such as one a GitHub App is not installed on.
Functions ¶
func CanonicalPrefix ¶
CanonicalPrefix writes a prefix the way a canonical address starts, without a port, so that `git@host:acme/`, `ssh://git@host:2222/acme/` and `https://host:3000/acme/` open the same repositories.
Types ¶
type APIToken ¶
APIToken is a token for a host's API, and whether a GitHub App or a sign-in made it.
type Access ¶
Access is one way of reading a repository: the address, and what goes with it in git's environment. Offered says whether a credential goes with it, which is what tells a refused one from none at all; Via names it for the logs, never its secret.
type Credential ¶
type Credential struct {
Prefix string
Token string
User string
Key string
Minter Minter
Label string
// contains filtered or unexported fields
}
Credential opens the repositories whose canonical address starts with Prefix, with a token or with the path of a key, whichever it carries. User goes with the token, and empty is the one its host expects (see tokenUser).
A credential made for each operation has a Minter instead of a Token, and a Label that names it in the logs.
func FromProto ¶
func FromProto(given []*gitdv1.Credential) []Credential
FromProto reads the credentials of a request, each prefix in canonical form.
func KeptMinter ¶
func KeptMinter(prefix string, minter Minter, label string) Credential
KeptMinter is a credential gitd keeps that makes a token for each operation on the repositories under prefix, named label in the logs.
func KeptToken ¶
func KeptToken(prefix, token, user string) Credential
KeptToken is a token gitd keeps for the repositories under prefix, sent as user (empty for the one its host expects).
func Stored ¶
func Stored(settings []config.Credential) ([]Credential, error)
Stored reads the credentials the configuration keeps, each secret from where it says: a token from its file or its environment variable, a key by its path, which ssh reads. A secret that cannot be read stops the start, rather than leaving its repositories to fail one by one.
func (Credential) NamesHost ¶
func (credential Credential) NamesHost() bool
NamesHost says whether the prefix names a host, as https://host[/path] does: a token whose prefix does not would go to any host a repository's submodules name.
type Keys ¶
type Keys struct {
// contains filtered or unexported fields
}
Keys hands ssh the host keys every connection is checked against, and says how each host takes SSH. Nothing is trusted on first use: the keys are the ones GitHub, GitLab, Bitbucket and Codeberg publish, built into the binary, and those of the files the configuration names, for any other host. A host takes SSH as `git` on port 22 unless the configuration says otherwise (repo.Hosts).
func NewKeys ¶
NewKeys writes the host keys under dir, where every ssh gitd starts reads them: the built-in ones followed by those of each file in extra. hosts say how the hosts not reached the usual way are, lowercased as config.Load leaves them, and stored are the credentials the configuration keeps (Stored).
func (*Keys) APIToken ¶
func (keys *Keys) APIToken(ctx context.Context, repository repo.Repo, given []Credential, purpose Purpose) (APIToken, error)
APIToken is the token a host's API takes for a repository and a purpose, from the same credential Access would choose: a token, or one made for this repository and purpose. Minted says it was made by a GitHub App or a sign-in, which only GitHub issues. A key, or no credential, has no token for an API.
func (*Keys) Access ¶
func (keys *Keys) Access(ctx context.Context, repository repo.Repo, given []Credential, purpose Purpose) (Access, error)
Access is how a repository is reached for a purpose: with the most specific credential that opens it, of those the request gives and those gitd keeps, or with nothing when none does. A request's wins over a kept one of the same prefix, so a caller can always say which. One credential and one attempt: nothing here guesses by trying them in turn.
A credential made for each operation — a GitHub App's — is made here, for that one repository and purpose. One that cannot reach the repository reads it as nothing would, so a public repository still reads, and refuses anything else.
type Minter ¶
type Minter interface {
Token(ctx context.Context, repository repo.Repo, purpose Purpose) (string, error)
}
Minter makes a token for one repository and one purpose, as a GitHub App does. One that cannot reach a repository answers an error that wraps ErrUnreachable.
type Purpose ¶
type Purpose int
Purpose is what an access to a repository is for, which is what a credential that is made for each operation — a GitHub App's installation token — is limited to.
type Source ¶
type Source interface {
Credentials() []Credential
}
Source is credentials gitd keeps that may change while it runs, such as the connections made through the API: asked for again at every operation.