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

config: enable setting tlsVerify during image pull #262

Merged
merged 1 commit into from
Jul 5, 2023
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,15 @@ config {
}
```

* **auth** - (Optional) Authenticate to the image registry using a static credential.
* **auth** - (Optional) Authenticate to the image registry using a static credential. `tls_verify` can be disabled for insecure registries.

```hcl
config {
image = "your.registry.tld/some/image"
auth {
username = "someuser"
password = "sup3rs3creT"
username = "someuser"
password = "sup3rs3creT"
tls_verify = true
}
}
```
Expand Down
5 changes: 3 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ type ClientConfig struct {
}

type ImageAuthConfig struct {
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
TLSVerify bool
Username string
Password string
}

func DefaultClientConfig() ClientConfig {
Expand Down
8 changes: 6 additions & 2 deletions api/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ func (c *API) ImagePull(ctx context.Context, nameWithTag string, auth ImageAuthC
headers := map[string]string{}

// handle authentication
if auth.Username != "" && auth.Password != "" {
usesAuth := auth.Username != "" && auth.Password != ""
if usesAuth {
authHeader, err := NewAuthHeader(auth)
if err != nil {
return "", err
}
headers["X-Registry-Auth"] = authHeader
}

res, err := c.PostWithHeaders(ctx, fmt.Sprintf("/v1.0.0/libpod/images/pull?reference=%s", nameWithTag), nil, headers)
c.logger.Trace("image pull details", "tls_verify", auth.TLSVerify, "reference", nameWithTag, "uses_auth", usesAuth)

urlPath := fmt.Sprintf("/v1.0.0/libpod/images/pull?reference=%s&tlsVerify=%t", nameWithTag, auth.TLSVerify)
res, err := c.PostWithHeaders(ctx, urlPath, nil, headers)
if err != nil {
return "", err
}
Expand Down
9 changes: 7 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ var (
"auth": hclspec.NewBlock("auth", false, hclspec.NewObject(map[string]*hclspec.Spec{
"username": hclspec.NewAttr("username", "string", false),
"password": hclspec.NewAttr("password", "string", false),
"tls_verify": hclspec.NewDefault(
hclspec.NewAttr("tls_verify", "bool", false),
hclspec.NewLiteral("true"),
),
})),
"command": hclspec.NewAttr("command", "string", false),
"cap_add": hclspec.NewAttr("cap_add", "list(string)", false),
Expand Down Expand Up @@ -99,8 +103,9 @@ var (

// AuthConfig is the tasks authentication configuration
type AuthConfig struct {
Username string `codec:"username"`
Password string `codec:"password"`
Username string `codec:"username"`
Password string `codec:"password"`
TLSVerify bool `codec:"tls_verify"`
}

// GCConfig is the driver GarbageCollection configuration
Expand Down
7 changes: 5 additions & 2 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,16 +952,19 @@ func (d *Driver) createImage(image string, auth *AuthConfig, forcePull bool, ima
}

d.logger.Info("Pulling image", "image", imageName)

_ = d.eventer.EmitEvent(&drivers.TaskEvent{
TaskID: cfg.ID,
TaskName: cfg.Name,
AllocID: cfg.AllocID,
Timestamp: time.Now(),
Message: "Pulling image " + imageName,
})

imageAuth := api.ImageAuthConfig{
Username: auth.Username,
Password: auth.Password,
TLSVerify: auth.TLSVerify,
Username: auth.Username,
Password: auth.Password,
}

result, err, _ := d.pullGroup.Do(imageName, func() (interface{}, error) {
Expand Down