Skip to content

make docker-credential-wincred work like docker-credential-osxkeychain - #139

Merged
vdemeester merged 3 commits into
docker:masterfrom
ekcasey:server-alias-wincred
Apr 30, 2019
Merged

make docker-credential-wincred work like docker-credential-osxkeychain#139
vdemeester merged 3 commits into
docker:masterfrom
ekcasey:server-alias-wincred

Conversation

@ekcasey

@ekcasey ekcasey commented Apr 3, 2019

Copy link
Copy Markdown
Contributor
  • fetch credentials for server with matching hostname if scheme, path, or port are not provided
  • if the credential request includes specific scheme, path, or port that does not match entry, don't return
  • extract url helpers into a package

Signed-off-by: Danny Joyce djoyce@pivotal.io
Signed-off-by: Emily Casey ecasey@pivotal.io

@ekcasey

ekcasey commented Apr 3, 2019

Copy link
Copy Markdown
Contributor Author

This fixes issues fetching docker credentials in libraries like https://github.com/google/go-containerregistry that resolve Docker Hub registry url differently (https://index.docker.io vs https://index.docker.io/v1)

@ekcasey

ekcasey commented Apr 4, 2019

Copy link
Copy Markdown
Contributor Author

@vdemeester It looks like the Travis build is broken for reasons unrelated to our changes. If that is not a correct diagnosis, let @djoyahoy and I know so we fix it :)

@guillaumerose

Copy link
Copy Markdown
Contributor

CI is now fixed. Can you rebase ? Thanks

* fetch credentials for server with matching hostname if scheme, path, or port are not provided
* if the credential request includes specific scheme, path, or port that does not match entry, don't return
* extract url helpers into a package

Signed-off-by: Emily Casey <ecasey@pivotal.io>
Signed-off-by: Danny Joyce <djoyce@pivotal.io>
@ekcasey
ekcasey force-pushed the server-alias-wincred branch from fe0ee73 to 6f4b0a7 Compare April 29, 2019 13:27
@ekcasey

ekcasey commented Apr 29, 2019

Copy link
Copy Markdown
Contributor Author

@guillaumerose done!

Comment thread osxkeychain/osxkeychain_darwin.go Outdated
import (
"errors"
"net/url"
"github.com/docker/docker-credential-helpers/registryurl"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit picking: Can you re-order the imports? goimports should do that for you 😺

Comment thread wincred/wincred_windows.go Outdated

import (
"bytes"
"github.com/docker/docker-credential-helpers/registryurl"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please re-organize the imports here too

func getTarget(serverURL string) (string, error) {
s, err := registryurl.Parse(serverURL)
if err != nil {
return serverURL, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return empty string here instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We returned the serverURL here b/c before we made our changes there was never a requirement that the url had to parse successfully (you could still fetch an exact match from the cred store). Happy to change this if you want to make this a requirement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right read it too fast, you return a nil error. That's fine then 👍

Signed-off-by: Emily Casey <ecasey@pivotal.io>
Comment thread wincred/wincred_windows.go Outdated
return "", err
}

targets := make([]string, 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: var targets []string

Comment thread wincred/wincred_windows.go Outdated
for i := range creds {
attrs := creds[i].Attributes
for _, attr := range attrs {
if strings.Compare(attr.Keyword, "label") == 0 &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the documentation: https://golang.org/pkg/strings/#Compare

Compare is included only for symmetry with package bytes. It is usually clearer and always faster to use the built-in string comparison operators ==, <, >, and so on.

So I guess if attr.Keyword == "label" is simpler 😸

Comment thread wincred/wincred_windows.go Outdated
attrs := creds[i].Attributes
for _, attr := range attrs {
if strings.Compare(attr.Keyword, "label") == 0 &&
bytes.Compare(attr.Value, []byte(credentials.CredsLabel)) == 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use bytes.Equal instead.
What is the real type behind attr.Value? Is it an arbitrary byte slice? Or always a string encoded into bytes? My point is: even if the result is the same, I think it's more clearer to cast attr.Value as string instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece of code existed before our PR so weren't sure if attr.Value needed to be a byte slice for a specific reason, happy to make the changes though.

}
}

if target, found := findMatch(s, targets, exactMatch); found {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed? Can't we just match with approximation? What is the targets length ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We assumed that if there were both an exact and an approximate match in the cred store, the exact match would be preferable. We can take the exact match out if you disagree.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 😄 Ok then 👍

Signed-off-by: Emily Casey <ecasey@pivotal.io>
Signed-off-by: Danny Joyce <djoyce@pivotal.io>

@silvin-lubecki silvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @ekcasey for the fixes 👍

@vdemeester vdemeester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐅

@vdemeester
vdemeester merged commit 152d643 into docker:master Apr 30, 2019
@ekcasey

ekcasey commented Apr 30, 2019

Copy link
Copy Markdown
Contributor Author

Thanks everybody!

thaJeztah added a commit to thaJeztah/cli that referenced this pull request Jun 11, 2019
full diff: docker/docker-credential-helpers@5241b46...8a9f93a

includes:

- docker/docker-credential-helpers#29 C.free(unsafe.Pointer(err)) -> C.g_error_free(err)
- docker/docker-credential-helpers#124 pass: changed the way for checking if password-store is initalized
  - addresses docker/docker-credential-helpers#133 docker-credential-pass commits about 10 times every time I run a docker command
- docker/docker-credential-helpers#143 Fix docker-credential-osxkeychain list behaviour in case of missing entry in keychain
- docker/docker-credential-helpers#139 make docker-credential-wincred work like docker-credential-osxkeychain

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Jun 20, 2019
full diff: docker/docker-credential-helpers@5241b46...8a9f93a

includes:

- docker/docker-credential-helpers#29 C.free(unsafe.Pointer(err)) -> C.g_error_free(err)
- docker/docker-credential-helpers#124 pass: changed the way for checking if password-store is initalized
  - addresses docker/docker-credential-helpers#133 docker-credential-pass commits about 10 times every time I run a docker command
- docker/docker-credential-helpers#143 Fix docker-credential-osxkeychain list behaviour in case of missing entry in keychain
- docker/docker-credential-helpers#139 make docker-credential-wincred work like docker-credential-osxkeychain

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: f6a4c76fbb6d594f4874dea5059e82eadfae867a
Component: cli
thaJeztah added a commit to thaJeztah/cli that referenced this pull request Jul 4, 2019
full diff: docker/docker-credential-helpers@5241b46...8a9f93a

includes:

- docker/docker-credential-helpers#29 C.free(unsafe.Pointer(err)) -> C.g_error_free(err)
- docker/docker-credential-helpers#124 pass: changed the way for checking if password-store is initalized
  - addresses docker/docker-credential-helpers#133 docker-credential-pass commits about 10 times every time I run a docker command
- docker/docker-credential-helpers#143 Fix docker-credential-osxkeychain list behaviour in case of missing entry in keychain
- docker/docker-credential-helpers#139 make docker-credential-wincred work like docker-credential-osxkeychain

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit f6a4c76)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/cli that referenced this pull request Jul 4, 2019
full diff: docker/docker-credential-helpers@5241b46...8a9f93a

includes:

- docker/docker-credential-helpers#29 C.free(unsafe.Pointer(err)) -> C.g_error_free(err)
- docker/docker-credential-helpers#124 pass: changed the way for checking if password-store is initalized
  - addresses docker/docker-credential-helpers#133 docker-credential-pass commits about 10 times every time I run a docker command
- docker/docker-credential-helpers#143 Fix docker-credential-osxkeychain list behaviour in case of missing entry in keychain
- docker/docker-credential-helpers#139 make docker-credential-wincred work like docker-credential-osxkeychain

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit f6a4c76)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/cli that referenced this pull request Jul 23, 2019
full diff: docker/docker-credential-helpers@5241b46...8a9f93a

includes:

- docker/docker-credential-helpers#29 C.free(unsafe.Pointer(err)) -> C.g_error_free(err)
- docker/docker-credential-helpers#124 pass: changed the way for checking if password-store is initalized
  - addresses docker/docker-credential-helpers#133 docker-credential-pass commits about 10 times every time I run a docker command
- docker/docker-credential-helpers#143 Fix docker-credential-osxkeychain list behaviour in case of missing entry in keychain
- docker/docker-credential-helpers#139 make docker-credential-wincred work like docker-credential-osxkeychain

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit f6a4c76)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/cli that referenced this pull request Aug 8, 2019
full diff: docker/docker-credential-helpers@5241b46...8a9f93a

includes:

- docker/docker-credential-helpers#29 C.free(unsafe.Pointer(err)) -> C.g_error_free(err)
- docker/docker-credential-helpers#124 pass: changed the way for checking if password-store is initalized
  - addresses docker/docker-credential-helpers#133 docker-credential-pass commits about 10 times every time I run a docker command
- docker/docker-credential-helpers#143 Fix docker-credential-osxkeychain list behaviour in case of missing entry in keychain
- docker/docker-credential-helpers#139 make docker-credential-wincred work like docker-credential-osxkeychain

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit f6a4c76)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Aug 8, 2019
full diff: docker/docker-credential-helpers@5241b46...8a9f93a

includes:

- docker/docker-credential-helpers#29 C.free(unsafe.Pointer(err)) -> C.g_error_free(err)
- docker/docker-credential-helpers#124 pass: changed the way for checking if password-store is initalized
  - addresses docker/docker-credential-helpers#133 docker-credential-pass commits about 10 times every time I run a docker command
- docker/docker-credential-helpers#143 Fix docker-credential-osxkeychain list behaviour in case of missing entry in keychain
- docker/docker-credential-helpers#139 make docker-credential-wincred work like docker-credential-osxkeychain

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit f6a4c76fbb6d594f4874dea5059e82eadfae867a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 24dcc56123634e048dc0c7d8fa2eeff65b97a33a
Component: cli
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Aug 8, 2019
full diff: docker/docker-credential-helpers@5241b46...8a9f93a

includes:

- docker/docker-credential-helpers#29 C.free(unsafe.Pointer(err)) -> C.g_error_free(err)
- docker/docker-credential-helpers#124 pass: changed the way for checking if password-store is initalized
  - addresses docker/docker-credential-helpers#133 docker-credential-pass commits about 10 times every time I run a docker command
- docker/docker-credential-helpers#143 Fix docker-credential-osxkeychain list behaviour in case of missing entry in keychain
- docker/docker-credential-helpers#139 make docker-credential-wincred work like docker-credential-osxkeychain

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit f6a4c76fbb6d594f4874dea5059e82eadfae867a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 11b15544c503d91d8ea3ba782d30d2070a24d84e
Component: cli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants