|
|
@ -5,20 +5,18 @@ import (
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/reference"
|
|
|
|
"github.com/docker/docker/api/types/reference"
|
|
|
|
"github.com/docker/docker/cli/command"
|
|
|
|
"github.com/docker/docker/cli/command"
|
|
|
|
"github.com/docker/docker/cliconfig"
|
|
|
|
"github.com/docker/docker/cliconfig"
|
|
|
|
"github.com/docker/docker/cliconfig/configfile"
|
|
|
|
"github.com/docker/docker/cliconfig/configfile"
|
|
|
|
"github.com/docker/docker/cliconfig/credentials"
|
|
|
|
"github.com/docker/docker/cliconfig/credentials"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
// EncodedAuth returns an encoded auth config for the given registry
|
|
|
|
* Return an encoded auth config for the given registry
|
|
|
|
// loaded from environment variables or docker config
|
|
|
|
* loaded from environment variables or docker config
|
|
|
|
// as available in that order
|
|
|
|
* as available in that order
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
func EncodedAuth(ref string) (string, error) {
|
|
|
|
func EncodedAuth(ref string) (string, error) {
|
|
|
|
auth, err := EncodedEnvAuth(ref)
|
|
|
|
auth, err := EncodedEnvAuth(ref)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -27,11 +25,9 @@ func EncodedAuth(ref string) (string, error) {
|
|
|
|
return auth, err
|
|
|
|
return auth, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
// EncodedEnvAuth returns an encoded auth config for the given registry
|
|
|
|
* Return an encoded auth config for the given registry
|
|
|
|
// loaded from environment variables
|
|
|
|
* loaded from environment variables
|
|
|
|
// Returns an error if authentication environment variables have not been set
|
|
|
|
* Returns an error if authentication environment variables have not been set
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
func EncodedEnvAuth(ref string) (string, error) {
|
|
|
|
func EncodedEnvAuth(ref string) (string, error) {
|
|
|
|
username := os.Getenv("REPO_USER")
|
|
|
|
username := os.Getenv("REPO_USER")
|
|
|
|
password := os.Getenv("REPO_PASS")
|
|
|
|
password := os.Getenv("REPO_PASS")
|
|
|
@ -42,17 +38,14 @@ func EncodedEnvAuth(ref string) (string, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Debugf("Loaded auth credentials %s for %s", auth, ref)
|
|
|
|
log.Debugf("Loaded auth credentials %s for %s", auth, ref)
|
|
|
|
return EncodeAuth(auth)
|
|
|
|
return EncodeAuth(auth)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return "", errors.New("Registry auth environment variables (REPO_USER, REPO_PASS) not set")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", errors.New("Registry auth environment variables (REPO_USER, REPO_PASS) not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
// EncodedConfigAuth returns an encoded auth config for the given registry
|
|
|
|
* Return an encoded auth config for the given registry
|
|
|
|
// loaded from the docker config
|
|
|
|
* loaded from the docker config
|
|
|
|
// Returns an empty string if credentials cannot be found for the referenced server
|
|
|
|
* Returns an empty string if credentials cannot be found for the referenced server
|
|
|
|
// The docker config must be mounted on the container
|
|
|
|
* The docker config must be mounted on the container
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
func EncodedConfigAuth(ref string) (string, error) {
|
|
|
|
func EncodedConfigAuth(ref string) (string, error) {
|
|
|
|
server, err := ParseServerAddress(ref)
|
|
|
|
server, err := ParseServerAddress(ref)
|
|
|
|
configDir := os.Getenv("DOCKER_CONFIG")
|
|
|
|
configDir := os.Getenv("DOCKER_CONFIG")
|
|
|
@ -92,18 +85,14 @@ func CredentialsStore(configFile configfile.ConfigFile) credentials.Store {
|
|
|
|
return credentials.NewFileStore(&configFile)
|
|
|
|
return credentials.NewFileStore(&configFile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
// EncodeAuth Base64 encode an AuthConfig struct for transmission over HTTP
|
|
|
|
* Base64 encode an AuthConfig struct for transmission over HTTP
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
func EncodeAuth(auth types.AuthConfig) (string, error) {
|
|
|
|
func EncodeAuth(auth types.AuthConfig) (string, error) {
|
|
|
|
return command.EncodeAuthToBase64(auth)
|
|
|
|
return command.EncodeAuthToBase64(auth)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
// DefaultAuthHandler will be invoked if an AuthConfig is rejected
|
|
|
|
* This function will be invoked if an AuthConfig is rejected
|
|
|
|
// It could be used to return a new value for the "X-Registry-Auth" authentication header,
|
|
|
|
* It could be used to return a new value for the "X-Registry-Auth" authentication header,
|
|
|
|
// but there's no point trying again with the same value as used in AuthConfig
|
|
|
|
* but there's no point trying again with the same value as used in AuthConfig
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
func DefaultAuthHandler() (string, error) {
|
|
|
|
func DefaultAuthHandler() (string, error) {
|
|
|
|
log.Debug("Authentication request was rejected. Trying again without authentication")
|
|
|
|
log.Debug("Authentication request was rejected. Trying again without authentication")
|
|
|
|
return "", nil
|
|
|
|
return "", nil
|
|
|
|