Skip to content

Instantly share code, notes, and snippets.

Created June 28, 2022 14:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Demonstrating go-containerregistry basic auth keychain
package main
import (
func main() {
keychain := authn.NewMultiKeychain(
basicKeychain{"", "username", "password"},
basicKeychain{"", "otheruser", "otherpass"},
google.Keychain, // for
if err := crane.Copy("", "",
crane.WithAuthFromKeychain(keychain)); err != nil {
type basicKeychain struct{ registry, username, password string }
func (b basicKeychain) Resolve(r authn.Resource) (authn.Authenticator, error) {
if r.RegistryStr() != b.registry {
return nil, fmt.Errorf("basicKeychain: only %q is supported", b.registry)
return b, nil
func (b basicKeychain) Authorization() (*authn.AuthConfig, error) {
return &authn.AuthConfig{
Username: b.username,
Password: b.password,
}, nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment