-
Notifications
You must be signed in to change notification settings - Fork 370
internal/libdocker: add authentication options for docker client #662
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
073df0d
add authentication options for docker client
ea905a9
remove out-of-scope code for custom dockerfile path
4be7d2d
simplify docker authentication config options
mrod502 ace9c68
remove extra newlines
mrod502 3fb367d
Merge branch 'master' into mr/docker-client-authentication
mrod502 9751adf
internal/libdocker: revert change to Connect
fjl 5a09f72
go.work.sum: update
fjl 44d7cda
internal/libdocker: simplify Authenticator
fjl 8081f2d
internal/libdocker: dedup image build options
fjl 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= | ||
| github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= | ||
| github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5 h1:2U0HzY8BJ8hVwDKIzp7y4voR9CX/nvcfymLmg2UiOio= | ||
| github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= |
This file contains hidden or 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 hidden or 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,76 @@ | ||
| package libdocker | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "os" | ||
| "path" | ||
|
|
||
| docker "github.com/fsouza/go-dockerclient" | ||
| ) | ||
|
|
||
| // CredHelpers represents the data stored by default in $HOME/.docker/config.json | ||
| type CredHelpers struct { | ||
| CredHelpers map[string]string `json:"credHelpers"` | ||
| CredsStore string `json:"credsStore"` | ||
| } | ||
|
|
||
| // Authenticator holds the configuration for docker registry authentication. | ||
| type Authenticator interface { | ||
| // AuthConfigs returns the auth configurations for all configured registries. | ||
| AuthConfigs() docker.AuthConfigurations | ||
| } | ||
|
|
||
| func NewCredHelperAuthenticator() (CredHelperAuthenticator, error) { | ||
| authConfigs, err := configureCredHelperAuth() | ||
| return CredHelperAuthenticator{authConfigs}, err | ||
| } | ||
|
|
||
| type CredHelperAuthenticator struct { | ||
| configs docker.AuthConfigurations | ||
| } | ||
|
|
||
| // AuthConfigs returns the auth configurations for all configured registries | ||
| func (c CredHelperAuthenticator) AuthConfigs() (a docker.AuthConfigurations) { | ||
| return c.configs | ||
| } | ||
|
|
||
| // configureCredHelperAuth - configures authentication for the specified registry based on $HOME/.docker/config.json | ||
| func configureCredHelperAuth() (docker.AuthConfigurations, error) { | ||
| authConfigurations := make(map[string]docker.AuthConfiguration) | ||
| credsHelpers, err := loadCredsHelpers() | ||
| if err != nil { | ||
| return docker.AuthConfigurations{}, err | ||
| } | ||
|
|
||
| for registry := range credsHelpers.CredHelpers { | ||
| authConfig, err := docker.NewAuthConfigurationsFromCredsHelpers(registry) | ||
| if err != nil { | ||
| return docker.AuthConfigurations{ | ||
| Configs: authConfigurations, | ||
| }, err | ||
| } | ||
| authConfigurations[registry] = *authConfig | ||
| } | ||
| return docker.AuthConfigurations{Configs: authConfigurations}, nil | ||
| } | ||
|
|
||
| func loadCredsHelpers() (c CredHelpers, err error) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the |
||
| cfgPath, err := dockerConfigPath() | ||
| if err != nil { | ||
| return | ||
| } | ||
| b, err := os.ReadFile(cfgPath) | ||
| if err != nil { | ||
| return | ||
| } | ||
| err = json.Unmarshal(b, &c) | ||
| return | ||
| } | ||
|
|
||
| func dockerConfigPath() (string, error) { | ||
| homeDir, err := os.UserHomeDir() | ||
| if err != nil { | ||
| return homeDir, err | ||
| } | ||
| return path.Join(homeDir, ".docker", "config.json"), nil | ||
| } | ||
This file contains hidden or 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 hidden or 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
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.
Here we just load all of the cred helpers configured in
$HOME/.docker/config.jsonso that a user doesn't need to specify them via command args