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

Support plaintext credentials as multi-call binary #5536

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions cmd/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import (
cliflags "github.com/docker/cli/cli/flags"
"github.com/docker/cli/cli/version"
platformsignals "github.com/docker/cli/cmd/docker/internal/signals"

"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/reexec"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -29,6 +31,10 @@ import (
)

func main() {
if reexec.Init() {
return
}

err := dockerMain(context.Background())
if err != nil && !errdefs.IsCancelled(err) {
_, _ = fmt.Fprintln(os.Stderr, err)
Expand Down
69 changes: 69 additions & 0 deletions cmd/docker/file_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package main

import (
"os"

credhelpers "github.com/docker/docker-credential-helpers/credentials"
"github.com/docker/docker/pkg/reexec"

"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/credentials"
"github.com/docker/cli/cli/config/types"
)

//nolint:gosec // ignore G101: Potential hardcoded credentials
const fileCredsHelperBinary = "docker-credential-file"

func init() {
reexec.Register(fileCredsHelperBinary, serveFileCredHelper)
}

func serveFileCredHelper() {
configfile := config.LoadDefaultConfigFile(os.Stderr)
store := credentials.NewFileStore(configfile)
credhelpers.Serve(&FileHelper{
fileStore: store,
})
}

var _ credhelpers.Helper = &FileHelper{}

type FileHelper struct {
fileStore credentials.Store
}

func (f *FileHelper) Add(creds *credhelpers.Credentials) error {
return f.fileStore.Store(types.AuthConfig{
Username: creds.Username,
Password: creds.Secret,
ServerAddress: creds.ServerURL,
})
}

func (f *FileHelper) Delete(serverAddress string) error {
return f.fileStore.Erase(serverAddress)
}

func (f *FileHelper) Get(serverAddress string) (string, string, error) {
authConfig, err := f.fileStore.Get(serverAddress)
if err != nil {
return "", "", err
}

return authConfig.Username, authConfig.Password, nil
}

func (f *FileHelper) List() (map[string]string, error) {
creds := make(map[string]string)

authConfig, err := f.fileStore.GetAll()
if err != nil {
return nil, err
}

for k, v := range authConfig {
creds[k] = v.Username
}

return creds, nil
}
26 changes: 26 additions & 0 deletions vendor/github.com/docker/docker/pkg/reexec/command_linux.go

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

19 changes: 19 additions & 0 deletions vendor/github.com/docker/docker/pkg/reexec/command_other.go

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

12 changes: 12 additions & 0 deletions vendor/github.com/docker/docker/pkg/reexec/command_unsupported.go

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

64 changes: 64 additions & 0 deletions vendor/github.com/docker/docker/pkg/reexec/reexec.go

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

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ github.com/docker/docker/pkg/longpath
github.com/docker/docker/pkg/pools
github.com/docker/docker/pkg/process
github.com/docker/docker/pkg/progress
github.com/docker/docker/pkg/reexec
github.com/docker/docker/pkg/stdcopy
github.com/docker/docker/pkg/streamformatter
github.com/docker/docker/pkg/stringid
Expand Down
Loading