oci

package
v0.15.21 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 15 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 oci is the provider for OCI and Docker registry credentials: the logins a Docker config keeps per registry, wherever that config is embedded (a config.json, a Kubernetes pull secret, Helm values, a Basic Authorization header aimed at a registry), and the native tokens of Docker Hub and Quay.

A login is a username and a password for one host, so its name in reports is `host/username`, which is not secret; the password travels in Token.Secret and is never shown. When the password is itself a Docker Hub or Quay token the finding is that token, so the same credential is one finding whether it turns up in a pull secret or in a CI variable. When it is another provider's credential, a GitHub token used against ghcr.io, the login says so and that provider's finding carries the token.

Verification is one anonymous probe of the registry's /v2/ endpoint followed by one token request with the login; no image or manifest is pulled. Only Docker Hub personal access tokens can revoke themselves; every other kind gets the owner's rotation procedure.

Index

Constants

View Source
const (
	// KindHubLogin is a Docker Hub username with a password that is not a
	// Docker Hub token.
	KindHubLogin detect.Kind = "docker-hub-login"
	// KindQuayLogin is a quay.io username with a password that is not a
	// robot token.
	KindQuayLogin detect.Kind = "quay-login"
	// KindACRLogin is an Azure Container Registry login: an admin user, a
	// repository-scoped token or a service principal.
	KindACRLogin detect.Kind = "acr-login"
	// KindGHCRLogin is a ghcr.io login; its password is a GitHub token.
	KindGHCRLogin detect.Kind = "ghcr-login"
	// KindGCRLogin is a Google Container or Artifact Registry login.
	KindGCRLogin detect.Kind = "gcr-login"
	// KindECRLogin is an Amazon ECR login; its password is a 12-hour token.
	KindECRLogin detect.Kind = "ecr-login"
	// KindHarborLogin is a login to a Harbor registry.
	KindHarborLogin detect.Kind = "harbor-login"
	// KindRegistryLogin is a login to any other registry.
	KindRegistryLogin detect.Kind = "registry-login"
	// KindHubPAT is a Docker Hub personal access token (dckr_pat_).
	KindHubPAT detect.Kind = "docker-hub-pat"
	// KindHubOAT is a Docker Hub organization access token (dckr_oat_).
	KindHubOAT detect.Kind = "docker-hub-oat"
	// KindQuayRobot is the token of a Quay robot account, 64 upper-case
	// alphanumerics that are only a credential together with the robot's
	// `org+name` username.
	KindQuayRobot detect.Kind = "quay-robot-token"
	// KindQuayOAuth is a Quay OAuth access token, 40 alphanumerics.
	KindQuayOAuth detect.Kind = "quay-oauth-token"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Login

type Login struct {
	Host, Username, Password string
	// Offset is where the entry, or the encoded blob holding it, starts.
	Offset int
	// Encoded reports whether the password came out of a base64 layer, so
	// no other provider has seen it in the clear.
	Encoded bool
}

Login is the credential of one registry entry: what the decoder hands the provider.

type Provider

type Provider struct {
	// Scheme is how registry hosts are reached, https by default; tests
	// point it at an http test server.
	Scheme string
	// HubURL is the Docker Hub API root, https://hub.docker.com by default.
	HubURL string
	// QuayHost is where Quay tokens are checked, quay.io by default.
	QuayHost string
	Client   *http.Client
	// contains filtered or unexported fields
}

Provider implements detect.Provider for container registries.

func New

func New(peers ...detect.Provider) *Provider

New returns a Provider against the public registries. peers are the other providers; a registry password that is one of their credentials is reported as theirs.

func (*Provider) DryRunRevoke

func (p *Provider) DryRunRevoke(ctx context.Context, tok detect.Token) error

DryRunRevoke implements detect.DryRunRevoker: it logs in and finds the token in the account's list exactly as Revoke would, and changes nothing.

func (*Provider) Find

func (p *Provider) Find(content []byte) []detect.Token

Find implements detect.Provider. The config decoder runs first and consumes the encoded blobs it understands; the bare token shapes are then searched outside those blobs, and a token that is already the password of a decoded login is not reported twice.

func (*Provider) Kinds

func (*Provider) Kinds() []detect.KindInfo

Kinds implements detect.Provider. Only a Docker Hub personal access token can be revoked through the API, by itself; everything else names where its owner rotates it.

func (*Provider) LocalSources

func (*Provider) LocalSources() detect.LocalSources

LocalSources implements detect.Provider: the Docker config, podman's and helm's auth files, and the variables CI jobs pass a registry password in. Only a login's host and user are compared, so only a config file can match; a variable holding a bare password matches when the password is a Docker Hub token. An entry that names a credsStore or credHelper keeps its secret in the OS keychain, which is not read.

func (*Provider) Name

func (*Provider) Name() string

Name implements detect.Provider.

func (*Provider) Revoke

func (p *Provider) Revoke(ctx context.Context, tokens []detect.Token) error

Revoke implements detect.Revoker for Docker Hub personal access tokens, the only kind a registry lets patty revoke: the token logs in, obtains a JWT for its account, finds itself in the account's token list and sets itself inactive. A read-only token may not manage tokens and says so. A deactivated token can be reactivated by its owner; deleting it is left to them. Every other kind is rotated by hand as the report says.

func (*Provider) Verify

func (p *Provider) Verify(ctx context.Context, tok detect.Token) detect.Verification

Verify implements detect.Provider with one exchange per credential and without pulling anything: a login makes one anonymous probe of the registry's /v2/ endpoint to learn where it hands out tokens, then one token request with the login and no scope. Docker Hub logins and tokens go to hub.docker.com's login endpoint instead, Quay OAuth tokens to the Quay API. A 401 is revoked; a 403 is a live credential that may not do what was asked, unless the registry answers a request without any credentials with 403 as well, as ghcr.io does: then the login was not accepted either.

Jump to

Keyboard shortcuts

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