The docker-credential-helpers
project (https://github.com/docker/docker-credential-helpers) provides a set of credential helpers for the Docker engine, enabling secure storage of authentication information. This guide focuses on the architecture of these helpers, specifically the credentials.Helper
interface, building new helpers in Go, and creating a robust development workflow.
Design Philosophy
The docker-credential-helpers
project follows a simple protocol for communication between the Docker engine and the credential helpers. The helpers are any program or script that follows this protocol, which is heavily inspired by Git. The helpers use the first argument in the command to identify the action.
Key Technologies and Dependencies
- Go: The primary language used for building credential helpers.
- golang.org/x/sys: A Go package for low-level interaction with the operating system.
- github.com/danieljoos/wincred: A Go package for interacting with the Windows Credential Manager.
- github.com/docker/docker-credential-helpers/client: A Go package for interacting with the Docker credential store.
- github.com/docker/docker-credential-helpers: The main Go package for building credential helpers.
- github.com/docker/docker-credential-osxkeychain: A Go package for interacting with the macOS Keychain.
- github.com/docker/docker-credential-secretservice: A Go package for interacting with Secret Service API compatible stores.
- github.com/docker/docker-credential-pass: A Go package for interacting with the
pass
password manager. - golangci/golangci-lint: A Go linter for static code analysis.
- crazymax/osxcross: A tool for cross-compiling Go applications for macOS on other platforms.
credentials.Helper
Interface
The credentials.Helper
interface is the foundation for building credential helpers. It defines two methods: Get()
and List()
.
Get()
: Retrieves credentials for a specific registry.List()
: Lists all available credentials.
To build a new credential helper, create a new Go package that implements the credentials.Helper
interface.
Example:
package mynewhelper
import (
"github.com/docker/docker-credential-helpers/credentials"
)
type MyNewHelper struct{}
func (h *MyNewHelper) Get(endpoint string) (map[string]string, error) {
// Implement the Get method for your helper
}
func (h *MyNewHelper) List() (map[string][]string, error) {
// Implement the List method for your helper
}
Building New Helpers in Go
To build a new credential helper in Go, follow these steps:
- Create a new directory for your helper.
- Initialize a new Go module with
go mod init <module-name>
. - Implement the
credentials.Helper
interface in a new Go file. - Add the
github.com/docker/docker-credential-helpers
package as a dependency. - Implement the
Get()
andList()
methods for your helper. - Build your helper with
go build
.
Creating a Robust Development Workflow
To create a robust development workflow, consider the following steps:
- Use
golangci/golangci-lint
for static code analysis. - Write tests for your helper.
- Use
crazymax/osxcross
for cross-compiling your helper for different platforms. - Set up continuous integration (CI) to test your helper on multiple platforms.
Docker Configuration
The Docker engine uses the credsStore
and credHelpers
properties to specify the default credential store and preferential credential helpers for specific registries.
Example:
{
"credsStore": "osxkeychain",
"credHelpers": {
"myregistry.com": "mynewhelper"
}
}
Authentication with the Container Registry
To authenticate with a container registry, use the docker login
command with the appropriate credentials.
Example:
docker login -u <username> -p <access_token> $CI_REGISTRY
Docker Desktop Release Notes
Docker Desktop now installs credential helpers from Github releases.
Sources:
- https://github.com/docker/docker-credential-helpers
- https://prometheus.io/docs/prometheus/latest/configuration/
- https://prometheus.io/docs/operating/configuration/
- https://developer.hashicorp.com/nomad/docs/drivers/docker
- https://docs.docker.com/engine/reference/commandline/login
- https://docs.docker.com/desktop/release-notes
- https://docs.docker.com/engine/reference/commandline/cli
- https://docs.gitlab.com/ee/user/packages/container_registry/authenticate_with_container_registry.html
- https://developer.hashicorp.com/vagrant/docs/providers/docker/configuration
- https://developer.hashicorp.com/packer/integrations/hashicorp/docker/latest/components/post-processor/docker-push