Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable default docker config provider #255

Merged
merged 2 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/imgpkg
/imgpkg-darwin-amd64
/imgpkg-darwin-arm66
/imgpkg-darwin-arm64
/imgpkg-linux-amd64
/imgpkg-windows-amd64.exe
/tmp
Expand Down
6 changes: 6 additions & 0 deletions hack/build-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ go fmt ./cmd/... ./pkg/... ./test/...
go mod vendor
go mod tidy

# related to https://github.com/vmware-tanzu/carvel-imgpkg/pull/255
# there doesn't appear to be a simple way to disable the defaultDockerConfigProvider
# Having defaultDockerConfigProvider enabled by default results in the imgpkg auth ordering not working correctly
# Specifically, the docker config.json is loaded before cli flags (and maybe even IaaS metadata services)
git apply ./hack/patch-k8s-pkg-credentialprovider.patch
DennisDenuto marked this conversation as resolved.
Show resolved Hide resolved

# makes builds reproducible
export CGO_ENABLED=0
LDFLAGS="-X github.com/k14s/imgpkg/pkg/imgpkg/cmd.Version=$VERSION -buildid="
Expand Down
6 changes: 6 additions & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ go fmt ./cmd/... ./pkg/... ./test/...
go mod vendor
go mod tidy

# related to https://github.com/vmware-tanzu/carvel-imgpkg/pull/255
# there doesn't appear to be a simple way to disable the defaultDockerConfigProvider
# Having defaultDockerConfigProvider enabled by default results in the imgpkg auth ordering not working correctly
# Specifically, the docker config.json is loaded before cli flags (and maybe even IaaS metadata services)
git apply ./hack/patch-k8s-pkg-credentialprovider.patch

# export GOOS=linux GOARCH=amd64
go build -ldflags="$LDFLAGS" -trimpath -o imgpkg ./cmd/imgpkg/...
./imgpkg version
Expand Down
13 changes: 13 additions & 0 deletions hack/patch-k8s-pkg-credentialprovider.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/vendor/github.com/vdemeester/k8s-pkg-credentialprovider/provider.go b/vendor/github.com/vdemeester/k8s-pkg-credentialprovider/provider.go
index 8c9ad34..f953bb4 100644
--- a/vendor/github.com/vdemeester/k8s-pkg-credentialprovider/provider.go
+++ b/vendor/github.com/vdemeester/k8s-pkg-credentialprovider/provider.go
@@ -70,7 +70,7 @@ type CachingDockerConfigProvider struct {

// Enabled implements dockerConfigProvider
func (d *defaultDockerConfigProvider) Enabled() bool {
- return true
+ return false
}

// Provide implements dockerConfigProvider
33 changes: 33 additions & 0 deletions pkg/imgpkg/registry/keychain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func TestMain(m *testing.M) {
gcpRegistryURL, server = registerGCPProvider()
defer server.Close()

tempConfigJSONProviderDir := registerDefaultDockerProvider()
defer os.RemoveAll(tempConfigJSONProviderDir)

os.Exit(m.Run())
}

Expand Down Expand Up @@ -664,6 +667,36 @@ func TestOrderingOfAuthOpts(t *testing.T) {
})
}

func registerDefaultDockerProvider() string {
// TestOrderingOfAuthOpts does *not* use the default .docker/config.json location (they use the DOCKER_CONFIG env var)
// (to avoid test pollution and/or messing with a dev's docker files they may rely on)
// Setting up the ordering tests in that way resulted in a slight loss of test coverage.
// for e.g. the introduction of credentialprovider.defaultDockerConfigProvider resulted in none of the tests failing
// So, in order to assert that credentialprovider.defaultDockerConfigProvider is disabled now and in the future
// we configure the credentialprovider.defaultDockerConfigProvider with a docker config json file with credentials
// (that shouldn't be chosen ever) for the same registry as the ordering tests.
// This is also done before any test is run since the credentialprovider.defaultDockerConfigProvider is cached
tempConfigJSONProviderDir, err := ioutil.TempDir(os.TempDir(), "test-default-keychain-provider")
if err != nil {
panic(fmt.Errorf("unable to run test: %s", err))
}

err = ioutil.WriteFile(filepath.Join(tempConfigJSONProviderDir, "config.json"), []byte(`{
cppforlife marked this conversation as resolved.
Show resolved Hide resolved
"auths" : {
"http://some.fake.registry/v1/" : {
"username": "provider-username",
"password": "provider-password"
}
}
}`), os.ModePerm)
if err != nil {
panic(fmt.Errorf("unable to run test: %s", err))
}

credentialprovider.SetPreferredDockercfgPath(tempConfigJSONProviderDir)
return tempConfigJSONProviderDir
}

func registerGCPProvider() (string, *httptest.Server) {
registryURL := "imgpkg-testing.kubernetes.carvel"
email := "foo@bar.baz"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.