dockercfg

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 9 Imported by: 10

README

github.com/cpuguy83/dockercfg

Go library to load docker CLI configs, auths, etc. with minimal deps. So far the only deps are on the stdlib.

Usage

See the godoc for API details.

I'm currently using this in zapp to handle registry auth instead of always asking the user to enter it.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCredentialsNotFound         = errors.New("credentials not found in native keychain")
	ErrCredentialsMissingServerURL = errors.New("no credentials server URL")
)

Errors from credential helpers

Functions

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the path to the docker cli config.

It will either use the DOCKER_CONFIG env var if set, or the value from `UserHomeConfigPath` DOCKER_CONFIG would be the dir path where `config.json` is stored, this returns the path to config.json.

func DecodeBase64Auth added in v0.2.0

func DecodeBase64Auth(auth AuthConfig) (string, string, error)

DecodeBase64Auth decodes the legacy file-based auth storage from the docker CLI. It takes the "Auth" filed from AuthConfig and decodes that into a username and password.

If "Auth" is empty, an empty user/pass will be returned, but not an error.

func FromFile

func FromFile(configPath string, cfg *Config) error

FromFile loads config from the specified path into cfg

func GetCredentialsFromHelper

func GetCredentialsFromHelper(helper, hostname string) (string, string, error)

GetCredentialsFromHelper attempts to lookup credentials from the passed in docker credential helper.

The credential helpoer should just be the suffix name (no "docker-credential-"). If the passed in helper program is empty this will look up the default helper for the platform.

If the credentials are not found, no error is returned, only empty credentials.

Hostnames should already be resolved using `ResolveRegistryAuth`

If the username string is empty, the password string is an identity token.

func GetRegistryCredentials

func GetRegistryCredentials(hostname string) (string, string, error)

GetRegistryCredentials gets registry credentials for the passed in registry host.

This will use `LoadDefaultConfig` to read registry auth details from the config. If the config doesn't exist, it will attempt to load registry credentials using the default credential helper for the platform.

func ResolveRegistryHost

func ResolveRegistryHost(host string) string

ResolveRegistryHost can be used to transform a docker registry host name into what is used for the docker config/cred helpers

This is useful for using with containerd authorizers. Natrually this only transforms docker hub URLs.

func UserHomeConfigPath

func UserHomeConfigPath() (string, error)

UserHomeConfigPath returns the path to the docker config in the current user's home dir.

Types

type AuthConfig

type AuthConfig struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	Auth     string `json:"auth,omitempty"`

	// Email is an optional value associated with the username.
	// This field is deprecated and will be removed in a later
	// version of docker.
	Email string `json:"email,omitempty"`

	ServerAddress string `json:"serveraddress,omitempty"`

	// IdentityToken is used to authenticate the user and get
	// an access token for the registry.
	IdentityToken string `json:"identitytoken,omitempty"`

	// RegistryToken is a bearer token to be sent to a registry
	RegistryToken string `json:"registrytoken,omitempty"`
}

AuthConfig contains authorization information for connecting to a Registry

type Config

type Config struct {
	AuthConfigs          map[string]AuthConfig  `json:"auths"`
	HTTPHeaders          map[string]string      `json:"HttpHeaders,omitempty"`
	PsFormat             string                 `json:"psFormat,omitempty"`
	ImagesFormat         string                 `json:"imagesFormat,omitempty"`
	NetworksFormat       string                 `json:"networksFormat,omitempty"`
	PluginsFormat        string                 `json:"pluginsFormat,omitempty"`
	VolumesFormat        string                 `json:"volumesFormat,omitempty"`
	StatsFormat          string                 `json:"statsFormat,omitempty"`
	DetachKeys           string                 `json:"detachKeys,omitempty"`
	CredentialsStore     string                 `json:"credsStore,omitempty"`
	CredentialHelpers    map[string]string      `json:"credHelpers,omitempty"`
	Filename             string                 `json:"-"` // Note: for internal use only
	ServiceInspectFormat string                 `json:"serviceInspectFormat,omitempty"`
	ServicesFormat       string                 `json:"servicesFormat,omitempty"`
	TasksFormat          string                 `json:"tasksFormat,omitempty"`
	SecretFormat         string                 `json:"secretFormat,omitempty"`
	ConfigFormat         string                 `json:"configFormat,omitempty"`
	NodesFormat          string                 `json:"nodesFormat,omitempty"`
	PruneFilters         []string               `json:"pruneFilters,omitempty"`
	Proxies              map[string]ProxyConfig `json:"proxies,omitempty"`
	Experimental         string                 `json:"experimental,omitempty"`
	StackOrchestrator    string                 `json:"stackOrchestrator,omitempty"`
	Kubernetes           *KubernetesConfig      `json:"kubernetes,omitempty"`
	CurrentContext       string                 `json:"currentContext,omitempty"`
	CLIPluginsExtraDirs  []string               `json:"cliPluginsExtraDirs,omitempty"`
	Aliases              map[string]string      `json:"aliases,omitempty"`
}

Config represents the on disk format of the docker CLI's config file.

func LoadDefaultConfig

func LoadDefaultConfig() (Config, error)

LoadDefaultConfig loads the docker cli config from the path returned from `ConfigPath`

func (*Config) GetRegistryCredentials

func (c *Config) GetRegistryCredentials(hostname string) (string, string, error)

GetRegistryCredentials gets credentials, if any, for the provided hostname

Hostnames should already be resolved using `ResolveRegistryAuth`

If the returned username string is empty, the password is an identity token.

type KubernetesConfig

type KubernetesConfig struct {
	AllNamespaces string `json:"allNamespaces,omitempty"`
}

KubernetesConfig contains Kubernetes orchestrator settings

type ProxyConfig

type ProxyConfig struct {
	HTTPProxy  string `json:"httpProxy,omitempty"`
	HTTPSProxy string `json:"httpsProxy,omitempty"`
	NoProxy    string `json:"noProxy,omitempty"`
	FTPProxy   string `json:"ftpProxy,omitempty"`
}

ProxyConfig contains proxy configuration settings

Jump to

Keyboard shortcuts

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