1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-28 15:21:29 +05:30

Compare commits

..

142 Commits

Author SHA1 Message Date
Nassim Eddequiouaq 5241b46610 Merge pull request #110 from euank/lazy-init
pass: only init on run, and do so lazily
2018-06-27 14:33:29 +02:00
Vincent Demeester 3cba3913ea pass: add IsInitialized helper
This will be useful for the cli where they check initialization:
https://github.com/docker/cli/blob/be8dab26a3ab589b96788fdb95f3d07378e57b9b/cli/config/credentials/default_store_linux.go#L8-L10

Signed-off-by: Euan Kemp <euank@euank.com>
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-27 14:28:47 +02:00
Vincent Demeester 8502b53592 Merge pull request #108 from euank/pass-trim‮‮‮‮‮‮‮‮trim-pass
pass: trim pass show output
2018-06-27 14:24:08 +02:00
Euan Kemp 5da09fd251 pass: only init on run, and do so lazily
This also fixes the following issues:

1. Safe for concurrent initialization still (it was before in 'init',
   but the alternative to this PR is not)
2. Uses the same password directory during init as it does during
   runtime (the change to getPassDir in initialization logic.
3. Prints significantly better errors if initialization fails
4. Has slightly cleaner abstractions by hiding the initialization check
   in 'runPass'

The 4th item there does mean there are a few cases where more work is
done before erroring, but that amount of work is trivial and my manual
audit didn't reveal anything that seemed worrying.

Fixes #96, alternative to #106

Signed-off-by: Euan Kemp <euank@euank.com>
2018-06-27 14:23:22 +02:00
Euan Kemp dd27c246bd pass: trim pass show output
As of 8446a40, pass show will include a newline when showing a password.
This causes the pass helper here to reliably fail to initialize since a
password doesn't round-trip.

Before making this change, the pass test would fail if the installed
password-store version was v1.7.1+, and after this change it passes
again.

Fixes #107

Signed-off-by: Euan Kemp <euank@euank.com>
2018-06-27 14:21:52 +02:00
Vincent Demeester 26deb2937d Merge pull request #109 from euank/better-exec
pass: simplify some code
2018-06-27 14:19:27 +02:00
Euan Kemp a13ff50017 pass: simplify some code
The exec.Command code and os.Getenv implementation were both needlessly
verbose. This replaces them with simpler variations.

Signed-off-by: Euan Kemp <euank@euank.com>
2018-06-27 14:15:36 +02:00
Vincent Demeester 1c295f7de8 Merge pull request #115 from n4ss/fix-appveyor
Fix Windows CI
2018-06-27 14:14:13 +02:00
Nassim 'Nass' Eddequiouaq 093af814ee fix go vet complaining on composite literales
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2018-06-27 14:02:28 +02:00
Vincent Demeester d499cf5cb9 Merge pull request #114 from n4ss/fix-travisci-osxkeychain
fix osxkeychain ci
2018-06-27 13:52:26 +02:00
Nassim 'Nass' Eddequiouaq b049338a6b Fix appveyor windows ci
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2018-06-27 13:45:32 +02:00
Nassim 'Nass' Eddequiouaq 91fc39d57a install yarn on osx for travisci
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2018-06-27 13:22:53 +02:00
Nassim 'Nass' Eddequiouaq 317219f3a6 Fix yarn complaint in travisci
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2018-06-27 12:13:18 +02:00
Nassim 'Nass' Eddequiouaq 21f4937ebc fix osxkeychain ci
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2018-06-27 11:58:22 +02:00
Vincent Demeester 19b711cc92 Merge pull request #100 from vdemeester/update-maintainers
Update MAINTAINERS file with current maintainers
2018-02-14 08:13:21 +01:00
Vincent Demeester 1f635a73ad Update MAINTAINERS file with current maintainers
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-02-12 14:39:43 +01:00
Jean-Laurent de Morlhon d68f9aeca3 Merge pull request #88 from n4ss/add-pass-config-notice
Add instructions for pass helper configuration
2017-08-30 14:17:07 +02:00
Vincent Demeester 05a9d4c50d Merge pull request #89 from tych0/better-initialization-check
pass: better initialization check
2017-08-29 21:46:31 +02:00
Tycho Andersen c2eec534ee pass: better initialization check
See comment for details, but basically, let's actually use pass to check
that it works.

Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-29 08:25:08 -07:00
Nassim 'Nass' Eddequiouaq 5be80ca212 Add instructions for pass helper configuration
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-08-28 18:11:27 +02:00
Vincent Demeester f00de1b72f Merge pull request #87 from n4ss/bump-0.6.0
Bump 0.6.0
2017-08-28 14:18:12 +02:00
Nassim 'Nass' Eddequiouaq 72f0375e37 Bump 0.6.0
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-08-25 19:37:31 +02:00
Nassim Eddequiouaq 3cce61446f Merge pull request #85 from promiseofcake/ljk-fix-makefile
Fix Makefile issues
2017-08-25 18:50:05 +02:00
Lucas Kacher ec0d036273 Fix Makefile issues
* mkdir fails when `bin` exists
* obtaining golint fails if previously installed (w/out the -u flag)

Signed-off-by: Lucas Kacher <lucas@vsco.co>
2017-08-23 11:08:54 -04:00
Vincent Demeester d3d9934897 Merge pull request #84 from tych0/fix-helpers-protocol
return "" instead of an error when pass isn't present
2017-08-22 20:10:46 +02:00
Tycho Andersen f212ea17df fix test
Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-17 10:36:48 -06:00
Tycho Andersen 09e536a128 return "" instead of an error when pass isn't present
It turns out the cred helpers protocol is to return "" and not an error
when a credential isn't present, so let's do that.

Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-17 09:19:19 -06:00
Vincent Demeester 3c90bd29a4 Merge pull request #83 from tych0/expose-pass-initialized
pass backend: expose pass initialized flag
2017-08-16 11:06:21 +02:00
Tycho Andersen b8fb9690c8 pass backend: expose pass initialized flag
This way clients don't have to run their own checks, they can just use the
library's detection.

Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-14 08:56:59 -06:00
Vincent Demeester 7efaffb4c4 Merge pull request #81 from tych0/pass-backend-and-package
Add `pass` backend and debian packaging for both -secretservice and -pass backends
2017-08-14 16:00:25 +02:00
Nassim Eddequiouaq 6338c06ba4 Merge pull request #69 from shhsu/command_env
A new entry point for calling the cred helpers that allow passing environment variables
2017-08-14 11:15:13 +02:00
Tycho Andersen 86c94d3e30 add a deb package for pass/secret service backends
Note that this single source package produces two binary packages: one for
-pass, and one for -secretservice, so that users can install whichever
password backend (and thus deps) that they want.

Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-11 08:15:29 -06:00
Tycho Andersen 1ab1037707 add a pass credential helper backend
Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-11 08:15:29 -06:00
Peter Hsu c69c0725bb A new entry point for calling the cred helpers that allow passing environment variables
Signed-off-by: Peter Hsu <shhsu@microsoft.com>
2017-06-30 10:45:22 -07:00
Nassim Eddequiouaq a8de4f6e8a Merge pull request #77 from jeanlaurent/win-release
Adding winrelease target
2017-06-15 12:39:03 +02:00
Jean-Laurent de Morlhon 4fbc86d7d0 Adding winrelease target
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-06-15 12:03:00 +02:00
Vincent Demeester 2d19ebb7f4 Merge pull request #76 from thaJeztah/bump-0.5.2
Bump version 0.5.2
2017-06-15 11:31:05 +02:00
Sebastiaan van Stijn 054c53824f Bump version 0.5.2
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 11:21:41 +02:00
Sebastiaan van Stijn be1808e3ed Merge pull request #75 from thaJeztah/update-changelog
Update changelog
2017-06-15 11:07:09 +02:00
Sebastiaan van Stijn e1d4c012bc Fix storing URLs without scheme (#72)
* Fix storing URLs without scheme

If secrets are stored without specifying a scheme
(https://), the keychain-helper would interpret the
hostname as _path_, causing lookup of secrets to fail.

This patch makes sure that a scheme is added (if missing).

If no scheme is specified, https:// is used as a default.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

* Have pre go1.8 compiler able to compile

Signed-off-by: Tibor Vass <teabee89@gmail.com>

* Fix URL parsing with port and no scheme

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>

* Improve parseURL comment

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-06-15 10:58:17 +02:00
Sebastiaan van Stijn ad6ee5d58d Update changelog
The changelog wasn't updated for each release.

This patch updates the changelog, with changes
taken from the releases page

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 00:46:21 +02:00
Nassim Eddequiouaq 94be56b6f4 Merge pull request #74 from thaJeztah/bump-travis-to-go-18
Update TravisCI to use Go 1.8
2017-06-14 22:08:13 +02:00
Sebastiaan van Stijn 37bf8afe8b Update TravisCI to use Go 1.8
To match the version used in docker

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-14 21:29:13 +02:00
Nassim Eddequiouaq 3d7e1817f2 Merge pull request #73 from n4ss/travisci-golang1.7
Update TravisCI to use Go 1.7
2017-06-14 17:21:44 +02:00
Nassim 'Nass' Eddequiouaq 5651367281 Update TravisCI to use Go 1.7
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-06-14 16:18:01 +02:00
Nassim Eddequiouaq d8f57a18c6 Merge pull request #61 from danieljoos/linux32
Workaround for Linux 32-bit build
2017-05-30 20:56:52 +02:00
Sebastiaan van Stijn 4bc0bc2a85 Merge pull request #67 from jeanlaurent/add-version-command
Add version command
2017-05-30 19:13:34 +02:00
Jean-Laurent de Morlhon 167b137eb4 vet/lint/fmt before release
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-05-30 18:26:18 +02:00
Jean-Laurent de Morlhon 2a67ef1524 make linter happy
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-05-30 18:26:18 +02:00
Jean-Laurent de Morlhon 6ba4edf6e9 Read version from sources
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-05-30 18:26:18 +02:00
Jean-Laurent de Morlhon fa4a4d4f71 Bump Version 0.5.1-> 0.5.2-devel
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-05-30 18:26:18 +02:00
Jean-Laurent de Morlhon 4d60b372aa Add a version command
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-05-30 18:26:18 +02:00
Vincent Demeester 607bf3c174 Merge pull request #68 from jeanlaurent/appveyor-build
AppVeyor build
2017-05-30 08:05:06 -07:00
Jean-Laurent de Morlhon 74f4f75bc1 AppVeyor build
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-05-30 11:59:52 +02:00
Jean-Laurent de Morlhon 0e7779e5a1 Merge pull request #66 from n4ss/release-v0.5.1
Update version tag to v0.5.1
2017-05-29 16:44:20 +02:00
Nassim 'Nass' Eddequiouaq fb9549d396 Update version tag
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-05-29 16:32:21 +02:00
Nassim Eddequiouaq ed11c58ebf Prevent invalid credentials: no missing server URL or username (#62)
* Prevent invalid credentials: no missing server URL or username

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>

* Add missing username/serverURL error checks in credstore client

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>

* Clean up doc on invalid creds errors and client's error checks

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>

* Add tests for missing ServerURL/Username

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>

* Clean isValidCredsMessage prototype

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>

* Add test for missing server URL and more detailed error msg

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-05-29 10:21:50 +02:00
Vincent Demeester 79ab7059b0 Merge pull request #64 from shhsu/redirect_stderr
Caller of cred helpers would now see the stderr returns from cred helpers
2017-05-26 09:25:21 -07:00
shhsu@microsoft.com 18d35e4984 Caller of cred helpers would now see the stderr returns from cred helpers
Signed-off-by: shhsu@microsoft.com <shhsu@microsoft.com>
2017-05-24 15:41:34 -07:00
Daniel Joos cdde659563 Workaround for Linux 32-bit build
This adds a workaround for the `secretservice` sub-package to build under 32bit Linux.
It limits the total number of list entries to (2^29)-1.
A short explanation of how this number was calculated has been added in a comment.

Signed-off-by: Daniel Joos <daniel@joosweb.de>
2017-05-10 00:38:33 +02:00
Vincent Demeester 71779cf7f5 Merge pull request #56 from simonferquel/align-get-with-list-filtering
[Windows] align get with list behavior
2017-03-22 09:53:49 +01:00
Simon Ferquel 51c78cdc14 [Windows] align get with list behavior
Avoiding to get unlabelled credentials

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
2017-03-16 18:16:37 +01:00
Vincent Demeester 120e37f15d Merge pull request #54 from vdemeester/update-maintainers
Add n4ss as maintainer 👼
2017-03-14 19:30:38 +01:00
Vincent Demeester 4962f775bf Add n4ss as maintainer 👼
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2017-03-14 16:04:27 +01:00
Jean-Laurent de Morlhon ce617b3357 Merge pull request #52 from jeanlaurent/run-test-on-release
Clean and run test before osx release
2017-03-13 16:45:02 -07:00
Jean-Laurent de Morlhon f3071aff0a Merge pull request #53 from n4ss/fix-windows-typos-tests
Fix syntax typos and tests implementation for Windows
2017-03-13 16:44:48 -07:00
Nassim 'Nass' Eddequiouaq 1515d4547e Fix syntax typos and tests implementation for windows
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-13 14:51:03 -07:00
Jean-Laurent de Morlhon f67589c36e Clean and run test before osx release
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-03-13 12:49:05 -07:00
Vincent Demeester 479de2a4f5 Merge pull request #45 from jeanlaurent/fix-mkdir
Remove mkdir -p where neccessary
2017-03-13 20:43:59 +01:00
Vincent Demeester cdba2ced06 Merge pull request #44 from jeanlaurent/osxrelease-task
Add a osx release target to the makefile to ease releasing.
2017-03-13 20:43:49 +01:00
Nassim Eddequiouaq 7f0538cd5e Merge pull request #50 from n4ss/fix-secserv-tests
Fix secretservice tests and expected behaviors
2017-03-13 11:56:46 -07:00
Nassim Eddequiouaq 14381bf0d6 Merge pull request #49 from n4ss/label-creds
Label credentials on each platform' creds store and fix secretservice behavior
2017-03-13 11:22:23 -07:00
Nassim 'Nass' Eddequiouaq 7133af577e Creds label can be configured from helpers
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-11 12:34:22 +01:00
Nassim 'Nass' Eddequiouaq 2f2e85cfb9 Remove unnecessary creds list's size check
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 16:59:57 +01:00
Nassim 'Nass' Eddequiouaq 47566329ff Fix secretservice tests and expected behaviors
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 07:29:25 -08:00
Nassim 'Nass' Eddequiouaq b9d19b479a Return empty server-url to usernames map if no search results
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:23:43 +01:00
Nassim 'Nass' Eddequiouaq e522e56699 Fix memory leaks and non-null terminated strings usage
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:23:17 +01:00
Nassim 'Nass' Eddequiouaq 8cb3338668 Filter docker credentials with label directly through libsecret
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:18:14 +01:00
Nassim 'Nass' Eddequiouaq cd76e4253f Use the proper docker secret schema for items to search for
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:15:05 +01:00
Nassim 'Nass' Eddequiouaq 021d7d6a19 Add label filter on the list of secrets
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:14:34 +01:00
Nassim 'Nass' Eddequiouaq 2a8670e0da Cleanup original modifications to the exposed APIs
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:14:04 +01:00
Nassim 'Nass' Eddequiouaq c5fbd3a5ad Fix type conversion for labels added to search queries on macOS
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:12:53 +01:00
Nassim 'Nass' Eddequiouaq c6cf8aa13b Add Label to Credentials in test files
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:12:32 +01:00
Nassim 'Nass' Eddequiouaq cfe7556d6d [SYNTAX] Run gofmt on changed files
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:12:12 +01:00
Nassim 'Nass' Eddequiouaq 23a1f310a5 Add a Docker Credentials label support for windows
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:11:57 +01:00
Nassim 'Nass' Eddequiouaq f7f2744e6d Add a Docker Credentials label support for linux
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:11:25 +01:00
Nassim 'Nass' Eddequiouaq 406812bf8e Add a Docker Credentials label support for macOS
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:11:13 +01:00
Nassim 'Nass' Eddequiouaq 595b7f2531 Add a Docker Credentials label to store and list creds
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
2017-03-10 15:10:54 +01:00
Jean-Laurent de Morlhon ad4463616e Remove mkdir -p where neccessary
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-03-03 18:51:21 +01:00
Jean-Laurent de Morlhon 365da011fb Add a osx release target to the makefile to ease releasing.
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-03-03 18:49:23 +01:00
Vincent Demeester 1057cf7f86 Merge pull request #43 from jeanlaurent/windows-makefile
Add .exe to windows Makefile target
2017-03-03 18:03:14 +01:00
Jean-Laurent de Morlhon 40d06d0090 Add .exe to windows Makefile target
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-03-03 17:58:06 +01:00
Vincent Demeester de50f50ab0 Merge pull request #41 from jeanlaurent/codesign
Add a makefile target to codesign output binary on macOS
2017-03-03 17:56:55 +01:00
Vincent Demeester 3c3e1d3af1 Merge pull request #42 from ebriney/fix-keychain-list
Reconstruct the full url when doing `keychain_list`
2017-03-03 17:56:15 +01:00
Emmanuel Briney 19ec1c3164 reconstruct the full url when doing keychain_list
Signed-off-by: Emmanuel Briney <emmanuel.briney@docker.com>
2017-03-03 17:16:00 +01:00
Jean-Laurent de Morlhon 2a3f7a4468 Add a makefile target to codesign output binary on macOS
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
2017-03-03 16:20:29 +01:00
Vincent Demeester b7c53e02cd Merge pull request #40 from ebriney/osx10.10-10.11-compatibility
Add cgo flags to support older version of OSX (10.10, 10.11)
2017-02-21 10:55:47 +01:00
Emmanuel Briney 94963d0da8 osxkeychain: add cgo flags to support older version of OSX
Signed-off-by: Emmanuel Briney <emmanuel.briney@docker.com>
2017-02-21 10:41:54 +01:00
Vincent Demeester 2514d5e8b2 Merge pull request #39 from docker/release-v0.4.0
Prepare v0.4.0 release
2017-02-16 15:55:09 +01:00
Vincent Demeester 01ed4b811b Merge pull request #26 from danieljoos/master
Updated wincred vendor & fixed Windows build
2017-02-16 15:52:37 +01:00
Vincent Demeester 9b6be7c243 Merge pull request #28 from KingEmet/patch-1
Update README.md
2017-02-16 11:41:56 +01:00
Vincent Demeester f853612e07 Prepare v0.4.0 release
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2017-02-16 11:19:45 +01:00
Brian Goff 69c9d2eab8 Merge pull request #38 from ebriney/mac-delete-before-adding
mac: delete credentials before adding them
2017-02-15 08:44:08 -05:00
ebriney eecc09c974 mac: delete credentials before adding them to avoid already exist error (fixes #37)
Signed-off-by: ebriney <emmanuel.briney@docker.com>
2017-02-14 22:50:44 +01:00
KingEmet 48079a964a add 'list' to API list
Signed-off-by: KingEmet <jsand@google.com>
2016-09-07 15:59:21 -07:00
Daniel Joos cfbce1c845 Removed unnecessary lines in wincred_windows.go
Those lines seem to be left from the last merge.
They cause build errors on Windows.

Signed-off-by: Daniel Joos <daniel@joosweb.de>
2016-09-07 09:59:03 +02:00
Daniel Joos a994ca1d54 Updated vendor pkg: github.com/danieljoos/wincred
This includes the following changes:
- Removed need for `C`
- Added some null checks to avoid possible panics
- `List` returns an empty list instead of an error, in case no credentials
  are installed on the system

Signed-off-by: Daniel Joos <daniel@joosweb.de>
2016-09-07 09:58:33 +02:00
Antonio Murdaca f72c04f1d8 Merge pull request #25 from KingEmet/master
Implement client.List, change list API
2016-09-06 18:43:16 +02:00
Jake Sanders c45d9e9e28 Implement client.List, change list API
[]string, []string -> map[string]string because the other APIs assume a
1:1 correspondence

Signed-off-by: Jake Sanders <jsand@google.com>
2016-09-02 15:15:12 -07:00
David Calavera 80833adff5 Merge pull request #18 from avaid96/listing
Implementing listing functionality across OSX, Linux and Windows
2016-07-20 13:55:38 -07:00
avaid96 f1498a0524 go fmt is all osx files and general files
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-16 12:19:47 -07:00
Avi Vaid c2abee4c0c go fmt in windows files
Signed-off-by: Avi Vaid <avaid1996@gmail.com>
2016-07-16 12:18:03 -07:00
avaid96 9e96a4905d fixed issue with wincred
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-16 12:09:31 -07:00
avaid96 cf9b6df432 fixed issue with wincred
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-16 12:08:55 -07:00
avaid96 b0c64357eb fixed issue with the windows test
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-16 12:07:50 -07:00
avaid96 5b764cc13a changes to wincred, completes list functionality in windows
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-16 11:59:43 -07:00
avaid96 b63a32e7a2 fixed another bug in the test for osx
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-15 17:46:46 -07:00
avaid96 173fe2dbc2 fixed a bug in the test for osx
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-15 17:43:52 -07:00
avaid96 b3ebaa455d trying to the OSX test to pass on Travis, it passes locally
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-15 17:32:47 -07:00
avaid96 029e094488 removed a semicolon and the placeholder for the error which we used to locate it. Seems like SecItemCopyMatching is giving an error for some reason- no error on local machine
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-13 14:36:14 -07:00
avaid96 8fa18eb16c implementation on client side as well, complete with tests
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-13 10:20:51 -07:00
avaid96 887a66459a I think OSX tests were failing because it was a list against an empty keychain, checking whether that is the case by filling it first
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-12 10:52:06 -07:00
Avi Vaid d2e6ed779a moved loop variable declaration to comply with c mode in travis
Signed-off-by: Avi Vaid <avaid1996@gmail.com>
2016-07-12 12:51:30 -04:00
avaid96 9557dc3c3f fixing a vet issue
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-12 00:04:34 -07:00
Avi Vaid 59b3d54595 added better test for list in linux
Signed-off-by: Avi Vaid <avaid1996@gmail.com>
2016-07-12 02:52:44 -04:00
avaid96 205e3b3056 cleaned up some of the osx code, added a better test for list
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-11 23:34:20 -07:00
Avi Vaid 7566a1e399 implemented freeing memory in secretservice and made minor edits to osxkeychain
Signed-off-by: Avi Vaid <avaid1996@gmail.com>
2016-07-11 19:45:37 -04:00
Avi Vaid 72661b3103 Implemented list functionality for secretservice- linux
Signed-off-by: Avi Vaid <avaid1996@gmail.com>
2016-07-11 19:33:35 -04:00
avaid96 5a8fb214ed Full implementation for OSX ready
Signed-off-by: avaid96 <avaid1996@gmail.com>
2016-07-11 10:50:44 -07:00
David Calavera 5128fa1bad Release v0.3.0.
Signed-off-by: David Calavera <david.calavera@gmail.com>
2016-05-31 17:41:15 -07:00
Vincent Demeester fee9277aa7 Merge pull request #15 from calavera/client
Add client functions to allow integrations within other CLIs.
2016-06-01 00:08:41 +02:00
David Calavera d80b179703 Merge pull request #16 from calavera/maintainers_file
Add maintainers file.
2016-05-31 14:52:43 -07:00
David Calavera c4fc9c07dd Add client functions to allow integrations within other CLIs.
This is a simplification of how the docker engine implements
this feature, but it will be ported there once this is merged.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2016-05-30 12:32:26 -07:00
David Calavera 2c63e775b4 Add maintainers file.
Signed-off-by: David Calavera <david.calavera@gmail.com>
2016-05-27 18:19:08 -07:00
David Calavera 00703eb6db Merge pull request #13 from calavera/export_helpers
Publish helper structs and methods.
2016-03-24 15:56:00 -07:00
David Calavera df8c7a02f1 Publish helper structs and methods.
Signed-off-by: David Calavera <david.calavera@gmail.com>
2016-03-24 15:08:17 -07:00
David Calavera 4b8917b1cf Merge pull request #12 from calavera/export_library
Export credentials functions to be able to use them as a library.
2016-03-24 13:32:25 -07:00
David Calavera 039c315f22 Export credentials functions to be able to use them as a library.
Signed-off-by: David Calavera <david.calavera@gmail.com>
2016-03-24 14:52:17 -04:00
David Calavera 6bbb56ae3c Merge pull request #11 from mgreau/fix-doc
Update related to the move to Docker Organization
2016-03-18 13:21:15 -07:00
Maxime Gréau ec937eebe2 Update related to the move to Docker Organization
- Fix link to project releases
  - Fix go command

Signed-off-by: Maxime Gréau <greaumaxime@gmail.com>
2016-03-17 00:18:01 +01:00
David Calavera fa24bb8912 Merge pull request #10 from calavera/release_description
Add a link to the Changelog in each release.
2016-03-15 10:27:01 -07:00
David Calavera 76055c2deb Add a link to the Changelog in each release.
Signed-off-by: David Calavera <david.calavera@gmail.com>
2016-03-14 14:04:17 -04:00
44 changed files with 2223 additions and 193 deletions
+1
View File
@@ -1 +1,2 @@
bin bin
release
+9 -2
View File
@@ -3,19 +3,26 @@
sudo: required sudo: required
language: go language: go
dist: trusty dist: trusty
osx_image: xcode9
os: os:
- linux - linux
- osx - osx
notifications: notifications:
email: false email: false
go: go:
- 1.6 - 1.8.1
install: make deps before_install:
# work-around for issue https://github.com/travis-ci/travis-ci/issues/6307
# might not be necessary in the future
- command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
- rvm get stable
addons: addons:
apt: apt:
packages: packages:
- libsecret-1-dev - libsecret-1-dev
- pass
before_script: before_script:
- make deps
- "export DISPLAY=:99.0" - "export DISPLAY=:99.0"
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sh ci/before_script_linux.sh; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sh ci/before_script_linux.sh; fi
- make validate - make validate
+46
View File
@@ -4,6 +4,52 @@ This changelog tracks the releases of docker-credential-helpers.
This project includes different binaries per platform. This project includes different binaries per platform.
The platform released is identified after the tag name. The platform released is identified after the tag name.
## v0.6.0 (Go client, Linux)
- New credential helper on Linux using `pass`
- New entry point for passing environment variables when calling a credential helper
- Add a Makefile rule generating a Windows release binary
### Note
`pass` needs to be configured for `docker-credential-pass` to work properly.
It must be initialized with a `gpg2` key ID. Make sure your GPG key exists is in `gpg2` keyring as `pass` uses `gpg2` instead of the regular `gpg`.
## v0.5.2 (Mac OS X, Windows, Linux)
- Add a `version` command to output the version
- Fix storing URLs without scheme, and use `https://` by default
## v0.5.1 (Go client, Mac OS X, Windows, Linux)
- Redirect credential helpers' standard error to the caller's
- Prevent invalid credentials and credentials queries
## v0.5.0 (Mac OS X)
- Add a label for Docker credentials and filter credentials lookup to filter keychain lookups
## v0.4.2 (Mac OS X, Windows)
- Fix osxkeychain list
- macOS binary is now signed on release
- Generate a `.exe` instead
## v0.4.1 (Mac OS X)
- Fixes to support older version of OSX (10.10, 10.11)
## v0.4.0 (Go client, Mac OS X, Windows, Linux)
- Full implementation for OSX ready
- Fix some windows issues
- Implement client.List, change list API
- mac: delete credentials before adding them to avoid already exist error (fixes #37)
## v0.3.0 (Go client)
- Add Go client library to talk with the native programs.
## v0.2.0 (Mac OS X, Windows, Linux) ## v0.2.0 (Mac OS X, Windows, Linux)
- Initial release of docker-credential-secretservice for Linux. - Initial release of docker-credential-secretservice for Linux.
+136
View File
@@ -0,0 +1,136 @@
# docker-credential-helpers maintainers file
#
# This file describes who runs the docker/docker-credential-helpers project and how.
# This is a living document - if you see something out of date or missing, speak up!
#
# It is structured to be consumable by both humans and programs.
# To extract its contents programmatically, use any TOML-compliant parser.
#
# This file is compiled into the MAINTAINERS file in docker/opensource.
#
[Org]
[Org."Core maintainers"]
people = [
"coolljt0725",
"cpuguy83",
"crosbymichael",
"dnephin",
"duglin",
"estesp",
"jhowardmsft",
"mavenugo",
"mhbauer",
"n4ss",
"runcom",
"stevvooe",
"thajeztah",
"tianon",
"tibor",
"tonistiigi",
"unclejack",
"vdemeester",
"vieux"
]
[people]
# A reference list of all people associated with the project.
# All other sections should refer to people by their canonical key
# in the people section.
# ADD YOURSELF HERE IN ALPHABETICAL ORDER
[people.coolljt0725]
Name = "Lei Jitang"
Email = "leijitang@huawei.com"
GitHub = "coolljt0725"
[people.cpuguy83]
Name = "Brian Goff"
Email = "cpuguy83@gmail.com"
Github = "cpuguy83"
[people.crosbymichael]
Name = "Michael Crosby"
Email = "crosbymichael@gmail.com"
GitHub = "crosbymichael"
[people.dnephin]
Name = "Daniel Nephin"
Email = "dnephin@gmail.com"
GitHub = "dnephin"
[people.duglin]
Name = "Doug Davis"
Email = "dug@us.ibm.com"
GitHub = "duglin"
[people.estesp]
Name = "Phil Estes"
Email = "estesp@linux.vnet.ibm.com"
GitHub = "estesp"
[people.jhowardmsft]
Name = "John Howard"
Email = "jhoward@microsoft.com"
GitHub = "jhowardmsft"
[people.mavenugo]
Name = "Madhu Venugopal"
Email = "madhu@docker.com"
GitHub = "mavenugo"
[people.mhbauer]
Name = "Morgan Bauer"
Email = "mbauer@us.ibm.com"
GitHub = "mhbauer"
[people.n4ss]
Name = "Nassim Eddequiouaq"
Email = "eddequiouaq.nassim@gmail.com"
GitHub = "n4ss"
[people.runcom]
Name = "Antonio Murdaca"
Email = "runcom@redhat.com"
GitHub = "runcom"
[people.stevvooe]
Name = "Stephen Day"
Email = "stephen.day@docker.com"
GitHub = "stevvooe"
[people.thajeztah]
Name = "Sebastiaan van Stijn"
Email = "github@gone.nl"
GitHub = "thaJeztah"
[people.tianon]
Name = "Tianon Gravi"
Email = "admwiggin@gmail.com"
GitHub = "tianon"
[people.tibor]
Name = "Tibor Vass"
Email = "tibor@docker.com"
GitHub = "tiborvass"
[people.tonistiigi]
Name = "Tõnis Tiigi"
Email = "tonis@docker.com"
GitHub = "tonistiigi"
[people.unclejack]
Name = "Cristian Staretu"
Email = "cristian.staretu@gmail.com"
GitHub = "unclejack"
[people.vdemeester]
Name = "Vincent Demeester"
Email = "vincent@sbr.pm"
GitHub = "vdemeester"
[people.vieux]
Name = "Victor Vieux"
Email = "vieux@docker.com"
GitHub = "vieux"
+48 -5
View File
@@ -1,23 +1,47 @@
.PHONY: all deps osxkeychain secretservice test validate wincred .PHONY: all deps osxkeychain secretservice test validate wincred pass deb
TRAVIS_OS_NAME ?= linux TRAVIS_OS_NAME ?= linux
VERSION := $(shell grep 'const Version' credentials/version.go | awk -F'"' '{ print $$2 }')
all: test all: test
deps: deps:
go get github.com/golang/lint/golint go get -u github.com/golang/lint/golint
clean:
rm -rf bin
rm -rf release
osxkeychain: osxkeychain:
mkdir -p bin mkdir -p bin
go build -o bin/docker-credential-osxkeychain osxkeychain/cmd/main_darwin.go go build -ldflags -s -o bin/docker-credential-osxkeychain osxkeychain/cmd/main_darwin.go
osxcodesign: osxkeychain
$(eval SIGNINGHASH = $(shell security find-identity -v -p codesigning | grep "Developer ID Application: Docker Inc" | cut -d ' ' -f 4))
xcrun -log codesign -s $(SIGNINGHASH) --force --verbose bin/docker-credential-osxkeychain
xcrun codesign --verify --deep --strict --verbose=2 --display bin/docker-credential-osxkeychain
osxrelease: clean vet_osx lint fmt test osxcodesign
mkdir -p release
@echo "\nPackaging version ${VERSION}\n"
cd bin && tar cvfz ../release/docker-credential-osxkeychain-v$(VERSION)-amd64.tar.gz docker-credential-osxkeychain
secretservice: secretservice:
mkdir -p bin mkdir -p bin
go build -o bin/docker-credential-secretservice secretservice/cmd/main_linux.go go build -o bin/docker-credential-secretservice secretservice/cmd/main_linux.go
pass:
mkdir -p bin
go build -o bin/docker-credential-pass pass/cmd/main_linux.go
wincred: wincred:
mkdir -p bin mkdir -p bin
go build -o bin/docker-credential-wincred wincred/cmd/main_windows.go go build -o bin/docker-credential-wincred.exe wincred/cmd/main_windows.go
winrelease: clean vet_win lint fmt test wincred
mkdir -p release
@echo "\nPackaging version ${VERSION}\n"
cd bin && zip ../release/docker-credential-wincred-v$(VERSION)-amd64.zip docker-credential-wincred.exe
test: test:
# tests all packages except vendor # tests all packages except vendor
@@ -26,14 +50,33 @@ test:
vet: vet_$(TRAVIS_OS_NAME) vet: vet_$(TRAVIS_OS_NAME)
go vet ./credentials go vet ./credentials
vet_win:
go vet ./wincred
vet_osx: vet_osx:
go vet ./osxkeychain go vet ./osxkeychain
vet_linux: vet_linux:
go vet ./secretservice go vet ./secretservice
validate: vet lint:
for p in `go list ./... | grep -v /vendor/`; do \ for p in `go list ./... | grep -v /vendor/`; do \
golint $$p ; \ golint $$p ; \
done done
fmt:
gofmt -s -l `ls **/*.go | grep -v vendor` gofmt -s -l `ls **/*.go | grep -v vendor`
validate: vet lint fmt
BUILDIMG:=docker-credential-secretservice-$(VERSION)
deb:
mkdir -p release
docker build -f deb/Dockerfile \
--build-arg VERSION=$(VERSION) \
--build-arg DISTRO=xenial \
--tag $(BUILDIMG) \
.
docker run --rm --net=none $(BUILDIMG) tar cf - /release | tar xf -
docker rmi $(BUILDIMG)
+28 -6
View File
@@ -4,7 +4,7 @@ docker-credential-helpers is a suite of programs to use native stores to keep Do
## Installation ## Installation
Go to the [Releases](https://github.com/calavera/docker-credential-helpers/releases) page and download the binary that works better for you. Put that binary in your `$PATH`, so Docker can find it. Go to the [Releases](https://github.com/docker/docker-credential-helpers/releases) page and download the binary that works better for you. Put that binary in your `$PATH`, so Docker can find it.
### Building from scratch ### Building from scratch
@@ -13,13 +13,13 @@ The programs in this repository are written with the Go programming language. Th
1 - Download the source and put it in your `$GOPATH` with `go get`. 1 - Download the source and put it in your `$GOPATH` with `go get`.
``` ```
$ go get github.com/calavera/docker-credential-helpers $ go get github.com/docker/docker-credential-helpers
``` ```
2 - Use `make` to build the program you want. That will leave any executable in the `bin` directory inside the repository. 2 - Use `make` to build the program you want. That will leave any executable in the `bin` directory inside the repository.
``` ```
$ cd $GOPATH/calavera/docker-credentials-helpers $ cd $GOPATH/docker/docker-credentials-helpers
$ make osxkeychain $ make osxkeychain
``` ```
@@ -27,6 +27,8 @@ $ make osxkeychain
## Usage ## Usage
### With the Docker Engine
Set the `credsStore` option in your `.docker/config.json` file with the suffix of the program you want to use. For instance, set it to `osxkeychain` if you want to use `docker-credential-osxkeychain`. Set the `credsStore` option in your `.docker/config.json` file with the suffix of the program you want to use. For instance, set it to `osxkeychain` if you want to use `docker-credential-osxkeychain`.
```json ```json
@@ -35,19 +37,39 @@ Set the `credsStore` option in your `.docker/config.json` file with the suffix o
} }
``` ```
### With other command line applications
The sub-package [client](https://godoc.org/github.com/docker/docker-credential-helpers/client) includes
functions to call external programs from your own command line applications.
There are three things you need to know if you need to interact with a helper:
1. The name of the program to execute, for instance `docker-credential-osxkeychain`.
2. The server address to identify the credentials, for instance `https://example.com`.
3. The username and secret to store, when you want to store credentials.
You can see examples of each function in the [client](https://godoc.org/github.com/docker/docker-credential-helpers/client) documentation.
### Available programs ### Available programs
1. osxkeychain: Provides a helper to use the OS X keychain as credentials store. 1. osxkeychain: Provides a helper to use the OS X keychain as credentials store.
1. secretservice: Provides a helper to use the D-Bus secret service as credentials store. 2. secretservice: Provides a helper to use the D-Bus secret service as credentials store.
2. wincred: Provides a helper to use Windows credentials manager as store. 3. wincred: Provides a helper to use Windows credentials manager as store.
4. pass: Provides a helper to use `pass` as credentials store.
#### Note
`pass` needs to be configured for `docker-credential-pass` to work properly.
It must be initialized with a `gpg2` key ID. Make sure your GPG key exists is in `gpg2` keyring as `pass` uses `gpg2` instead of the regular `gpg`.
## Development ## Development
A credential helper can be any program that can read values from the standard input. We use the first argument in the command line to differentiate the kind of command to execute. There are three valid values: A credential helper can be any program that can read values from the standard input. We use the first argument in the command line to differentiate the kind of command to execute. There are four valid values:
- `store`: Adds credentials to the keychain. The payload in the standard input is a JSON document with `ServerURL`, `Username` and `Secret`. - `store`: Adds credentials to the keychain. The payload in the standard input is a JSON document with `ServerURL`, `Username` and `Secret`.
- `get`: Retrieves credentials from the keychain. The payload in the standard input is the raw value for the `ServerURL`. - `get`: Retrieves credentials from the keychain. The payload in the standard input is the raw value for the `ServerURL`.
- `erase`: Removes credentials from the keychain. The payload in the standard input is the raw value for the `ServerURL`. - `erase`: Removes credentials from the keychain. The payload in the standard input is the raw value for the `ServerURL`.
- `list`: Lists stored credentials. There is no standard input payload.
This repository also includes libraries to implement new credentials programs in Go. Adding a new helper program is pretty easy. You can see how the OS X keychain helper works in the [osxkeychain](osxkeychain) directory. This repository also includes libraries to implement new credentials programs in Go. Adding a new helper program is pretty easy. You can see how the OS X keychain helper works in the [osxkeychain](osxkeychain) directory.
+12 -54
View File
@@ -1,66 +1,24 @@
version: "{build}" image: Visual Studio 2015
# Source Config
clone_folder: c:\gopath\src\github.com\docker\docker-credential-helpers
# Build host
environment: environment:
global:
GOPATH: c:\gopath GOPATH: c:\gopath
CGO_ENABLED: 1
GOVERSION: 1.6
matrix:
- platform: x86
GOARCH: 386
MSYS2_BITS: 32
- platform: x64
GOARCH: amd64
MSYS2_BITS: 64
init: stack: go 1.8.7
- git config --global core.autocrlf input
# Build clone_folder: c:\gopath\src\github.com\docker\docker-credential-helpers
clone_depth: 10
install: before_build:
# Install Go 1.6. - set PATH=%PATH%;C:\MinGW\bin;
- rmdir c:\go /s /q
- appveyor DownloadFile https://storage.googleapis.com/golang/go%GOVERSION%.windows-%GOARCH%.msi
- msiexec /i go%GOVERSION%.windows-%GOARCH%.msi /q
- set Path=c:\msys64\mingw%MSYS2_BITS%\bin;c:\go\bin;%Path%
- go version
- go env
build: false build_script:
- mingw32-make vet_win wincred
test_script: test_script:
- go vet ./wincred - mingw32-make test
- go test -v github.com/docker/docker-credential-helpers/wincred
# Equivalent to `before_deploy` phase deploy: off
after_test:
# build binary
- mkdir bin
- go build -o bin/docker-credential-wincred wincred/cmd/main_windows.go
# build zipfile, will look like docker-credential-wincred-v0.1.0-amd64.zip in the root directory
- cd bin && 7z a ../docker-credential-wincred-%APPVEYOR_REPO_TAG_NAME%-%GOARCH%.zip docker-credential-wincred
# IMPORTANT All the artifacts need to be listed here, or they won't be uploaded to GitHub
artifacts: artifacts:
- path: docker-credential-wincred-$(APPVEYOR_REPO_TAG_NAME)-$(GOARCH).zip - path: bin/docker-credential-wincred.exe
name: docker-credential-wincred-$(APPVEYOR_REPO_TAG_NAME)-$(GOARCH).zip
deploy: configuration: Release
# All the zipped artifacts will be deployed
artifact: /.*\.zip/
auth_token:
secure: ixWmTXZs8aV5+9s6vPXziIcdMMLd+lBVINJ0K/Sy++2wllpRxUec4/TPVKUGLqvL
provider: GitHub
# deploy when a new tag is pushed
on:
appveyor_repo_tag: true
branches:
only:
- master
+18
View File
@@ -2,3 +2,21 @@ set -ex
sh -e /etc/init.d/xvfb start sh -e /etc/init.d/xvfb start
sleep 3 # give xvfb some time to start sleep 3 # give xvfb some time to start
# init key for pass
gpg --batch --gen-key <<-EOF
%echo Generating a standard key
Key-Type: DSA
Key-Length: 1024
Subkey-Type: ELG-E
Subkey-Length: 1024
Name-Real: Meshuggah Rocks
Name-Email: meshuggah@example.com
Expire-Date: 0
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOF
key=$(gpg --no-auto-check-trustdb --list-secret-keys | grep ^sec | cut -d/ -f2 | cut -d" " -f1)
pass init $key
+121
View File
@@ -0,0 +1,121 @@
package client
import (
"bytes"
"encoding/json"
"fmt"
"strings"
"github.com/docker/docker-credential-helpers/credentials"
)
// isValidCredsMessage checks if 'msg' contains invalid credentials error message.
// It returns whether the logs are free of invalid credentials errors and the error if it isn't.
// error values can be errCredentialsMissingServerURL or errCredentialsMissingUsername.
func isValidCredsMessage(msg string) error {
if credentials.IsCredentialsMissingServerURLMessage(msg) {
return credentials.NewErrCredentialsMissingServerURL()
}
if credentials.IsCredentialsMissingUsernameMessage(msg) {
return credentials.NewErrCredentialsMissingUsername()
}
return nil
}
// Store uses an external program to save credentials.
func Store(program ProgramFunc, creds *credentials.Credentials) error {
cmd := program("store")
buffer := new(bytes.Buffer)
if err := json.NewEncoder(buffer).Encode(creds); err != nil {
return err
}
cmd.Input(buffer)
out, err := cmd.Output()
if err != nil {
t := strings.TrimSpace(string(out))
if isValidErr := isValidCredsMessage(t); isValidErr != nil {
err = isValidErr
}
return fmt.Errorf("error storing credentials - err: %v, out: `%s`", err, t)
}
return nil
}
// Get executes an external program to get the credentials from a native store.
func Get(program ProgramFunc, serverURL string) (*credentials.Credentials, error) {
cmd := program("get")
cmd.Input(strings.NewReader(serverURL))
out, err := cmd.Output()
if err != nil {
t := strings.TrimSpace(string(out))
if credentials.IsErrCredentialsNotFoundMessage(t) {
return nil, credentials.NewErrCredentialsNotFound()
}
if isValidErr := isValidCredsMessage(t); isValidErr != nil {
err = isValidErr
}
return nil, fmt.Errorf("error getting credentials - err: %v, out: `%s`", err, t)
}
resp := &credentials.Credentials{
ServerURL: serverURL,
}
if err := json.NewDecoder(bytes.NewReader(out)).Decode(resp); err != nil {
return nil, err
}
return resp, nil
}
// Erase executes a program to remove the server credentials from the native store.
func Erase(program ProgramFunc, serverURL string) error {
cmd := program("erase")
cmd.Input(strings.NewReader(serverURL))
out, err := cmd.Output()
if err != nil {
t := strings.TrimSpace(string(out))
if isValidErr := isValidCredsMessage(t); isValidErr != nil {
err = isValidErr
}
return fmt.Errorf("error erasing credentials - err: %v, out: `%s`", err, t)
}
return nil
}
// List executes a program to list server credentials in the native store.
func List(program ProgramFunc) (map[string]string, error) {
cmd := program("list")
cmd.Input(strings.NewReader("unused"))
out, err := cmd.Output()
if err != nil {
t := strings.TrimSpace(string(out))
if isValidErr := isValidCredsMessage(t); isValidErr != nil {
err = isValidErr
}
return nil, fmt.Errorf("error listing credentials - err: %v, out: `%s`", err, t)
}
var resp map[string]string
if err = json.NewDecoder(bytes.NewReader(out)).Decode(&resp); err != nil {
return nil, err
}
return resp, nil
}
+213
View File
@@ -0,0 +1,213 @@
package client
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"strings"
"testing"
"github.com/docker/docker-credential-helpers/credentials"
)
const (
validServerAddress = "https://index.docker.io/v1"
validUsername = "linus"
validServerAddress2 = "https://example.com:5002"
invalidServerAddress = "https://foobar.example.com"
missingCredsAddress = "https://missing.docker.io/v1"
)
var errProgramExited = fmt.Errorf("exited 1")
// mockProgram simulates interactions between the docker client and a remote
// credentials helper.
// Unit tests inject this mocked command into the remote to control execution.
type mockProgram struct {
arg string
input io.Reader
}
// Output returns responses from the remote credentials helper.
// It mocks those responses based in the input in the mock.
func (m *mockProgram) Output() ([]byte, error) {
in, err := ioutil.ReadAll(m.input)
if err != nil {
return nil, err
}
inS := string(in)
switch m.arg {
case "erase":
switch inS {
case validServerAddress:
return nil, nil
default:
return []byte("program failed"), errProgramExited
}
case "get":
switch inS {
case validServerAddress:
return []byte(`{"Username": "foo", "Secret": "bar"}`), nil
case validServerAddress2:
return []byte(`{"Username": "<token>", "Secret": "abcd1234"}`), nil
case missingCredsAddress:
return []byte(credentials.NewErrCredentialsNotFound().Error()), errProgramExited
case invalidServerAddress:
return []byte("program failed"), errProgramExited
case "":
return []byte(credentials.NewErrCredentialsMissingServerURL().Error()), errProgramExited
}
case "store":
var c credentials.Credentials
err := json.NewDecoder(strings.NewReader(inS)).Decode(&c)
if err != nil {
return []byte("error storing credentials"), errProgramExited
}
switch c.ServerURL {
case validServerAddress:
return nil, nil
case validServerAddress2:
return nil, nil
default:
return []byte("error storing credentials"), errProgramExited
}
case "list":
return []byte(fmt.Sprintf(`{"%s": "%s"}`, validServerAddress, validUsername)), nil
}
return []byte(fmt.Sprintf("unknown argument %q with %q", m.arg, inS)), errProgramExited
}
// Input sets the input to send to a remote credentials helper.
func (m *mockProgram) Input(in io.Reader) {
m.input = in
}
func mockProgramFn(args ...string) Program {
return &mockProgram{
arg: args[0],
}
}
func ExampleStore() {
p := NewShellProgramFunc("docker-credential-secretservice")
c := &credentials.Credentials{
ServerURL: "https://example.com",
Username: "calavera",
Secret: "my super secret token",
}
if err := Store(p, c); err != nil {
fmt.Println(err)
}
}
func TestStore(t *testing.T) {
valid := []credentials.Credentials{
{validServerAddress, "foo", "bar"},
{validServerAddress2, "<token>", "abcd1234"},
}
for _, v := range valid {
if err := Store(mockProgramFn, &v); err != nil {
t.Fatal(err)
}
}
invalid := []credentials.Credentials{
{invalidServerAddress, "foo", "bar"},
}
for _, v := range invalid {
if err := Store(mockProgramFn, &v); err == nil {
t.Fatalf("Expected error for server %s, got nil", v.ServerURL)
}
}
}
func ExampleGet() {
p := NewShellProgramFunc("docker-credential-secretservice")
creds, err := Get(p, "https://example.com")
if err != nil {
fmt.Println(err)
}
fmt.Printf("Got credentials for user `%s` in `%s`\n", creds.Username, creds.ServerURL)
}
func TestGet(t *testing.T) {
valid := []credentials.Credentials{
{validServerAddress, "foo", "bar"},
{validServerAddress2, "<token>", "abcd1234"},
}
for _, v := range valid {
c, err := Get(mockProgramFn, v.ServerURL)
if err != nil {
t.Fatal(err)
}
if c.Username != v.Username {
t.Fatalf("expected username `%s`, got %s", v.Username, c.Username)
}
if c.Secret != v.Secret {
t.Fatalf("expected secret `%s`, got %s", v.Secret, c.Secret)
}
}
missingServerURLErr := credentials.NewErrCredentialsMissingServerURL()
invalid := []struct {
serverURL string
err string
}{
{missingCredsAddress, credentials.NewErrCredentialsNotFound().Error()},
{invalidServerAddress, "error getting credentials - err: exited 1, out: `program failed`"},
{"", fmt.Sprintf("error getting credentials - err: %s, out: `%s`",
missingServerURLErr.Error(), missingServerURLErr.Error())},
}
for _, v := range invalid {
_, err := Get(mockProgramFn, v.serverURL)
if err == nil {
t.Fatalf("Expected error for server %s, got nil", v.serverURL)
}
if err.Error() != v.err {
t.Fatalf("Expected error `%s`, got `%v`", v.err, err)
}
}
}
func ExampleErase() {
p := NewShellProgramFunc("docker-credential-secretservice")
if err := Erase(p, "https://example.com"); err != nil {
fmt.Println(err)
}
}
func TestErase(t *testing.T) {
if err := Erase(mockProgramFn, validServerAddress); err != nil {
t.Fatal(err)
}
if err := Erase(mockProgramFn, invalidServerAddress); err == nil {
t.Fatalf("Expected error for server %s, got nil", invalidServerAddress)
}
}
func TestList(t *testing.T) {
auths, err := List(mockProgramFn)
if err != nil {
t.Fatal(err)
}
if username, exists := auths[validServerAddress]; !exists || username != validUsername {
t.Fatalf("auths[%s] returned %s, %t; expected %s, %t", validServerAddress, username, exists, validUsername, true)
}
}
+56
View File
@@ -0,0 +1,56 @@
package client
import (
"fmt"
"io"
"os"
"os/exec"
)
// Program is an interface to execute external programs.
type Program interface {
Output() ([]byte, error)
Input(in io.Reader)
}
// ProgramFunc is a type of function that initializes programs based on arguments.
type ProgramFunc func(args ...string) Program
// NewShellProgramFunc creates programs that are executed in a Shell.
func NewShellProgramFunc(name string) ProgramFunc {
return NewShellProgramFuncWithEnv(name, nil)
}
// NewShellProgramFuncWithEnv creates programs that are executed in a Shell with environment variables
func NewShellProgramFuncWithEnv(name string, env *map[string]string) ProgramFunc {
return func(args ...string) Program {
return &Shell{cmd: createProgramCmdRedirectErr(name, args, env)}
}
}
func createProgramCmdRedirectErr(commandName string, args []string, env *map[string]string) *exec.Cmd {
programCmd := exec.Command(commandName, args...)
programCmd.Env = os.Environ()
if env != nil {
for k, v := range *env {
programCmd.Env = append(programCmd.Env, fmt.Sprintf("%s=%s", k, v))
}
}
programCmd.Stderr = os.Stderr
return programCmd
}
// Shell invokes shell commands to talk with a remote credentials helper.
type Shell struct {
cmd *exec.Cmd
}
// Output returns responses from the remote credentials helper.
func (s *Shell) Output() ([]byte, error) {
return s.cmd.Output()
}
// Input sets the input to send to a remote credentials helper.
func (s *Shell) Input(in io.Reader) {
s.cmd.Stdin = in
}
+92 -16
View File
@@ -10,36 +10,80 @@ import (
"strings" "strings"
) )
type credentialsGetResponse struct { // Credentials holds the information shared between docker and the credentials store.
type Credentials struct {
ServerURL string
Username string Username string
Secret string Secret string
} }
// isValid checks the integrity of Credentials object such that no credentials lack
// a server URL or a username.
// It returns whether the credentials are valid and the error if it isn't.
// error values can be errCredentialsMissingServerURL or errCredentialsMissingUsername
func (c *Credentials) isValid() (bool, error) {
if len(c.ServerURL) == 0 {
return false, NewErrCredentialsMissingServerURL()
}
if len(c.Username) == 0 {
return false, NewErrCredentialsMissingUsername()
}
return true, nil
}
// CredsLabel holds the way Docker credentials should be labeled as such in credentials stores that allow labelling.
// That label allows to filter out non-Docker credentials too at lookup/search in macOS keychain,
// Windows credentials manager and Linux libsecret. Default value is "Docker Credentials"
var CredsLabel = "Docker Credentials"
// SetCredsLabel is a simple setter for CredsLabel
func SetCredsLabel(label string) {
CredsLabel = label
}
// Serve initializes the credentials helper and parses the action argument. // Serve initializes the credentials helper and parses the action argument.
// This function is designed to be called from a command line interface.
// It uses os.Args[1] as the key for the action.
// It uses os.Stdin as input and os.Stdout as output.
// This function terminates the program with os.Exit(1) if there is an error.
func Serve(helper Helper) { func Serve(helper Helper) {
if err := handleCommand(helper); err != nil { var err error
if len(os.Args) != 2 {
err = fmt.Errorf("Usage: %s <store|get|erase|list|version>", os.Args[0])
}
if err == nil {
err = HandleCommand(helper, os.Args[1], os.Stdin, os.Stdout)
}
if err != nil {
fmt.Fprintf(os.Stdout, "%v\n", err) fmt.Fprintf(os.Stdout, "%v\n", err)
os.Exit(1) os.Exit(1)
} }
} }
func handleCommand(helper Helper) error { // HandleCommand uses a helper and a key to run a credential action.
if len(os.Args) != 2 { func HandleCommand(helper Helper, key string, in io.Reader, out io.Writer) error {
return fmt.Errorf("Usage: %s <store|get|erase>", os.Args[0]) switch key {
}
switch os.Args[1] {
case "store": case "store":
return store(helper, os.Stdin) return Store(helper, in)
case "get": case "get":
return get(helper, os.Stdin, os.Stdout) return Get(helper, in, out)
case "erase": case "erase":
return erase(helper, os.Stdin) return Erase(helper, in)
case "list":
return List(helper, out)
case "version":
return PrintVersion(out)
} }
return fmt.Errorf("Usage: %s <store|get|erase>", os.Args[0]) return fmt.Errorf("Unknown credential action `%s`", key)
} }
func store(helper Helper, reader io.Reader) error { // Store uses a helper and an input reader to save credentials.
// The reader must contain the JSON serialization of a Credentials struct.
func Store(helper Helper, reader io.Reader) error {
scanner := bufio.NewScanner(reader) scanner := bufio.NewScanner(reader)
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
@@ -56,10 +100,17 @@ func store(helper Helper, reader io.Reader) error {
return err return err
} }
if ok, err := creds.isValid(); !ok {
return err
}
return helper.Add(&creds) return helper.Add(&creds)
} }
func get(helper Helper, reader io.Reader, writer io.Writer) error { // Get retrieves the credentials for a given server url.
// The reader must contain the server URL to search.
// The writer is used to write the JSON serialization of the credentials.
func Get(helper Helper, reader io.Reader, writer io.Writer) error {
scanner := bufio.NewScanner(reader) scanner := bufio.NewScanner(reader)
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
@@ -72,13 +123,17 @@ func get(helper Helper, reader io.Reader, writer io.Writer) error {
} }
serverURL := strings.TrimSpace(buffer.String()) serverURL := strings.TrimSpace(buffer.String())
if len(serverURL) == 0 {
return NewErrCredentialsMissingServerURL()
}
username, secret, err := helper.Get(serverURL) username, secret, err := helper.Get(serverURL)
if err != nil { if err != nil {
return err return err
} }
resp := credentialsGetResponse{ resp := Credentials{
ServerURL: serverURL,
Username: username, Username: username,
Secret: secret, Secret: secret,
} }
@@ -92,7 +147,9 @@ func get(helper Helper, reader io.Reader, writer io.Writer) error {
return nil return nil
} }
func erase(helper Helper, reader io.Reader) error { // Erase removes credentials from the store.
// The reader must contain the server URL to remove.
func Erase(helper Helper, reader io.Reader) error {
scanner := bufio.NewScanner(reader) scanner := bufio.NewScanner(reader)
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
@@ -105,6 +162,25 @@ func erase(helper Helper, reader io.Reader) error {
} }
serverURL := strings.TrimSpace(buffer.String()) serverURL := strings.TrimSpace(buffer.String())
if len(serverURL) == 0 {
return NewErrCredentialsMissingServerURL()
}
return helper.Delete(serverURL) return helper.Delete(serverURL)
} }
//List returns all the serverURLs of keys in
//the OS store as a list of strings
func List(helper Helper, writer io.Writer) error {
accts, err := helper.List()
if err != nil {
return err
}
return json.NewEncoder(writer).Encode(accts)
}
//PrintVersion outputs the current version.
func PrintVersion(writer io.Writer) error {
fmt.Fprintln(writer, Version)
return nil
}
+116 -7
View File
@@ -36,6 +36,11 @@ func (m *memoryStore) Get(serverURL string) (string, string, error) {
return c.Username, c.Secret, nil return c.Username, c.Secret, nil
} }
func (m *memoryStore) List() (map[string]string, error) {
//Simply a placeholder to let memoryStore be a valid implementation of Helper interface
return nil, nil
}
func TestStore(t *testing.T) { func TestStore(t *testing.T) {
serverURL := "https://index.docker.io/v1/" serverURL := "https://index.docker.io/v1/"
creds := &Credentials{ creds := &Credentials{
@@ -50,7 +55,7 @@ func TestStore(t *testing.T) {
in := bytes.NewReader(b) in := bytes.NewReader(b)
h := newMemoryStore() h := newMemoryStore()
if err := store(h, in); err != nil { if err := Store(h, in); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -68,6 +73,46 @@ func TestStore(t *testing.T) {
} }
} }
func TestStoreMissingServerURL(t *testing.T) {
creds := &Credentials{
ServerURL: "",
Username: "foo",
Secret: "bar",
}
b, err := json.Marshal(creds)
if err != nil {
t.Fatal(err)
}
in := bytes.NewReader(b)
h := newMemoryStore()
if err := Store(h, in); IsCredentialsMissingServerURL(err) == false {
t.Fatal(err)
}
}
func TestStoreMissingUsername(t *testing.T) {
creds := &Credentials{
ServerURL: "https://index.docker.io/v1/",
Username: "",
Secret: "bar",
}
b, err := json.Marshal(creds)
if err != nil {
t.Fatal(err)
}
in := bytes.NewReader(b)
h := newMemoryStore()
if err := Store(h, in); IsCredentialsMissingUsername(err) == false {
t.Fatal(err)
}
}
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
serverURL := "https://index.docker.io/v1/" serverURL := "https://index.docker.io/v1/"
creds := &Credentials{ creds := &Credentials{
@@ -82,13 +127,13 @@ func TestGet(t *testing.T) {
in := bytes.NewReader(b) in := bytes.NewReader(b)
h := newMemoryStore() h := newMemoryStore()
if err := store(h, in); err != nil { if err := Store(h, in); err != nil {
t.Fatal(err) t.Fatal(err)
} }
buf := strings.NewReader(serverURL) buf := strings.NewReader(serverURL)
w := new(bytes.Buffer) w := new(bytes.Buffer)
if err := get(h, buf, w); err != nil { if err := Get(h, buf, w); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -96,7 +141,7 @@ func TestGet(t *testing.T) {
t.Fatalf("expected output in the writer, got %d", w.Len()) t.Fatalf("expected output in the writer, got %d", w.Len())
} }
var c credentialsGetResponse var c Credentials
if err := json.NewDecoder(w).Decode(&c); err != nil { if err := json.NewDecoder(w).Decode(&c); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -110,6 +155,32 @@ func TestGet(t *testing.T) {
} }
} }
func TestGetMissingServerURL(t *testing.T) {
serverURL := "https://index.docker.io/v1/"
creds := &Credentials{
ServerURL: serverURL,
Username: "foo",
Secret: "bar",
}
b, err := json.Marshal(creds)
if err != nil {
t.Fatal(err)
}
in := bytes.NewReader(b)
h := newMemoryStore()
if err := Store(h, in); err != nil {
t.Fatal(err)
}
buf := strings.NewReader("")
w := new(bytes.Buffer)
if err := Get(h, buf, w); IsCredentialsMissingServerURL(err) == false {
t.Fatal(err)
}
}
func TestErase(t *testing.T) { func TestErase(t *testing.T) {
serverURL := "https://index.docker.io/v1/" serverURL := "https://index.docker.io/v1/"
creds := &Credentials{ creds := &Credentials{
@@ -124,17 +195,55 @@ func TestErase(t *testing.T) {
in := bytes.NewReader(b) in := bytes.NewReader(b)
h := newMemoryStore() h := newMemoryStore()
if err := store(h, in); err != nil { if err := Store(h, in); err != nil {
t.Fatal(err) t.Fatal(err)
} }
buf := strings.NewReader(serverURL) buf := strings.NewReader(serverURL)
if err := erase(h, buf); err != nil { if err := Erase(h, buf); err != nil {
t.Fatal(err) t.Fatal(err)
} }
w := new(bytes.Buffer) w := new(bytes.Buffer)
if err := get(h, buf, w); err == nil { if err := Get(h, buf, w); err == nil {
t.Fatal("expected error getting missing creds, got empty") t.Fatal("expected error getting missing creds, got empty")
} }
} }
func TestEraseMissingServerURL(t *testing.T) {
serverURL := "https://index.docker.io/v1/"
creds := &Credentials{
ServerURL: serverURL,
Username: "foo",
Secret: "bar",
}
b, err := json.Marshal(creds)
if err != nil {
t.Fatal(err)
}
in := bytes.NewReader(b)
h := newMemoryStore()
if err := Store(h, in); err != nil {
t.Fatal(err)
}
buf := strings.NewReader("")
if err := Erase(h, buf); IsCredentialsMissingServerURL(err) == false {
t.Fatal(err)
}
}
func TestList(t *testing.T) {
//This tests that there is proper input an output into the byte stream
//Individual stores are very OS specific and have been tested in osxkeychain and secretservice respectively
out := new(bytes.Buffer)
h := newMemoryStore()
if err := List(h, out); err != nil {
t.Fatal(err)
}
//testing that there is an output
if out.Len() == 0 {
t.Fatalf("expected output in the writer, got %d", 0)
}
}
+102
View File
@@ -0,0 +1,102 @@
package credentials
const (
// ErrCredentialsNotFound standardizes the not found error, so every helper returns
// the same message and docker can handle it properly.
errCredentialsNotFoundMessage = "credentials not found in native keychain"
// ErrCredentialsMissingServerURL and ErrCredentialsMissingUsername standardize
// invalid credentials or credentials management operations
errCredentialsMissingServerURLMessage = "no credentials server URL"
errCredentialsMissingUsernameMessage = "no credentials username"
)
// errCredentialsNotFound represents an error
// raised when credentials are not in the store.
type errCredentialsNotFound struct{}
// Error returns the standard error message
// for when the credentials are not in the store.
func (errCredentialsNotFound) Error() string {
return errCredentialsNotFoundMessage
}
// NewErrCredentialsNotFound creates a new error
// for when the credentials are not in the store.
func NewErrCredentialsNotFound() error {
return errCredentialsNotFound{}
}
// IsErrCredentialsNotFound returns true if the error
// was caused by not having a set of credentials in a store.
func IsErrCredentialsNotFound(err error) bool {
_, ok := err.(errCredentialsNotFound)
return ok
}
// IsErrCredentialsNotFoundMessage returns true if the error
// was caused by not having a set of credentials in a store.
//
// This function helps to check messages returned by an
// external program via its standard output.
func IsErrCredentialsNotFoundMessage(err string) bool {
return err == errCredentialsNotFoundMessage
}
// errCredentialsMissingServerURL represents an error raised
// when the credentials object has no server URL or when no
// server URL is provided to a credentials operation requiring
// one.
type errCredentialsMissingServerURL struct{}
func (errCredentialsMissingServerURL) Error() string {
return errCredentialsMissingServerURLMessage
}
// errCredentialsMissingUsername represents an error raised
// when the credentials object has no username or when no
// username is provided to a credentials operation requiring
// one.
type errCredentialsMissingUsername struct{}
func (errCredentialsMissingUsername) Error() string {
return errCredentialsMissingUsernameMessage
}
// NewErrCredentialsMissingServerURL creates a new error for
// errCredentialsMissingServerURL.
func NewErrCredentialsMissingServerURL() error {
return errCredentialsMissingServerURL{}
}
// NewErrCredentialsMissingUsername creates a new error for
// errCredentialsMissingUsername.
func NewErrCredentialsMissingUsername() error {
return errCredentialsMissingUsername{}
}
// IsCredentialsMissingServerURL returns true if the error
// was an errCredentialsMissingServerURL.
func IsCredentialsMissingServerURL(err error) bool {
_, ok := err.(errCredentialsMissingServerURL)
return ok
}
// IsCredentialsMissingServerURLMessage checks for an
// errCredentialsMissingServerURL in the error message.
func IsCredentialsMissingServerURLMessage(err string) bool {
return err == errCredentialsMissingServerURLMessage
}
// IsCredentialsMissingUsername returns true if the error
// was an errCredentialsMissingUsername.
func IsCredentialsMissingUsername(err error) bool {
_, ok := err.(errCredentialsMissingUsername)
return ok
}
// IsCredentialsMissingUsernameMessage checks for an
// errCredentialsMissingUsername in the error message.
func IsCredentialsMissingUsernameMessage(err string) bool {
return err == errCredentialsMissingUsernameMessage
}
+6 -13
View File
@@ -1,21 +1,14 @@
package credentials package credentials
import "errors"
// Credentials holds the information shared between docker and the credentials store.
type Credentials struct {
ServerURL string
Username string
Secret string
}
// Helper is the interface a credentials store helper must implement. // Helper is the interface a credentials store helper must implement.
type Helper interface { type Helper interface {
// Add appends credentials to the store.
Add(*Credentials) error Add(*Credentials) error
// Delete removes credentials from the store.
Delete(serverURL string) error Delete(serverURL string) error
// Get retrieves credentials from the store.
// It returns username and secret as strings.
Get(serverURL string) (string, string, error) Get(serverURL string) (string, string, error)
// List returns the stored serverURLs and their associated usernames.
List() (map[string]string, error)
} }
// ErrCredentialsNotFound standarizes the not found error, so every helper returns
// the same message and docker can handle it properly.
var ErrCredentialsNotFound = errors.New("credentials not found in native keychain")
+4
View File
@@ -0,0 +1,4 @@
package credentials
// Version holds a string describing the current version
const Version = "0.6.0"
+19
View File
@@ -0,0 +1,19 @@
FROM ubuntu:xenial
ARG VERSION
ARG DISTRO
RUN apt-get update && apt-get install -yy debhelper dh-make golang-go libsecret-1-dev
RUN mkdir -p /build
WORKDIR /build
ENV GOPATH /build
COPY Makefile .
COPY credentials credentials
COPY secretservice secretservice
COPY pass pass
COPY deb/debian ./debian
COPY deb/build-deb .
RUN /build/build-deb ${VERSION} ${DISTRO}
Executable
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -x
set -e
version=$1
distro=$2
maintainer=$(awk -F ': ' '$1 == "Maintainer" { print $2; exit }' debian/control)
cat > "debian/changelog" <<-EOF
docker-credential-helpers ($version) $DISTRO; urgency=low
* New upstream version
-- $maintainer $(date --rfc-2822)
EOF
mkdir -p src/github.com/docker/docker-credential-helpers
ln -s /build/credentials /build/src/github.com/docker/docker-credential-helpers/credentials
ln -s /build/secretservice /build/src/github.com/docker/docker-credential-helpers/secretservice
ln -s /build/pass /build/src/github.com/docker/docker-credential-helpers/pass
dpkg-buildpackage -us -uc
mkdir /release
mv /docker-credential-* /release
+1
View File
@@ -0,0 +1 @@
9
+25
View File
@@ -0,0 +1,25 @@
Source: docker-credential-helpers
Section: admin
Priority: optional
Maintainer: Docker <support@docker.com>
Homepage: https://dockerproject.org
Standards-Version: 3.9.6
Vcs-Browser: https://github.com/docker/docker-credential-helpers
Vcs-Git: git://github.com/docker/docker-credential-helpers.git
Build-Depends: debhelper
, dh-make
, libsecret-1-dev
Package: docker-credential-secretservice
Architecture: any
Depends: libsecret-1-0
, ${misc:Depends}
Description: docker-credential-secretservice is a credential helper backend
which uses libsecret to keep Docker credentials safe.
Package: docker-credential-pass
Architecture: any
Depends: pass
, ${misc:Depends}
Description: docker-credential-secretservice is a credential helper backend
which uses the pass utility to keep Docker credentials safe.
@@ -0,0 +1 @@
debian/tmp/usr/bin/docker-credential-pass
@@ -0,0 +1 @@
debian/tmp/usr/bin/docker-credential-secretservice
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/make -f
DESTDIR := $(CURDIR)/debian/tmp
override_dh_auto_build:
make secretservice pass
override_dh_auto_install:
install -D bin/docker-credential-secretservice $(DESTDIR)/usr/bin/docker-credential-secretservice
install -D bin/docker-credential-pass $(DESTDIR)/usr/bin/docker-credential-pass
%:
dh $@
override_dh_auto_test:
# no tests
+1 -1
View File
@@ -6,5 +6,5 @@ import (
) )
func main() { func main() {
credentials.Serve(osxkeychain.New()) credentials.Serve(osxkeychain.Osxkeychain{})
} }
+132 -2
View File
@@ -1,4 +1,8 @@
#include "osxkeychain_darwin.h" #include "osxkeychain_darwin.h"
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/NSValue.h>
#include <stdio.h>
#include <string.h>
char *get_error(OSStatus status) { char *get_error(OSStatus status) {
char *buf = malloc(128); char *buf = malloc(128);
@@ -10,7 +14,9 @@ char *get_error(OSStatus status) {
return buf; return buf;
} }
char *keychain_add(struct Server *server, char *username, char *secret) { char *keychain_add(struct Server *server, char *label, char *username, char *secret) {
SecKeychainItemRef item;
OSStatus status = SecKeychainAddInternetPassword( OSStatus status = SecKeychainAddInternetPassword(
NULL, NULL,
strlen(server->host), server->host, strlen(server->host), server->host,
@@ -21,11 +27,27 @@ char *keychain_add(struct Server *server, char *username, char *secret) {
server->proto, server->proto,
kSecAuthenticationTypeDefault, kSecAuthenticationTypeDefault,
strlen(secret), secret, strlen(secret), secret,
NULL &item
); );
if (status) { if (status) {
return get_error(status); return get_error(status);
} }
SecKeychainAttribute attribute;
SecKeychainAttributeList attrs;
attribute.tag = kSecLabelItemAttr;
attribute.data = label;
attribute.length = strlen(label);
attrs.count = 1;
attrs.attr = &attribute;
status = SecKeychainItemModifyContent(item, &attrs, 0, NULL);
if (status) {
return get_error(status);
}
return NULL; return NULL;
} }
@@ -96,3 +118,111 @@ char *keychain_delete(struct Server *server) {
} }
return NULL; return NULL;
} }
char * CFStringToCharArr(CFStringRef aString) {
if (aString == NULL) {
return NULL;
}
CFIndex length = CFStringGetLength(aString);
CFIndex maxSize =
CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
char *buffer = (char *)malloc(maxSize);
if (CFStringGetCString(aString, buffer, maxSize,
kCFStringEncodingUTF8)) {
return buffer;
}
return NULL;
}
char *keychain_list(char *credsLabel, char *** paths, char *** accts, unsigned int *list_l) {
CFStringRef credsLabelCF = CFStringCreateWithCString(NULL, credsLabel, kCFStringEncodingUTF8);
CFMutableDictionaryRef query = CFDictionaryCreateMutable (NULL, 1, NULL, NULL);
CFDictionaryAddValue(query, kSecClass, kSecClassInternetPassword);
CFDictionaryAddValue(query, kSecReturnAttributes, kCFBooleanTrue);
CFDictionaryAddValue(query, kSecMatchLimit, kSecMatchLimitAll);
CFDictionaryAddValue(query, kSecAttrLabel, credsLabelCF);
//Use this query dictionary
CFTypeRef result= NULL;
OSStatus status = SecItemCopyMatching(
query,
&result);
CFRelease(credsLabelCF);
//Ran a search and store the results in result
if (status) {
return get_error(status);
}
CFIndex numKeys = CFArrayGetCount(result);
*paths = (char **) malloc((int)sizeof(char *)*numKeys);
*accts = (char **) malloc((int)sizeof(char *)*numKeys);
//result is of type CFArray
for(CFIndex i=0; i<numKeys; i++) {
CFDictionaryRef currKey = CFArrayGetValueAtIndex(result,i);
CFStringRef protocolTmp = CFDictionaryGetValue(currKey, CFSTR("ptcl"));
if (protocolTmp != NULL) {
CFStringRef protocolStr = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@"), protocolTmp);
if (CFStringCompare(protocolStr, CFSTR("htps"), 0) == kCFCompareEqualTo) {
protocolTmp = CFSTR("https://");
}
else {
protocolTmp = CFSTR("http://");
}
CFRelease(protocolStr);
}
else {
char * path = "0";
char * acct = "0";
(*paths)[i] = (char *) malloc(sizeof(char)*(strlen(path)));
memcpy((*paths)[i], path, sizeof(char)*(strlen(path)));
(*accts)[i] = (char *) malloc(sizeof(char)*(strlen(acct)));
memcpy((*accts)[i], acct, sizeof(char)*(strlen(acct)));
continue;
}
CFMutableStringRef str = CFStringCreateMutableCopy(NULL, 0, protocolTmp);
CFStringRef serverTmp = CFDictionaryGetValue(currKey, CFSTR("srvr"));
if (serverTmp != NULL) {
CFStringAppend(str, serverTmp);
}
CFStringRef pathTmp = CFDictionaryGetValue(currKey, CFSTR("path"));
if (pathTmp != NULL) {
CFStringAppend(str, pathTmp);
}
const NSNumber * portTmp = CFDictionaryGetValue(currKey, CFSTR("port"));
if (portTmp != NULL && portTmp.integerValue != 0) {
CFStringRef portStr = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@"), portTmp);
CFStringAppend(str, CFSTR(":"));
CFStringAppend(str, portStr);
CFRelease(portStr);
}
CFStringRef acctTmp = CFDictionaryGetValue(currKey, CFSTR("acct"));
if (acctTmp == NULL) {
acctTmp = CFSTR("account not defined");
}
char * path = CFStringToCharArr(str);
char * acct = CFStringToCharArr(acctTmp);
//We now have all we need, username and servername. Now export this to .go
(*paths)[i] = (char *) malloc(sizeof(char)*(strlen(path)+1));
memcpy((*paths)[i], path, sizeof(char)*(strlen(path)+1));
(*accts)[i] = (char *) malloc(sizeof(char)*(strlen(acct)+1));
memcpy((*accts)[i], acct, sizeof(char)*(strlen(acct)+1));
CFRelease(str);
}
*list_l = (int)numKeys;
return NULL;
}
void freeListData(char *** data, unsigned int length) {
for(int i=0; i<length; i++) {
free((*data)[i]);
}
free(*data);
}
+87 -27
View File
@@ -1,8 +1,8 @@
package osxkeychain package osxkeychain
/* /*
#cgo CFLAGS: -x objective-c #cgo CFLAGS: -x objective-c -mmacosx-version-min=10.10
#cgo LDFLAGS: -framework Security -framework Foundation #cgo LDFLAGS: -framework Security -framework Foundation -mmacosx-version-min=10.10
#include "osxkeychain_darwin.h" #include "osxkeychain_darwin.h"
#include <stdlib.h> #include <stdlib.h>
@@ -22,27 +22,27 @@ import (
// when the credentials are not in the keychain. // when the credentials are not in the keychain.
const errCredentialsNotFound = "The specified item could not be found in the keychain." const errCredentialsNotFound = "The specified item could not be found in the keychain."
type osxkeychain struct{} // Osxkeychain handles secrets using the OS X Keychain as store.
type Osxkeychain struct{}
// New creates a new osxkeychain.
func New() credentials.Helper {
return osxkeychain{}
}
// Add adds new credentials to the keychain. // Add adds new credentials to the keychain.
func (h osxkeychain) Add(creds *credentials.Credentials) error { func (h Osxkeychain) Add(creds *credentials.Credentials) error {
h.Delete(creds.ServerURL)
s, err := splitServer(creds.ServerURL) s, err := splitServer(creds.ServerURL)
if err != nil { if err != nil {
return err return err
} }
defer freeServer(s) defer freeServer(s)
label := C.CString(credentials.CredsLabel)
defer C.free(unsafe.Pointer(label))
username := C.CString(creds.Username) username := C.CString(creds.Username)
defer C.free(unsafe.Pointer(username)) defer C.free(unsafe.Pointer(username))
secret := C.CString(creds.Secret) secret := C.CString(creds.Secret)
defer C.free(unsafe.Pointer(secret)) defer C.free(unsafe.Pointer(secret))
errMsg := C.keychain_add(s, username, secret) errMsg := C.keychain_add(s, label, username, secret)
if errMsg != nil { if errMsg != nil {
defer C.free(unsafe.Pointer(errMsg)) defer C.free(unsafe.Pointer(errMsg))
return errors.New(C.GoString(errMsg)) return errors.New(C.GoString(errMsg))
@@ -52,7 +52,7 @@ func (h osxkeychain) Add(creds *credentials.Credentials) error {
} }
// Delete removes credentials from the keychain. // Delete removes credentials from the keychain.
func (h osxkeychain) Delete(serverURL string) error { func (h Osxkeychain) Delete(serverURL string) error {
s, err := splitServer(serverURL) s, err := splitServer(serverURL)
if err != nil { if err != nil {
return err return err
@@ -69,7 +69,7 @@ func (h osxkeychain) Delete(serverURL string) error {
} }
// Get returns the username and secret to use for a given registry server URL. // Get returns the username and secret to use for a given registry server URL.
func (h osxkeychain) Get(serverURL string) (string, string, error) { func (h Osxkeychain) Get(serverURL string) (string, string, error) {
s, err := splitServer(serverURL) s, err := splitServer(serverURL)
if err != nil { if err != nil {
return "", "", err return "", "", err
@@ -87,9 +87,8 @@ func (h osxkeychain) Get(serverURL string) (string, string, error) {
if errMsg != nil { if errMsg != nil {
defer C.free(unsafe.Pointer(errMsg)) defer C.free(unsafe.Pointer(errMsg))
goMsg := C.GoString(errMsg) goMsg := C.GoString(errMsg)
if goMsg == errCredentialsNotFound { if goMsg == errCredentialsNotFound {
return "", "", credentials.ErrCredentialsNotFound return "", "", credentials.NewErrCredentialsNotFound()
} }
return "", "", errors.New(goMsg) return "", "", errors.New(goMsg)
@@ -100,31 +99,63 @@ func (h osxkeychain) Get(serverURL string) (string, string, error) {
return user, pass, nil return user, pass, nil
} }
func splitServer(serverURL string) (*C.struct_Server, error) { // List returns the stored URLs and corresponding usernames.
u, err := url.Parse(serverURL) func (h Osxkeychain) List() (map[string]string, error) {
if err != nil { credsLabelC := C.CString(credentials.CredsLabel)
return nil, err defer C.free(unsafe.Pointer(credsLabelC))
var pathsC **C.char
defer C.free(unsafe.Pointer(pathsC))
var acctsC **C.char
defer C.free(unsafe.Pointer(acctsC))
var listLenC C.uint
errMsg := C.keychain_list(credsLabelC, &pathsC, &acctsC, &listLenC)
if errMsg != nil {
defer C.free(unsafe.Pointer(errMsg))
goMsg := C.GoString(errMsg)
return nil, errors.New(goMsg)
} }
hostAndPort := strings.Split(u.Host, ":") defer C.freeListData(&pathsC, listLenC)
host := hostAndPort[0] defer C.freeListData(&acctsC, listLenC)
var port int
if len(hostAndPort) == 2 { var listLen int
p, err := strconv.Atoi(hostAndPort[1]) listLen = int(listLenC)
pathTmp := (*[1 << 30]*C.char)(unsafe.Pointer(pathsC))[:listLen:listLen]
acctTmp := (*[1 << 30]*C.char)(unsafe.Pointer(acctsC))[:listLen:listLen]
//taking the array of c strings into go while ignoring all the stuff irrelevant to credentials-helper
resp := make(map[string]string)
for i := 0; i < listLen; i++ {
if C.GoString(pathTmp[i]) == "0" {
continue
}
resp[C.GoString(pathTmp[i])] = C.GoString(acctTmp[i])
}
return resp, nil
}
func splitServer(serverURL string) (*C.struct_Server, error) {
u, err := parseURL(serverURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
port = p
}
proto := C.kSecProtocolTypeHTTPS proto := C.kSecProtocolTypeHTTPS
if u.Scheme != "https" { if u.Scheme == "http" {
proto = C.kSecProtocolTypeHTTP proto = C.kSecProtocolTypeHTTP
} }
var port int
p := getPort(u)
if p != "" {
port, err = strconv.Atoi(p)
if err != nil {
return nil, err
}
}
return &C.struct_Server{ return &C.struct_Server{
proto: C.SecProtocolType(proto), proto: C.SecProtocolType(proto),
host: C.CString(host), host: C.CString(getHostname(u)),
port: C.uint(port), port: C.uint(port),
path: C.CString(u.Path), path: C.CString(u.Path),
}, nil }, nil
@@ -134,3 +165,32 @@ func freeServer(s *C.struct_Server) {
C.free(unsafe.Pointer(s.host)) C.free(unsafe.Pointer(s.host))
C.free(unsafe.Pointer(s.path)) C.free(unsafe.Pointer(s.path))
} }
// parseURL parses and validates a given serverURL to an url.URL, and
// returns an error if validation failed. Querystring parameters are
// omitted in the resulting URL, because they are not used in the helper.
//
// If serverURL does not have a valid scheme, `//` is used as scheme
// before parsing. This prevents the hostname being used as path,
// and the credentials being stored without host.
func parseURL(serverURL string) (*url.URL, error) {
// Check if serverURL has a scheme, otherwise add `//` as scheme.
if !strings.Contains(serverURL, "://") && !strings.HasPrefix(serverURL, "//") {
serverURL = "//" + serverURL
}
u, err := url.Parse(serverURL)
if err != nil {
return nil, err
}
if u.Scheme != "" && u.Scheme != "https" && u.Scheme != "http" {
return nil, errors.New("unsupported scheme: " + u.Scheme)
}
if getHostname(u) == "" {
return nil, errors.New("no hostname in URL")
}
u.RawQuery = ""
return u, nil
}
+3 -1
View File
@@ -7,6 +7,8 @@ struct Server {
unsigned int port; unsigned int port;
}; };
char *keychain_add(struct Server *server, char *username, char *secret); char *keychain_add(struct Server *server, char *label, char *username, char *secret);
char *keychain_get(struct Server *server, unsigned int *username_l, char **username, unsigned int *secret_l, char **secret); char *keychain_get(struct Server *server, unsigned int *username_l, char **username, unsigned int *secret_l, char **secret);
char *keychain_delete(struct Server *server); char *keychain_delete(struct Server *server);
char *keychain_list(char *credsLabel, char *** data, char *** accts, unsigned int *list_l);
void freeListData(char *** data, unsigned int length);
+217 -9
View File
@@ -1,9 +1,10 @@
package osxkeychain package osxkeychain
import ( import (
"testing" "errors"
"fmt"
"github.com/docker/docker-credential-helpers/credentials" "github.com/docker/docker-credential-helpers/credentials"
"testing"
) )
func TestOSXKeychainHelper(t *testing.T) { func TestOSXKeychainHelper(t *testing.T) {
@@ -12,8 +13,12 @@ func TestOSXKeychainHelper(t *testing.T) {
Username: "foobar", Username: "foobar",
Secret: "foobarbaz", Secret: "foobarbaz",
} }
creds1 := &credentials.Credentials{
helper := New() ServerURL: "https://foobar.docker.io:2376/v2",
Username: "foobarbaz",
Secret: "foobar",
}
helper := Osxkeychain{}
if err := helper.Add(creds); err != nil { if err := helper.Add(creds); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -31,15 +36,218 @@ func TestOSXKeychainHelper(t *testing.T) {
t.Fatalf("expected %s, got %s\n", "foobarbaz", secret) t.Fatalf("expected %s, got %s\n", "foobarbaz", secret)
} }
auths, err := helper.List()
if err != nil || len(auths) == 0 {
t.Fatal(err)
}
helper.Add(creds1)
defer helper.Delete(creds1.ServerURL)
newauths, err := helper.List()
if len(newauths)-len(auths) != 1 {
if err == nil {
t.Fatalf("Error: len(newauths): %d, len(auths): %d", len(newauths), len(auths))
}
t.Fatalf("Error: len(newauths): %d, len(auths): %d\n Error= %v", len(newauths), len(auths), err)
}
if err := helper.Delete(creds.ServerURL); err != nil { if err := helper.Delete(creds.ServerURL); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func TestMissingCredentials(t *testing.T) { // TestOSXKeychainHelperParseURL verifies that a // "scheme" is added to URLs,
helper := New() // and that invalid URLs produce an error.
_, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd") func TestOSXKeychainHelperParseURL(t *testing.T) {
if err != credentials.ErrCredentialsNotFound { tests := []struct {
t.Fatalf("exptected ErrCredentialsNotFound, got %v", err) url string
expectedURL string
err error
}{
{url: "foobar.docker.io", expectedURL: "//foobar.docker.io"},
{url: "foobar.docker.io:2376", expectedURL: "//foobar.docker.io:2376"},
{url: "//foobar.docker.io:2376", expectedURL: "//foobar.docker.io:2376"},
{url: "http://foobar.docker.io:2376", expectedURL: "http://foobar.docker.io:2376"},
{url: "https://foobar.docker.io:2376", expectedURL: "https://foobar.docker.io:2376"},
{url: "https://foobar.docker.io:2376/some/path", expectedURL: "https://foobar.docker.io:2376/some/path"},
{url: "https://foobar.docker.io:2376/some/other/path?foo=bar", expectedURL: "https://foobar.docker.io:2376/some/other/path"},
{url: "/foobar.docker.io", err: errors.New("no hostname in URL")},
{url: "ftp://foobar.docker.io:2376", err: errors.New("unsupported scheme: ftp")},
}
for _, te := range tests {
u, err := parseURL(te.url)
if te.err == nil && err != nil {
t.Errorf("Error: failed to parse URL %q: %s", te.url, err)
continue
}
if te.err != nil && err == nil {
t.Errorf("Error: expected error %q, got none when parsing URL %q", te.err, te.url)
continue
}
if te.err != nil && err.Error() != te.err.Error() {
t.Errorf("Error: expected error %q, got %q when parsing URL %q", te.err, err, te.url)
continue
}
if u != nil && u.String() != te.expectedURL {
t.Errorf("Error: expected URL: %q, but got %q for URL: %q", te.expectedURL, u.String(), te.url)
}
}
}
// TestOSXKeychainHelperRetrieveAliases verifies that secrets can be accessed
// through variations on the URL
func TestOSXKeychainHelperRetrieveAliases(t *testing.T) {
tests := []struct {
storeURL string
readURL string
}{
// stored with port, retrieved without
{"https://foobar.docker.io:2376", "https://foobar.docker.io"},
// stored as https, retrieved without scheme
{"https://foobar.docker.io:2376", "foobar.docker.io"},
// stored with path, retrieved without
{"https://foobar.docker.io:1234/one/two", "https://foobar.docker.io:1234"},
}
helper := Osxkeychain{}
defer func() {
for _, te := range tests {
helper.Delete(te.storeURL)
}
}()
// Clean store before testing.
for _, te := range tests {
helper.Delete(te.storeURL)
}
for _, te := range tests {
c := &credentials.Credentials{ServerURL: te.storeURL, Username: "hello", Secret: "world"}
if err := helper.Add(c); err != nil {
t.Errorf("Error: failed to store secret for URL %q: %s", te.storeURL, err)
continue
}
if _, _, err := helper.Get(te.readURL); err != nil {
t.Errorf("Error: failed to read secret for URL %q using %q", te.storeURL, te.readURL)
}
helper.Delete(te.storeURL)
}
}
// TestOSXKeychainHelperRetrieveStrict verifies that only matching secrets are
// returned.
func TestOSXKeychainHelperRetrieveStrict(t *testing.T) {
tests := []struct {
storeURL string
readURL string
}{
// stored as https, retrieved using http
{"https://foobar.docker.io:2376", "http://foobar.docker.io:2376"},
// stored as http, retrieved using https
{"http://foobar.docker.io:2376", "https://foobar.docker.io:2376"},
// same: stored as http, retrieved without a scheme specified (hence, using the default https://)
{"http://foobar.docker.io", "foobar.docker.io:5678"},
// non-matching ports
{"https://foobar.docker.io:1234", "https://foobar.docker.io:5678"},
// non-matching ports TODO is this desired behavior? The other way round does work
//{"https://foobar.docker.io", "https://foobar.docker.io:5678"},
// non-matching paths
{"https://foobar.docker.io:1234/one/two", "https://foobar.docker.io:1234/five/six"},
}
helper := Osxkeychain{}
defer func() {
for _, te := range tests {
helper.Delete(te.storeURL)
}
}()
// Clean store before testing.
for _, te := range tests {
helper.Delete(te.storeURL)
}
for _, te := range tests {
c := &credentials.Credentials{ServerURL: te.storeURL, Username: "hello", Secret: "world"}
if err := helper.Add(c); err != nil {
t.Errorf("Error: failed to store secret for URL %q: %s", te.storeURL, err)
continue
}
if _, _, err := helper.Get(te.readURL); err == nil {
t.Errorf("Error: managed to read secret for URL %q using %q, but should not be able to", te.storeURL, te.readURL)
}
helper.Delete(te.storeURL)
}
}
// TestOSXKeychainHelperStoreRetrieve verifies that secrets stored in the
// the keychain can be read back using the URL that was used to store them.
func TestOSXKeychainHelperStoreRetrieve(t *testing.T) {
tests := []struct {
url string
}{
{url: "foobar.docker.io"},
{url: "foobar.docker.io:2376"},
{url: "//foobar.docker.io:2376"},
{url: "https://foobar.docker.io:2376"},
{url: "http://foobar.docker.io:2376"},
{url: "https://foobar.docker.io:2376/some/path"},
{url: "https://foobar.docker.io:2376/some/other/path"},
{url: "https://foobar.docker.io:2376/some/other/path?foo=bar"},
}
helper := Osxkeychain{}
defer func() {
for _, te := range tests {
helper.Delete(te.url)
}
}()
// Clean store before testing.
for _, te := range tests {
helper.Delete(te.url)
}
// Note that we don't delete between individual tests here, to verify that
// subsequent stores/overwrites don't affect storing / retrieving secrets.
for i, te := range tests {
c := &credentials.Credentials{
ServerURL: te.url,
Username: fmt.Sprintf("user-%d", i),
Secret: fmt.Sprintf("secret-%d", i),
}
if err := helper.Add(c); err != nil {
t.Errorf("Error: failed to store secret for URL: %s: %s", te.url, err)
continue
}
user, secret, err := helper.Get(te.url)
if err != nil {
t.Errorf("Error: failed to read secret for URL %q: %s", te.url, err)
continue
}
if user != c.Username {
t.Errorf("Error: expected username %s, got username %s for URL: %s", c.Username, user, te.url)
}
if secret != c.Secret {
t.Errorf("Error: expected secret %s, got secret %s for URL: %s", c.Secret, secret, te.url)
}
}
}
func TestMissingCredentials(t *testing.T) {
helper := Osxkeychain{}
_, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd")
if !credentials.IsErrCredentialsNotFound(err) {
t.Fatalf("expected ErrCredentialsNotFound, got %v", err)
} }
} }
+13
View File
@@ -0,0 +1,13 @@
//+build go1.8
package osxkeychain
import "net/url"
func getHostname(u *url.URL) string {
return u.Hostname()
}
func getPort(u *url.URL) string {
return u.Port()
}
+41
View File
@@ -0,0 +1,41 @@
//+build !go1.8
package osxkeychain
import (
"net/url"
"strings"
)
func getHostname(u *url.URL) string {
return stripPort(u.Host)
}
func getPort(u *url.URL) string {
return portOnly(u.Host)
}
func stripPort(hostport string) string {
colon := strings.IndexByte(hostport, ':')
if colon == -1 {
return hostport
}
if i := strings.IndexByte(hostport, ']'); i != -1 {
return strings.TrimPrefix(hostport[:i], "[")
}
return hostport[:colon]
}
func portOnly(hostport string) string {
colon := strings.IndexByte(hostport, ':')
if colon == -1 {
return ""
}
if i := strings.Index(hostport, "]:"); i != -1 {
return hostport[i+len("]:"):]
}
if strings.Contains(hostport, "]") {
return ""
}
return hostport[colon+len(":"):]
}
+10
View File
@@ -0,0 +1,10 @@
package main
import (
"github.com/docker/docker-credential-helpers/credentials"
"github.com/docker/docker-credential-helpers/pass"
)
func main() {
credentials.Serve(pass.Pass{})
}
+207
View File
@@ -0,0 +1,207 @@
// A `pass` based credential helper. Passwords are stored as arguments to pass
// of the form: "$PASS_FOLDER/base64-url(serverURL)/username". We base64-url
// encode the serverURL, because under the hood pass uses files and folders, so
// /s will get translated into additional folders.
package pass
import (
"bytes"
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"strings"
"sync"
"github.com/docker/docker-credential-helpers/credentials"
)
const PASS_FOLDER = "docker-credential-helpers"
// Pass handles secrets using Linux secret-service as a store.
type Pass struct{}
// Ideally these would be stored as members of Pass, but since all of Pass's
// methods have value receivers, not pointer receivers, and changing that is
// backwards incompatible, we assume that all Pass instances share the same configuration
// initializationMutex is held while initializing so that only one 'pass'
// round-tripping is done to check pass is functioning.
var initializationMutex sync.Mutex
var passInitialized bool
// CheckInitialized checks whether the password helper can be used. It
// internally caches and so may be safely called multiple times with no impact
// on performance, though the first call may take longer.
func (p Pass) CheckInitialized() bool {
return p.checkInitialized() == nil
}
func (p Pass) checkInitialized() error {
initializationMutex.Lock()
defer initializationMutex.Unlock()
if passInitialized {
return nil
}
// In principle, we could just run `pass init`. However, pass has a bug
// where if gpg fails, it doesn't always exit 1. Additionally, pass
// uses gpg2, but gpg is the default, which may be confusing. So let's
// just explictily check that pass actually can store and retreive a
// password.
password := "pass is initialized"
name := path.Join(getPassDir(), "docker-pass-initialized-check")
_, err := p.runPassHelper(password, "insert", "-f", "-m", name)
if err != nil {
return fmt.Errorf("error initializing pass: %v", err)
}
stored, err := p.runPassHelper("", "show", name)
if err != nil {
return fmt.Errorf("error fetching password during initialization: %v", err)
}
if stored != password {
return fmt.Errorf("error round-tripping password during initialization: %q != %q", password, stored)
}
passInitialized = true
return nil
}
func (p Pass) runPass(stdinContent string, args ...string) (string, error) {
if err := p.checkInitialized(); err != nil {
return "", err
}
return p.runPassHelper(stdinContent, args...)
}
func (p Pass) runPassHelper(stdinContent string, args ...string) (string, error) {
var stdout, stderr bytes.Buffer
cmd := exec.Command("pass", args...)
cmd.Stdin = strings.NewReader(stdinContent)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
return "", fmt.Errorf("%s: %s", err, stderr.String())
}
// trim newlines; pass v1.7.1+ includes a newline at the end of `show` output
return strings.TrimRight(stdout.String(), "\n\r"), nil
}
// Add adds new credentials to the keychain.
func (h Pass) Add(creds *credentials.Credentials) error {
if creds == nil {
return errors.New("missing credentials")
}
encoded := base64.URLEncoding.EncodeToString([]byte(creds.ServerURL))
_, err := h.runPass(creds.Secret, "insert", "-f", "-m", path.Join(PASS_FOLDER, encoded, creds.Username))
return err
}
// Delete removes credentials from the store.
func (h Pass) Delete(serverURL string) error {
if serverURL == "" {
return errors.New("missing server url")
}
encoded := base64.URLEncoding.EncodeToString([]byte(serverURL))
_, err := h.runPass("", "rm", "-rf", path.Join(PASS_FOLDER, encoded))
return err
}
func getPassDir() string {
passDir := "$HOME/.password-store"
if envDir := os.Getenv("PASSWORD_STORE_DIR"); envDir != "" {
passDir = envDir
}
return os.ExpandEnv(passDir)
}
// listPassDir lists all the contents of a directory in the password store.
// Pass uses fancy unicode to emit stuff to stdout, so rather than try
// and parse this, let's just look at the directory structure instead.
func listPassDir(args ...string) ([]os.FileInfo, error) {
passDir := getPassDir()
p := path.Join(append([]string{passDir, PASS_FOLDER}, args...)...)
contents, err := ioutil.ReadDir(p)
if err != nil {
if os.IsNotExist(err) {
return []os.FileInfo{}, nil
}
return nil, err
}
return contents, nil
}
// Get returns the username and secret to use for a given registry server URL.
func (h Pass) Get(serverURL string) (string, string, error) {
if serverURL == "" {
return "", "", errors.New("missing server url")
}
encoded := base64.URLEncoding.EncodeToString([]byte(serverURL))
if _, err := os.Stat(path.Join(getPassDir(), PASS_FOLDER, encoded)); err != nil {
if os.IsNotExist(err) {
return "", "", nil
}
return "", "", err
}
usernames, err := listPassDir(encoded)
if err != nil {
return "", "", err
}
if len(usernames) < 1 {
return "", "", fmt.Errorf("no usernames for %s", serverURL)
}
actual := strings.TrimSuffix(usernames[0].Name(), ".gpg")
secret, err := h.runPass("", "show", path.Join(PASS_FOLDER, encoded, actual))
return actual, secret, err
}
// List returns the stored URLs and corresponding usernames for a given credentials label
func (h Pass) List() (map[string]string, error) {
servers, err := listPassDir()
if err != nil {
return nil, err
}
resp := map[string]string{}
for _, server := range servers {
if !server.IsDir() {
continue
}
serverURL, err := base64.URLEncoding.DecodeString(server.Name())
if err != nil {
return nil, err
}
usernames, err := listPassDir(server.Name())
if err != nil {
return nil, err
}
if len(usernames) < 1 {
return nil, fmt.Errorf("no usernames for %s", serverURL)
}
resp[string(serverURL)] = strings.TrimSuffix(usernames[0].Name(), ".gpg")
}
return resp, nil
}
+75
View File
@@ -0,0 +1,75 @@
package pass
import (
"strings"
"testing"
"github.com/docker/docker-credential-helpers/credentials"
)
func TestPassHelper(t *testing.T) {
helper := Pass{}
creds := &credentials.Credentials{
ServerURL: "https://foobar.docker.io:2376/v1",
Username: "nothing",
Secret: "isthebestmeshuggahalbum",
}
helper.Add(creds)
creds.ServerURL = "https://foobar.docker.io:9999/v2"
helper.Add(creds)
credsList, err := helper.List()
if err != nil {
t.Fatal(err)
}
for server, username := range credsList {
if !(strings.Contains(server, "2376") ||
strings.Contains(server, "9999")) {
t.Fatalf("invalid url: %s", creds.ServerURL)
}
if username != "nothing" {
t.Fatalf("invalid username: %v", username)
}
u, s, err := helper.Get(server)
if err != nil {
t.Fatal(err)
}
if u != username {
t.Fatalf("invalid username %s", u)
}
if s != "isthebestmeshuggahalbum" {
t.Fatalf("invalid secret: %s", s)
}
err = helper.Delete(server)
if err != nil {
t.Fatal(err)
}
username, _, err = helper.Get(server)
if err != nil {
t.Fatal(err)
}
if username != "" {
t.Fatalf("%s shouldn't exist any more", username)
}
}
credsList, err = helper.List()
if err != nil {
t.Fatal(err)
}
if len(credsList) != 0 {
t.Fatal("didn't delete all creds?")
}
}
+1 -1
View File
@@ -6,5 +6,5 @@ import (
) )
func main() { func main() {
credentials.Serve(secretservice.New()) credentials.Serve(secretservice.Secretservice{})
} }
+69 -5
View File
@@ -1,4 +1,5 @@
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "secretservice_linux.h" #include "secretservice_linux.h"
const SecretSchema *docker_get_schema(void) const SecretSchema *docker_get_schema(void)
@@ -6,6 +7,7 @@ const SecretSchema *docker_get_schema(void)
static const SecretSchema docker_schema = { static const SecretSchema docker_schema = {
"io.docker.Credentials", SECRET_SCHEMA_NONE, "io.docker.Credentials", SECRET_SCHEMA_NONE,
{ {
{ "label", SECRET_SCHEMA_ATTRIBUTE_STRING },
{ "server", SECRET_SCHEMA_ATTRIBUTE_STRING }, { "server", SECRET_SCHEMA_ATTRIBUTE_STRING },
{ "username", SECRET_SCHEMA_ATTRIBUTE_STRING }, { "username", SECRET_SCHEMA_ATTRIBUTE_STRING },
{ "docker_cli", SECRET_SCHEMA_ATTRIBUTE_STRING }, { "docker_cli", SECRET_SCHEMA_ATTRIBUTE_STRING },
@@ -15,11 +17,12 @@ const SecretSchema *docker_get_schema(void)
return &docker_schema; return &docker_schema;
} }
GError *add(char *server, char *username, char *secret) { GError *add(char *label, char *server, char *username, char *secret) {
GError *err = NULL; GError *err = NULL;
secret_password_store_sync (DOCKER_SCHEMA, SECRET_COLLECTION_DEFAULT, secret_password_store_sync (DOCKER_SCHEMA, SECRET_COLLECTION_DEFAULT,
server, secret, NULL, &err, server, secret, NULL, &err,
"label", label,
"server", server, "server", server,
"username", username, "username", username,
"docker_cli", "1", "docker_cli", "1",
@@ -39,7 +42,7 @@ GError *delete(char *server) {
return NULL; return NULL;
} }
char *get_username(SecretItem *item) { char *get_attribute(const char *attribute, SecretItem *item) {
GHashTable *attributes; GHashTable *attributes;
GHashTableIter iter; GHashTableIter iter;
gchar *value, *key; gchar *value, *key;
@@ -47,7 +50,7 @@ char *get_username(SecretItem *item) {
attributes = secret_item_get_attributes(item); attributes = secret_item_get_attributes(item);
g_hash_table_iter_init(&iter, attributes); g_hash_table_iter_init(&iter, attributes);
while (g_hash_table_iter_next(&iter, (void **)&key, (void **)&value)) { while (g_hash_table_iter_next(&iter, (void **)&key, (void **)&value)) {
if (strncmp(key, "username", strlen(key)) == 0) if (strncmp(key, attribute, strlen(key)) == 0)
return (char *)value; return (char *)value;
} }
g_hash_table_unref(attributes); g_hash_table_unref(attributes);
@@ -70,7 +73,7 @@ GError *get(char *server, char **username, char **secret) {
service = secret_service_get_sync(SECRET_SERVICE_NONE, NULL, &err); service = secret_service_get_sync(SECRET_SERVICE_NONE, NULL, &err);
if (err == NULL) { if (err == NULL) {
items = secret_service_search_sync(service, NULL, attributes, flags, NULL, &err); items = secret_service_search_sync(service, DOCKER_SCHEMA, attributes, flags, NULL, &err);
if (err == NULL) { if (err == NULL) {
for (l = items; l != NULL; l = g_list_next(l)) { for (l = items; l != NULL; l = g_list_next(l)) {
value = secret_item_get_schema_name(l->data); value = secret_item_get_schema_name(l->data);
@@ -84,7 +87,7 @@ GError *get(char *server, char **username, char **secret) {
*secret = strdup(secret_value_get(secretValue, &length)); *secret = strdup(secret_value_get(secretValue, &length));
secret_value_unref(secretValue); secret_value_unref(secretValue);
} }
*username = get_username(l->data); *username = get_attribute("username", l->data);
} }
g_list_free_full(items, g_object_unref); g_list_free_full(items, g_object_unref);
} }
@@ -96,3 +99,64 @@ GError *get(char *server, char **username, char **secret) {
} }
return NULL; return NULL;
} }
GError *list(char *ref_label, char *** paths, char *** accts, unsigned int *list_l) {
GList *items;
GError *err = NULL;
SecretService *service;
SecretSearchFlags flags = SECRET_SEARCH_LOAD_SECRETS | SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK;
GHashTable *attributes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
// List credentials with the right label only
g_hash_table_insert(attributes, g_strdup("label"), g_strdup(ref_label));
service = secret_service_get_sync(SECRET_SERVICE_NONE, NULL, &err);
if (err != NULL) {
return err;
}
items = secret_service_search_sync(service, NULL, attributes, flags, NULL, &err);
int numKeys = g_list_length(items);
if (err != NULL) {
return err;
}
char **tmp_paths = (char **) calloc(1,(int)sizeof(char *)*numKeys);
char **tmp_accts = (char **) calloc(1,(int)sizeof(char *)*numKeys);
// items now contains our keys from the gnome keyring
// we will now put it in our two lists to return it to go
GList *current;
int listNumber = 0;
for(current = items; current!=NULL; current = current->next) {
char *pathTmp = secret_item_get_label(current->data);
// you cannot have a key without a label in the gnome keyring
char *acctTmp = get_attribute("username",current->data);
if (acctTmp==NULL) {
acctTmp = "account not defined";
}
tmp_paths[listNumber] = (char *) calloc(1, sizeof(char)*(strlen(pathTmp)+1));
tmp_accts[listNumber] = (char *) calloc(1, sizeof(char)*(strlen(acctTmp)+1));
memcpy(tmp_paths[listNumber], pathTmp, sizeof(char)*(strlen(pathTmp)+1));
memcpy(tmp_accts[listNumber], acctTmp, sizeof(char)*(strlen(acctTmp)+1));
listNumber = listNumber + 1;
}
*paths = (char **) realloc(tmp_paths, (int)sizeof(char *)*listNumber);
*accts = (char **) realloc(tmp_accts, (int)sizeof(char *)*listNumber);
*list_l = listNumber;
return NULL;
}
void freeListData(char *** data, unsigned int length) {
int i;
for(i=0; i<length; i++) {
free((*data)[i]);
}
free(*data);
}
+46 -12
View File
@@ -14,18 +14,16 @@ import (
"github.com/docker/docker-credential-helpers/credentials" "github.com/docker/docker-credential-helpers/credentials"
) )
type secretservice struct{} // Secretservice handles secrets using Linux secret-service as a store.
type Secretservice struct{}
// New creates a new secretservice.
func New() credentials.Helper {
return secretservice{}
}
// Add adds new credentials to the keychain. // Add adds new credentials to the keychain.
func (h secretservice) Add(creds *credentials.Credentials) error { func (h Secretservice) Add(creds *credentials.Credentials) error {
if creds == nil { if creds == nil {
return errors.New("missing credentials") return errors.New("missing credentials")
} }
credsLabel := C.CString(credentials.CredsLabel)
defer C.free(unsafe.Pointer(credsLabel))
server := C.CString(creds.ServerURL) server := C.CString(creds.ServerURL)
defer C.free(unsafe.Pointer(server)) defer C.free(unsafe.Pointer(server))
username := C.CString(creds.Username) username := C.CString(creds.Username)
@@ -33,7 +31,7 @@ func (h secretservice) Add(creds *credentials.Credentials) error {
secret := C.CString(creds.Secret) secret := C.CString(creds.Secret)
defer C.free(unsafe.Pointer(secret)) defer C.free(unsafe.Pointer(secret))
if err := C.add(server, username, secret); err != nil { if err := C.add(credsLabel, server, username, secret); err != nil {
defer C.g_error_free(err) defer C.g_error_free(err)
errMsg := (*C.char)(unsafe.Pointer(err.message)) errMsg := (*C.char)(unsafe.Pointer(err.message))
return errors.New(C.GoString(errMsg)) return errors.New(C.GoString(errMsg))
@@ -41,8 +39,8 @@ func (h secretservice) Add(creds *credentials.Credentials) error {
return nil return nil
} }
// Delete removes credentials from the keychain. // Delete removes credentials from the store.
func (h secretservice) Delete(serverURL string) error { func (h Secretservice) Delete(serverURL string) error {
if serverURL == "" { if serverURL == "" {
return errors.New("missing server url") return errors.New("missing server url")
} }
@@ -58,7 +56,7 @@ func (h secretservice) Delete(serverURL string) error {
} }
// Get returns the username and secret to use for a given registry server URL. // Get returns the username and secret to use for a given registry server URL.
func (h secretservice) Get(serverURL string) (string, string, error) { func (h Secretservice) Get(serverURL string) (string, string, error) {
if serverURL == "" { if serverURL == "" {
return "", "", errors.New("missing server url") return "", "", errors.New("missing server url")
} }
@@ -78,7 +76,43 @@ func (h secretservice) Get(serverURL string) (string, string, error) {
user := C.GoString(username) user := C.GoString(username)
pass := C.GoString(secret) pass := C.GoString(secret)
if pass == "" { if pass == "" {
return "", "", credentials.ErrCredentialsNotFound return "", "", credentials.NewErrCredentialsNotFound()
} }
return user, pass, nil return user, pass, nil
} }
// List returns the stored URLs and corresponding usernames for a given credentials label
func (h Secretservice) List() (map[string]string, error) {
credsLabelC := C.CString(credentials.CredsLabel)
defer C.free(unsafe.Pointer(credsLabelC))
var pathsC **C.char
defer C.free(unsafe.Pointer(pathsC))
var acctsC **C.char
defer C.free(unsafe.Pointer(acctsC))
var listLenC C.uint
err := C.list(credsLabelC, &pathsC, &acctsC, &listLenC)
if err != nil {
defer C.free(unsafe.Pointer(err))
return nil, errors.New("Error from list function in secretservice_linux.c likely due to error in secretservice library")
}
defer C.freeListData(&pathsC, listLenC)
defer C.freeListData(&acctsC, listLenC)
resp := make(map[string]string)
listLen := int(listLenC)
if listLen == 0 {
return resp, nil
}
// The maximum capacity of the following two slices is limited to (2^29)-1 to remain compatible
// with 32-bit platforms. The size of a `*C.char` (a pointer) is 4 Byte on a 32-bit system
// and (2^29)*4 == math.MaxInt32 + 1. -- See issue golang/go#13656
pathTmp := (*[(1 << 29) - 1]*C.char)(unsafe.Pointer(pathsC))[:listLen:listLen]
acctTmp := (*[(1 << 29) - 1]*C.char)(unsafe.Pointer(acctsC))[:listLen:listLen]
for i := 0; i < listLen; i++ {
resp[C.GoString(pathTmp[i])] = C.GoString(acctTmp[i])
}
return resp, nil
}
+3 -1
View File
@@ -6,6 +6,8 @@ const SecretSchema *docker_get_schema(void) G_GNUC_CONST;
#define DOCKER_SCHEMA docker_get_schema() #define DOCKER_SCHEMA docker_get_schema()
GError *add(char *server, char *username, char *secret); GError *add(char *label, char *server, char *username, char *secret);
GError *delete(char *server); GError *delete(char *server);
GError *get(char *server, char **username, char **secret); GError *get(char *server, char **username, char **secret);
GError *list(char *label, char *** paths, char *** accts, unsigned int *list_l);
void freeListData(char *** data, unsigned int length);
+45 -4
View File
@@ -1,6 +1,7 @@
package secretservice package secretservice
import ( import (
"strings"
"testing" "testing"
"github.com/docker/docker-credential-helpers/credentials" "github.com/docker/docker-credential-helpers/credentials"
@@ -15,11 +16,37 @@ func TestSecretServiceHelper(t *testing.T) {
Secret: "foobarbaz", Secret: "foobarbaz",
} }
helper := New() helper := Secretservice{}
// Check how many docker credentials we have when starting the test
old_auths, err := helper.List()
if err != nil {
t.Fatal(err)
}
// If any docker credentials with the tests values we are providing, we
// remove them as they probably come from a previous failed test
for k, v := range old_auths {
if strings.Compare(k, creds.ServerURL) == 0 && strings.Compare(v, creds.Username) == 0 {
if err := helper.Delete(creds.ServerURL); err != nil {
t.Fatal(err)
}
}
}
// Check again how many docker credentials we have when starting the test
old_auths, err = helper.List()
if err != nil {
t.Fatal(err)
}
// Add new credentials
if err := helper.Add(creds); err != nil { if err := helper.Add(creds); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// Verify that it is inside the secret service store
username, secret, err := helper.Get(creds.ServerURL) username, secret, err := helper.Get(creds.ServerURL)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -33,17 +60,31 @@ func TestSecretServiceHelper(t *testing.T) {
t.Fatalf("expected %s, got %s\n", "foobarbaz", secret) t.Fatalf("expected %s, got %s\n", "foobarbaz", secret)
} }
// We should have one more credential than before adding
new_auths, err := helper.List()
if err != nil || (len(new_auths)-len(old_auths) != 1) {
t.Fatal(err)
}
old_auths = new_auths
// Deleting the credentials associated to current server url should succeed
if err := helper.Delete(creds.ServerURL); err != nil { if err := helper.Delete(creds.ServerURL); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// We should have one less credential than before deleting
new_auths, err = helper.List()
if err != nil || (len(old_auths)-len(new_auths) != 1) {
t.Fatal(err)
}
} }
func TestMissingCredentials(t *testing.T) { func TestMissingCredentials(t *testing.T) {
t.Skip("test requires gnome-keyring but travis CI doesn't have it") t.Skip("test requires gnome-keyring but travis CI doesn't have it")
helper := New() helper := Secretservice{}
_, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd") _, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd")
if err != credentials.ErrCredentialsNotFound { if !credentials.IsErrCredentialsNotFound(err) {
t.Fatalf("exptected ErrCredentialsNotFound, got %v", err) t.Fatalf("expected ErrCredentialsNotFound, got %v", err)
} }
} }
+21 -4
View File
@@ -1,7 +1,6 @@
package wincred package wincred
import ( import (
"C"
"encoding/binary" "encoding/binary"
"reflect" "reflect"
"syscall" "syscall"
@@ -10,6 +9,8 @@ import (
"unsafe" "unsafe"
) )
var nullPointer = unsafe.Pointer(uintptr(0))
// Create a Go string using a pointer to a zero-terminated UTF 16 encoded string. // Create a Go string using a pointer to a zero-terminated UTF 16 encoded string.
// See github.com/AllenDang/w32 // See github.com/AllenDang/w32
func utf16PtrToString(wstr *uint16) string { func utf16PtrToString(wstr *uint16) string {
@@ -36,8 +37,22 @@ func utf16ToByte(wstr []uint16) (result []byte) {
return return
} }
// Copies the given C byte array to a Go byte array (see `C.GoBytes`)
func goBytes(src unsafe.Pointer, len uint32) []byte {
if src == nullPointer {
return []byte{}
}
slice := (*[1 << 30]byte)(src)[0:len]
rv := make([]byte, len)
copy(rv, slice)
return rv[:]
}
// Convert the given CREDENTIAL struct to a more usable structure // Convert the given CREDENTIAL struct to a more usable structure
func nativeToCredential(cred *nativeCREDENTIAL) (result *Credential) { func nativeToCredential(cred *nativeCREDENTIAL) (result *Credential) {
if unsafe.Pointer(cred) == nullPointer {
return nil
}
result = new(Credential) result = new(Credential)
result.Comment = utf16PtrToString(cred.Comment) result.Comment = utf16PtrToString(cred.Comment)
result.TargetName = utf16PtrToString(cred.TargetName) result.TargetName = utf16PtrToString(cred.TargetName)
@@ -45,7 +60,7 @@ func nativeToCredential(cred *nativeCREDENTIAL) (result *Credential) {
result.UserName = utf16PtrToString(cred.UserName) result.UserName = utf16PtrToString(cred.UserName)
result.LastWritten = time.Unix(0, cred.LastWritten.Nanoseconds()) result.LastWritten = time.Unix(0, cred.LastWritten.Nanoseconds())
result.Persist = CredentialPersistence(cred.Persist) result.Persist = CredentialPersistence(cred.Persist)
result.CredentialBlob = C.GoBytes(unsafe.Pointer(cred.CredentialBlob), C.int(cred.CredentialBlobSize)) result.CredentialBlob = goBytes(unsafe.Pointer(cred.CredentialBlob), cred.CredentialBlobSize)
result.Attributes = make([]CredentialAttribute, cred.AttributeCount) result.Attributes = make([]CredentialAttribute, cred.AttributeCount)
attrSliceHeader := reflect.SliceHeader{ attrSliceHeader := reflect.SliceHeader{
Data: cred.Attributes, Data: cred.Attributes,
@@ -56,15 +71,17 @@ func nativeToCredential(cred *nativeCREDENTIAL) (result *Credential) {
for i, attr := range attrSlice { for i, attr := range attrSlice {
resultAttr := &result.Attributes[i] resultAttr := &result.Attributes[i]
resultAttr.Keyword = utf16PtrToString(attr.Keyword) resultAttr.Keyword = utf16PtrToString(attr.Keyword)
resultAttr.Value = C.GoBytes(unsafe.Pointer(attr.Value), C.int(attr.ValueSize)) resultAttr.Value = goBytes(unsafe.Pointer(attr.Value), attr.ValueSize)
} }
return result return result
} }
// Convert the given Credential object back to a CREDENTIAL struct, which can be used for calling the // Convert the given Credential object back to a CREDENTIAL struct, which can be used for calling the
// Windows APIs // Windows APIs
func nativeFromCredential(cred *Credential) (result *nativeCREDENTIAL) { func nativeFromCredential(cred *Credential) (result *nativeCREDENTIAL) {
if cred == nil {
return nil
}
result = new(nativeCREDENTIAL) result = new(nativeCREDENTIAL)
result.Flags = 0 result.Flags = 0
result.Type = 0 result.Type = 0
+42 -4
View File
@@ -8,12 +8,18 @@ import (
var ( var (
modadvapi32 = syscall.NewLazyDLL("advapi32.dll") modadvapi32 = syscall.NewLazyDLL("advapi32.dll")
procCredRead = modadvapi32.NewProc("CredReadW") procCredRead proc = modadvapi32.NewProc("CredReadW")
procCredWrite = modadvapi32.NewProc("CredWriteW") procCredWrite proc = modadvapi32.NewProc("CredWriteW")
procCredDelete = modadvapi32.NewProc("CredDeleteW") procCredDelete proc = modadvapi32.NewProc("CredDeleteW")
procCredFree = modadvapi32.NewProc("CredFree") procCredFree proc = modadvapi32.NewProc("CredFree")
procCredEnumerate proc = modadvapi32.NewProc("CredEnumerateW")
) )
// Interface for syscall.Proc: helps testing
type proc interface {
Call(a ...uintptr) (r1, r2 uintptr, lastErr error)
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa374788(v=vs.85).aspx // http://msdn.microsoft.com/en-us/library/windows/desktop/aa374788(v=vs.85).aspx
type nativeCREDENTIAL struct { type nativeCREDENTIAL struct {
Flags uint32 Flags uint32
@@ -48,6 +54,8 @@ const (
naCRED_TYPE_DOMAIN_VISIBLE_PASSWORD nativeCRED_TYPE = 0x4 naCRED_TYPE_DOMAIN_VISIBLE_PASSWORD nativeCRED_TYPE = 0x4
naCRED_TYPE_GENERIC_CERTIFICATE nativeCRED_TYPE = 0x5 naCRED_TYPE_GENERIC_CERTIFICATE nativeCRED_TYPE = 0x5
naCRED_TYPE_DOMAIN_EXTENDED nativeCRED_TYPE = 0x6 naCRED_TYPE_DOMAIN_EXTENDED nativeCRED_TYPE = 0x6
naERROR_NOT_FOUND = "Element not found."
) )
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa374804(v=vs.85).aspx // http://msdn.microsoft.com/en-us/library/windows/desktop/aa374804(v=vs.85).aspx
@@ -97,3 +105,33 @@ func nativeCredDelete(cred *Credential, typ nativeCRED_TYPE) error {
return nil return nil
} }
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa374794(v=vs.85).aspx
func nativeCredEnumerate(filter string, all bool) ([]*Credential, error) {
var count int
var pcreds uintptr
var filterPtr uintptr
if !all {
filterUtf16Ptr, _ := syscall.UTF16PtrFromString(filter)
filterPtr = uintptr(unsafe.Pointer(filterUtf16Ptr))
} else {
filterPtr = 0
}
ret, _, err := procCredEnumerate.Call(
filterPtr,
0,
uintptr(unsafe.Pointer(&count)),
uintptr(unsafe.Pointer(&pcreds)),
)
if ret == 0 {
return nil, err
}
defer procCredFree.Call(pcreds)
pcredsSlice := (*[1 << 30]uintptr)(unsafe.Pointer(pcreds))[:count:count]
creds := make([]*Credential, count)
for i := range creds {
creds[i] = nativeToCredential((*nativeCREDENTIAL)(unsafe.Pointer(pcredsSlice[i])))
}
return creds, nil
}
+11
View File
@@ -67,3 +67,14 @@ func (t *DomainPassword) Delete() (err error) {
func (t *DomainPassword) SetPassword(pw string) { func (t *DomainPassword) SetPassword(pw string) {
t.CredentialBlob = utf16ToByte(syscall.StringToUTF16(pw)) t.CredentialBlob = utf16ToByte(syscall.StringToUTF16(pw))
} }
// List the contents of the Credentials store
func List() ([]*Credential, error) {
creds, err := nativeCredEnumerate("", true)
if err != nil && err.Error() == naERROR_NOT_FOUND {
// Ignore ERROR_NOT_FOUND and return an empty list instead
creds = []*Credential{}
err = nil
}
return creds, err
}
+1 -1
View File
@@ -6,5 +6,5 @@ import (
) )
func main() { func main() {
credentials.Serve(wincred.New()) credentials.Serve(wincred.Wincred{})
} }
+42 -10
View File
@@ -1,28 +1,30 @@
package wincred package wincred
import ( import (
"bytes"
"strings"
winc "github.com/danieljoos/wincred" winc "github.com/danieljoos/wincred"
"github.com/docker/docker-credential-helpers/credentials" "github.com/docker/docker-credential-helpers/credentials"
) )
type wincred struct{} // Wincred handles secrets using the Windows credential service.
type Wincred struct{}
// New creates a new wincred.
func New() credentials.Helper {
return wincred{}
}
// Add adds new credentials to the windows credentials manager. // Add adds new credentials to the windows credentials manager.
func (h wincred) Add(creds *credentials.Credentials) error { func (h Wincred) Add(creds *credentials.Credentials) error {
credsLabels := []byte(credentials.CredsLabel)
g := winc.NewGenericCredential(creds.ServerURL) g := winc.NewGenericCredential(creds.ServerURL)
g.UserName = creds.Username g.UserName = creds.Username
g.CredentialBlob = []byte(creds.Secret) g.CredentialBlob = []byte(creds.Secret)
g.Persist = winc.PersistLocalMachine g.Persist = winc.PersistLocalMachine
g.Attributes = []winc.CredentialAttribute{{Keyword: "label", Value: credsLabels}}
return g.Write() return g.Write()
} }
// Delete removes credentials from the windows credentials manager. // Delete removes credentials from the windows credentials manager.
func (h wincred) Delete(serverURL string) error { func (h Wincred) Delete(serverURL string) error {
g, err := winc.GetGenericCredential(serverURL) g, err := winc.GetGenericCredential(serverURL)
if g == nil { if g == nil {
return nil return nil
@@ -34,10 +36,40 @@ func (h wincred) Delete(serverURL string) error {
} }
// Get retrieves credentials from the windows credentials manager. // Get retrieves credentials from the windows credentials manager.
func (h wincred) Get(serverURL string) (string, string, error) { func (h Wincred) Get(serverURL string) (string, string, error) {
g, _ := winc.GetGenericCredential(serverURL) g, _ := winc.GetGenericCredential(serverURL)
if g == nil { if g == nil {
return "", "", credentials.ErrCredentialsNotFound return "", "", credentials.NewErrCredentialsNotFound()
} }
for _, attr := range g.Attributes {
if strings.Compare(attr.Keyword, "label") == 0 &&
bytes.Compare(attr.Value, []byte(credentials.CredsLabel)) == 0 {
return g.UserName, string(g.CredentialBlob), nil return g.UserName, string(g.CredentialBlob), nil
}
}
return "", "", credentials.NewErrCredentialsNotFound()
}
// List returns the stored URLs and corresponding usernames for a given credentials label.
func (h Wincred) List() (map[string]string, error) {
creds, err := winc.List()
if err != nil {
return nil, err
}
resp := make(map[string]string)
for i := range creds {
attrs := creds[i].Attributes
for _, attr := range attrs {
if strings.Compare(attr.Keyword, "label") == 0 &&
bytes.Compare(attr.Value, []byte(credentials.CredsLabel)) == 0 {
resp[creds[i].TargetName] = creds[i].UserName
}
}
}
return resp, nil
} }
+54 -4
View File
@@ -1,6 +1,7 @@
package wincred package wincred
import ( import (
"strings"
"testing" "testing"
"github.com/docker/docker-credential-helpers/credentials" "github.com/docker/docker-credential-helpers/credentials"
@@ -12,8 +13,38 @@ func TestWinCredHelper(t *testing.T) {
Username: "foobar", Username: "foobar",
Secret: "foobarbaz", Secret: "foobarbaz",
} }
creds1 := &credentials.Credentials{
ServerURL: "https://foobar.docker.io:2376/v2",
Username: "foobarbaz",
Secret: "foobar",
}
helper := Wincred{}
// check for and remove remaining credentials from previous fail tests
oldauths, err := helper.List()
if err != nil {
t.Fatal(err)
}
for k, v := range oldauths {
if strings.Compare(k, creds.ServerURL) == 0 && strings.Compare(v, creds.Username) == 0 {
if err := helper.Delete(creds.ServerURL); err != nil {
t.Fatal(err)
}
} else if strings.Compare(k, creds1.ServerURL) == 0 && strings.Compare(v, creds1.Username) == 0 {
if err := helper.Delete(creds1.ServerURL); err != nil {
t.Fatal(err)
}
}
}
// recount for credentials
oldauths, err = helper.List()
if err != nil {
t.Fatal(err)
}
helper := New()
if err := helper.Add(creds); err != nil { if err := helper.Add(creds); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -31,15 +62,34 @@ func TestWinCredHelper(t *testing.T) {
t.Fatalf("expected %s, got %s\n", "foobarbaz", secret) t.Fatalf("expected %s, got %s\n", "foobarbaz", secret)
} }
auths, err := helper.List()
if err != nil || len(auths)-len(oldauths) != 1 {
t.Fatal(err)
}
helper.Add(creds1)
defer helper.Delete(creds1.ServerURL)
newauths, err := helper.List()
if err != nil {
t.Fatal(err)
}
if len(newauths)-len(auths) != 1 {
if err == nil {
t.Fatalf("Error: len(newauths): %d, len(auths): %d", len(newauths), len(auths))
}
t.Fatalf("Error: len(newauths): %d, len(auths): %d\n Error= %v", len(newauths), len(auths), err)
}
if err := helper.Delete(creds.ServerURL); err != nil { if err := helper.Delete(creds.ServerURL); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func TestMissingCredentials(t *testing.T) { func TestMissingCredentials(t *testing.T) {
helper := New() helper := Wincred{}
_, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd") _, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd")
if err != credentials.ErrCredentialsNotFound { if !credentials.IsErrCredentialsNotFound(err) {
t.Fatalf("exptected ErrCredentialsNotFound, got %v", err) t.Fatalf("expected ErrCredentialsNotFound, got %v", err)
} }
} }