Skip to content

Commit 511f65c

Browse files
authored
mz280: log used credential sources explicitly (#369)
2 parents 5b6cfca + 27ca164 commit 511f65c

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ expect - see [Known Issues](#known-issues).
5656
- [Caching Layers](#caching-layers)
5757
- [Caching Base Images](#caching-base-images)
5858
- [Pushing to Different Registries](#pushing-to-different-registries)
59+
- [Credential Provider Priorities](#credential-provider-priorities)
5960
- [Pushing to Docker Hub](#pushing-to-docker-hub)
6061
- [Pushing to Google GCR](#pushing-to-google-gcr)
6162
- [Pushing to GCR using Workload Identity](#pushing-to-gcr-using-workload-identity)
@@ -621,6 +622,11 @@ kaniko comes with support for GCR, Docker `config.json` and Amazon ECR, but
621622
configuring another credential helper should allow pushing to a different
622623
registry.
623624

625+
#### Credential Provider Priorities
626+
627+
By default kaniko will configure all built-in credential providers for you. These are `[default, env, google, ecr, acr, gitlab]`.
628+
You can (de)-activate credential helpers via the [`--credential-helpers`](#flag---credential-helpers) flag. The `default` credential helper will always be active and itself handles two sources: `DOCKER_AUTH_CONFIG` environment variable and `/kaniko/.docker/config.json` file, where priority is always given to `DOCKER_AUTH_CONFIG` and therefore can shadow credentials configured in the config file. If you want to disable `DOCKER_AUTH_CONFIG` you have to unset the environment variable explicitly `unset DOCKER_AUTH_CONFIG` prior to calling kaniko.
629+
624630
#### Pushing to Docker Hub
625631

626632
Get your docker registry user and password encoded in base64

cmd/executor/cmd/root.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,15 @@ var RootCmd = &cobra.Command{
187187
}
188188
if !opts.NoPush || opts.CacheRepo != "" {
189189
if err := executor.CheckPushPermissions(opts); err != nil {
190-
exit(fmt.Errorf("error checking push permissions -- make sure you entered the correct tag name, and that you are authenticated correctly, and try again: %w", err))
190+
logrus.Warnf("make sure you entered the correct tag name, that you are authenticated correctly, and try again.")
191+
// mz280: remind users that DOCKER_AUTH_CONFIG gets prioritized by docker-cli
192+
// https://github.com/docker/cli/pull/6171
193+
_, ok := os.LookupEnv("DOCKER_AUTH_CONFIG")
194+
if ok {
195+
logrus.Warnf("note that your DOCKER_AUTH_CONFIG env variable can shadow credentials from configfile")
196+
logrus.Warnf("see https://github.com/osscontainertools/kaniko/issues/280#issuecomment-3498449955")
197+
}
198+
exit(fmt.Errorf("error checking push permissions: %w", err))
191199
}
192200
}
193201
if err := resolveRelativePaths(); err != nil {

pkg/creds/creds.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,43 @@ limitations under the License.
1717
package creds
1818

1919
import (
20+
"fmt"
2021
"io"
22+
"os"
23+
"strings"
2124

2225
ecr "github.com/awslabs/amazon-ecr-credential-helper/ecr-login"
2326
"github.com/chrismellard/docker-credential-acr-env/pkg/credhelper"
2427
gitlab "github.com/ePirat/docker-credential-gitlabci/pkg/credhelper"
2528
"github.com/google/go-containerregistry/pkg/authn"
2629
"github.com/google/go-containerregistry/pkg/v1/google"
2730
"github.com/osscontainertools/kaniko/pkg/config"
31+
"github.com/osscontainertools/kaniko/pkg/util"
2832
"github.com/sirupsen/logrus"
2933
)
3034

3135
// GetKeychain returns a keychain for accessing container registries.
3236
func GetKeychain(opts *config.RegistryOptions) authn.Keychain {
3337
var helpers []string
38+
var prios []string
39+
40+
_, ok := os.LookupEnv("DOCKER_AUTH_CONFIG")
41+
if ok {
42+
prios = append(prios, "env:DOCKER_AUTH_CONFIG")
43+
}
44+
45+
cf := util.DockerConfLocation()
46+
_, err := os.Lstat(cf)
47+
if err == nil {
48+
prios = append(prios, fmt.Sprintf("file:%s", cf))
49+
}
3450

3551
if len(opts.CredentialHelpers) == 0 {
3652
helpers = []string{"env", "google", "ecr", "acr", "gitlab"}
3753
} else {
3854
helpers = opts.CredentialHelpers
3955
}
56+
prios = append(prios, helpers...)
4057

4158
keychains := []authn.Keychain{authn.DefaultKeychain}
4259
for _, source := range helpers {
@@ -72,5 +89,6 @@ func GetKeychain(opts *config.RegistryOptions) authn.Keychain {
7289
}
7390
}
7491

92+
logrus.Infof("credential providers by priority: [%s]", strings.Join(prios, ", "))
7593
return authn.NewMultiKeychain(keychains...)
7694
}

0 commit comments

Comments
 (0)