-
Notifications
You must be signed in to change notification settings - Fork 2k
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
docker: fix a bug where auth for private registries wasn't parsed correctly #24215
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2274214
e2e
pkazmierczak 936d57e
e2e docker job files corrections
pkazmierczak ac400e6
podman test typos correction
pkazmierczak 3238de0
pass encoded basic auth, not user/pass pair
pkazmierczak c6c9c4b
comment
pkazmierczak bf1e050
TestDockerDriver_AuthConfiguration correction
pkazmierczak 7f9d295
cl
pkazmierczak 268622d
AuthFromTaskConfig
pkazmierczak a1ae4c9
simplify
pkazmierczak abf43de
remove redundant code
pkazmierczak 29cb20c
mark registry as insecure for e2e
pkazmierczak 5eb1e15
eh that's a bad idea
pkazmierczak d0c89d8
Tim's comment
pkazmierczak 5d16152
e2e fix
pkazmierczak 46ae9df
helper update for e2e
pkazmierczak 3e22629
wrap up e2e
pkazmierczak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
docker: Fix incorrect auth parsing for private registries | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2481,6 +2481,7 @@ func TestDockerDriver_AuthConfiguration(t *testing.T) { | |
{ | ||
Repo: "redis:7", | ||
AuthConfig: ®istry.AuthConfig{ | ||
Auth: "eyJ1c2VybmFtZSI6InRlc3QiLCJwYXNzd29yZCI6IjEyMzQifQ==", | ||
Username: "test", | ||
Password: "1234", | ||
Email: "", | ||
|
@@ -2490,6 +2491,7 @@ func TestDockerDriver_AuthConfiguration(t *testing.T) { | |
{ | ||
Repo: "quay.io/redis:7", | ||
AuthConfig: ®istry.AuthConfig{ | ||
Auth: "eyJ1c2VybmFtZSI6InRlc3QiLCJwYXNzd29yZCI6IjU2NzgifQ==", | ||
Username: "test", | ||
Password: "5678", | ||
Email: "", | ||
|
@@ -2499,6 +2501,7 @@ func TestDockerDriver_AuthConfiguration(t *testing.T) { | |
{ | ||
Repo: "other.io/redis:7", | ||
AuthConfig: ®istry.AuthConfig{ | ||
Auth: "eyJ1c2VybmFtZSI6InRlc3QiLCJwYXNzd29yZCI6ImFiY2QifQ==", | ||
Username: "test", | ||
Password: "abcd", | ||
Email: "", | ||
|
@@ -2535,6 +2538,7 @@ func TestDockerDriver_AuthFromTaskConfig(t *testing.T) { | |
ServerAddr: "www.foobar.com", | ||
}, | ||
AuthConfig: ®istry.AuthConfig{ | ||
Auth: "eyJ1c2VybmFtZSI6ImZvbyIsInBhc3N3b3JkIjoiYmFyIn0=", | ||
Username: "foo", | ||
Password: "bar", | ||
Email: "[email protected]", | ||
|
@@ -2549,6 +2553,7 @@ func TestDockerDriver_AuthFromTaskConfig(t *testing.T) { | |
ServerAddr: "www.foobar.com", | ||
}, | ||
AuthConfig: ®istry.AuthConfig{ | ||
Auth: "eyJ1c2VybmFtZSI6ImZvbyIsInBhc3N3b3JkIjoiYmFyIn0=", | ||
Username: "foo", | ||
Password: "bar", | ||
ServerAddress: "www.foobar.com", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
// Package docker contains test cases related to the docker task driver. | ||
package docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package docker | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/nomad/e2e/e2eutil" | ||
"github.com/hashicorp/nomad/e2e/v3/cluster3" | ||
"github.com/hashicorp/nomad/e2e/v3/jobs3" | ||
"github.com/shoenig/test/must" | ||
) | ||
|
||
const ( | ||
registryService = "registry" | ||
) | ||
|
||
func TestDocker(t *testing.T) { | ||
cluster3.Establish(t, | ||
cluster3.Leader(), | ||
cluster3.LinuxClients(1), | ||
) | ||
|
||
runRegistry(t) | ||
|
||
t.Run("testRedis", testRedis) | ||
t.Run("testAuthBasic", testAuthBasic) | ||
t.Run("testAuthFileStatic", testAuthFileStatic) | ||
t.Run("testAuthHelper", testAuthHelper) | ||
} | ||
|
||
func findService(t *testing.T, name string) (string, int) { | ||
services, _, err := e2eutil.NomadClient(t).Services().Get(name, nil) | ||
must.NoError(t, err, must.Sprintf("failed to find %q service", name)) | ||
must.Len(t, 1, services, must.Sprintf("expected 1 %q service", name)) | ||
return services[0].Address, services[0].Port | ||
} | ||
|
||
func runRegistry(t *testing.T) { | ||
_, regCleanup := jobs3.Submit(t, | ||
"../docker_registry/registry.hcl", | ||
jobs3.Timeout(40*time.Second), // pulls an image | ||
) | ||
t.Cleanup(regCleanup) | ||
|
||
// lookup registry address | ||
addr, port := findService(t, registryService) | ||
address := fmt.Sprintf("%s:%d", addr, port) | ||
|
||
t.Logf("Setting up insecure private registry at %v", address) | ||
|
||
// run the sed job to fixup the auth.json file with correct address and make | ||
// sure the registry is marked as insecure for docker, otherwise pulls will | ||
// fail | ||
_, sedCleanup := jobs3.Submit(t, | ||
"./input/registry-auths.hcl", | ||
jobs3.Var("registry_address", address), | ||
jobs3.Var("user", "root"), | ||
jobs3.Var("helper_dir", "/usr/local/bin"), | ||
jobs3.Var("auth_dir", "/etc"), | ||
jobs3.Var("docker_conf_dir", "/etc/docker"), | ||
jobs3.WaitComplete("create-files"), | ||
jobs3.Timeout(20*time.Second), | ||
) | ||
t.Cleanup(sedCleanup) | ||
} | ||
|
||
func testRedis(t *testing.T) { | ||
job, cleanup := jobs3.Submit(t, "./input/redis.hcl") | ||
t.Cleanup(cleanup) | ||
|
||
logs := job.TaskLogs("cache", "redis") | ||
must.StrContains(t, logs.Stdout, "oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo") | ||
} | ||
|
||
func testAuthBasic(t *testing.T) { | ||
// find the private registry service | ||
regAddr, regPort := findService(t, "registry") | ||
|
||
// run the private bash image | ||
bashJob, bashCleanup := jobs3.Submit(t, "./input/auth_basic.hcl", | ||
jobs3.Var("registry_address", regAddr), | ||
jobs3.Var("registry_port", strconv.Itoa(regPort)), | ||
jobs3.WaitComplete("basic"), | ||
) | ||
t.Cleanup(bashCleanup) | ||
logs := bashJob.TaskLogs("basic", "echo") | ||
must.StrContains(t, logs.Stdout, "The auth basic test is OK!") | ||
} | ||
|
||
func testAuthFileStatic(t *testing.T) { | ||
// find the private registry service | ||
regAddr, regPort := findService(t, "registry") | ||
|
||
// run the private _static bash image | ||
bashJob, bashCleanup := jobs3.Submit(t, "./input/auth_static.hcl", | ||
jobs3.Var("registry_address", regAddr), | ||
jobs3.Var("registry_port", strconv.Itoa(regPort)), | ||
jobs3.WaitComplete("static"), | ||
) | ||
t.Cleanup(bashCleanup) | ||
logs := bashJob.TaskLogs("static", "echo") | ||
must.StrContains(t, logs.Stdout, "The static auth test is OK!") | ||
} | ||
|
||
func testAuthHelper(t *testing.T) { | ||
// find the private registry service | ||
regAddr, regPort := findService(t, "registry") | ||
|
||
t.Log("registry", regAddr, regPort) | ||
|
||
// run the private _helper bash image | ||
bashJob, bashCleanup := jobs3.Submit(t, "./input/auth_helper.hcl", | ||
jobs3.Var("registry_address", regAddr), | ||
jobs3.Var("registry_port", strconv.Itoa(regPort)), | ||
jobs3.WaitComplete("helper"), | ||
) | ||
t.Cleanup(bashCleanup) | ||
logs := bashJob.TaskLogs("helper", "echo") | ||
must.StrContains(t, logs.Stdout, "The credentials helper auth test is OK!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
# This job runs a docker task using a container stored in a private registry | ||
# configured with basic authentication. The registry.hcl job should be running | ||
# and healthy before running this job. The registry_address and registry_port | ||
# HCL variables must be provided. | ||
|
||
variable "registry_address" { | ||
type = string | ||
description = "The HTTP address of the local registry" | ||
default = "localhost" | ||
} | ||
|
||
variable "registry_port" { | ||
type = number | ||
description = "The HTTP port of the local registry" | ||
default = "7511" | ||
} | ||
|
||
variable "registry_username" { | ||
type = string | ||
description = "The Basic Auth username of the local registry" | ||
default = "auth_basic_user" | ||
} | ||
|
||
variable "registry_password" { | ||
type = string | ||
description = "The Basic Auth password of the local registry" | ||
default = "auth_basic_pass" | ||
} | ||
|
||
locals { | ||
registry_auth = base64encode("${var.registry_username}:${var.registry_password}") | ||
} | ||
|
||
job "auth_basic" { | ||
type = "batch" | ||
|
||
constraint { | ||
attribute = "${attr.kernel.name}" | ||
value = "linux" | ||
} | ||
|
||
group "basic" { | ||
reschedule { | ||
attempts = 0 | ||
unlimited = false | ||
} | ||
|
||
network { | ||
mode = "host" | ||
} | ||
|
||
task "echo" { | ||
driver = "docker" | ||
|
||
config { | ||
image = "${var.registry_address}:${var.registry_port}/docker.io/library/bash_auth_basic:private" | ||
args = ["echo", "The auth basic test is OK!"] | ||
auth_soft_fail = true | ||
|
||
auth { | ||
username = "${var.registry_username}" | ||
password = "${var.registry_password}" | ||
} | ||
} | ||
|
||
resources { | ||
cpu = 100 | ||
memory = 64 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
# This job runs a docker task using a container stored in a private registry | ||
# configured with credentials helper authentication. The registry.hcl job should | ||
# be running and healthy before running this job. | ||
|
||
variable "registry_address" { | ||
type = string | ||
description = "The HTTP address of the local registry" | ||
default = "localhost" | ||
} | ||
|
||
variable "registry_port" { | ||
type = number | ||
description = "The HTTP port of the local registry" | ||
default = "7511" | ||
} | ||
|
||
job "auth_static" { | ||
type = "batch" | ||
|
||
constraint { | ||
attribute = "${attr.kernel.name}" | ||
value = "linux" | ||
} | ||
|
||
group "helper" { | ||
reschedule { | ||
attempts = 0 | ||
unlimited = false | ||
} | ||
|
||
network { | ||
mode = "host" | ||
} | ||
|
||
task "echo" { | ||
driver = "docker" | ||
|
||
config { | ||
image = "${var.registry_address}:${var.registry_port}/docker.io/library/bash_auth_helper:private" | ||
args = ["echo", "The credentials helper auth test is OK!"] | ||
|
||
# usename and password come from [docker-credential-]test.sh found on | ||
# $PATH as specified by "helper=test.sh" in plugin config | ||
} | ||
|
||
resources { | ||
cpu = 100 | ||
memory = 64 | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👻