credentials

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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

func CanonicalPrefix(prefix string) string

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

type APIToken struct {
	Token  string
	Minted bool
}

APIToken is a token for a host's API, and whether a GitHub App or a sign-in made it.

type Access

type Access struct {
	URL     string
	Env     []string
	Offered bool
	Via     string
}

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

func NewKeys(dir string, extra []string, hosts repo.Hosts, stored []Credential) (*Keys, error)

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.

func (*Keys) Address

func (keys *Keys) Address(repository repo.Repo) string

Address is where a repository is read over HTTPS, on its host's port: what a copy of it names as its origin.

func (*Keys) AlsoKeep

func (keys *Keys) AlsoKeep(source Source)

AlsoKeep adds credentials gitd keeps besides those of the configuration file.

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.

const (
	// Read fetches: prepare, update, checkout, probe.
	Read Purpose = iota
	// Write pushes a published branch.
	Write
	// PullRequests opens a pull request and asks for its reviewers and labels.
	PullRequests
)

func (Purpose) String

func (purpose Purpose) String() string

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.

Jump to

Keyboard shortcuts

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