mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-28 07:11:36 +05:30
Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5241b46610 | |||
| 3cba3913ea | |||
| 8502b53592 | |||
| 5da09fd251 | |||
| dd27c246bd | |||
| 26deb2937d | |||
| a13ff50017 | |||
| 1c295f7de8 | |||
| 093af814ee | |||
| d499cf5cb9 | |||
| b049338a6b | |||
| 91fc39d57a | |||
| 317219f3a6 | |||
| 21f4937ebc | |||
| 19b711cc92 | |||
| 1f635a73ad | |||
| d68f9aeca3 | |||
| 05a9d4c50d | |||
| c2eec534ee | |||
| 5be80ca212 | |||
| f00de1b72f | |||
| 72f0375e37 | |||
| 3cce61446f | |||
| ec0d036273 | |||
| d3d9934897 | |||
| f212ea17df | |||
| 09e536a128 | |||
| 3c90bd29a4 | |||
| b8fb9690c8 | |||
| 7efaffb4c4 | |||
| 6338c06ba4 | |||
| 86c94d3e30 | |||
| 1ab1037707 | |||
| c69c0725bb | |||
| a8de4f6e8a | |||
| 4fbc86d7d0 | |||
| 2d19ebb7f4 | |||
| 054c53824f | |||
| be1808e3ed | |||
| e1d4c012bc | |||
| ad6ee5d58d | |||
| 94be56b6f4 | |||
| 37bf8afe8b | |||
| 3d7e1817f2 | |||
| 5651367281 | |||
| d8f57a18c6 | |||
| 4bc0bc2a85 | |||
| 167b137eb4 | |||
| 2a67ef1524 | |||
| 6ba4edf6e9 | |||
| fa4a4d4f71 | |||
| 4d60b372aa | |||
| 607bf3c174 | |||
| 74f4f75bc1 | |||
| 0e7779e5a1 | |||
| fb9549d396 | |||
| ed11c58ebf | |||
| 79ab7059b0 | |||
| 18d35e4984 | |||
| cdde659563 | |||
| 71779cf7f5 | |||
| 51c78cdc14 | |||
| 120e37f15d | |||
| 4962f775bf |
+9
-2
@@ -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
|
||||||
|
|||||||
+35
-1
@@ -4,6 +4,41 @@ 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)
|
## v0.4.0 (Go client, Mac OS X, Windows, Linux)
|
||||||
|
|
||||||
- Full implementation for OSX ready
|
- Full implementation for OSX ready
|
||||||
@@ -11,7 +46,6 @@ The platform released is identified after the tag name.
|
|||||||
- Implement client.List, change list API
|
- Implement client.List, change list API
|
||||||
- mac: delete credentials before adding them to avoid already exist error (fixes #37)
|
- mac: delete credentials before adding them to avoid already exist error (fixes #37)
|
||||||
|
|
||||||
|
|
||||||
## v0.3.0 (Go client)
|
## v0.3.0 (Go client)
|
||||||
|
|
||||||
- Add Go client library to talk with the native programs.
|
- Add Go client library to talk with the native programs.
|
||||||
|
|||||||
+6
-30
@@ -11,20 +11,16 @@
|
|||||||
[Org]
|
[Org]
|
||||||
[Org."Core maintainers"]
|
[Org."Core maintainers"]
|
||||||
people = [
|
people = [
|
||||||
"aaronlehmann",
|
|
||||||
"calavera",
|
|
||||||
"coolljt0725",
|
"coolljt0725",
|
||||||
"cpuguy83",
|
"cpuguy83",
|
||||||
"crosbymichael",
|
"crosbymichael",
|
||||||
"dnephin",
|
"dnephin",
|
||||||
"dongluochen",
|
|
||||||
"duglin",
|
"duglin",
|
||||||
"estesp",
|
"estesp",
|
||||||
"icecrime",
|
|
||||||
"jhowardmsft",
|
"jhowardmsft",
|
||||||
"lk4d4",
|
|
||||||
"mavenugo",
|
"mavenugo",
|
||||||
"mhbauer",
|
"mhbauer",
|
||||||
|
"n4ss",
|
||||||
"runcom",
|
"runcom",
|
||||||
"stevvooe",
|
"stevvooe",
|
||||||
"thajeztah",
|
"thajeztah",
|
||||||
@@ -44,16 +40,6 @@
|
|||||||
|
|
||||||
# ADD YOURSELF HERE IN ALPHABETICAL ORDER
|
# ADD YOURSELF HERE IN ALPHABETICAL ORDER
|
||||||
|
|
||||||
[people.aaronlehmann]
|
|
||||||
Name = "Aaron Lehmann"
|
|
||||||
Email = "aaron.lehmann@docker.com"
|
|
||||||
GitHub = "aaronlehmann"
|
|
||||||
|
|
||||||
[people.calavera]
|
|
||||||
Name = "David Calavera"
|
|
||||||
Email = "david.calavera@gmail.com"
|
|
||||||
GitHub = "calavera"
|
|
||||||
|
|
||||||
[people.coolljt0725]
|
[people.coolljt0725]
|
||||||
Name = "Lei Jitang"
|
Name = "Lei Jitang"
|
||||||
Email = "leijitang@huawei.com"
|
Email = "leijitang@huawei.com"
|
||||||
@@ -74,11 +60,6 @@
|
|||||||
Email = "dnephin@gmail.com"
|
Email = "dnephin@gmail.com"
|
||||||
GitHub = "dnephin"
|
GitHub = "dnephin"
|
||||||
|
|
||||||
[people.dongluochen]
|
|
||||||
Name = "Dongluo Chen"
|
|
||||||
Email = "dongluo.chen@docker.com"
|
|
||||||
GitHub = "dongluochen"
|
|
||||||
|
|
||||||
[people.duglin]
|
[people.duglin]
|
||||||
Name = "Doug Davis"
|
Name = "Doug Davis"
|
||||||
Email = "dug@us.ibm.com"
|
Email = "dug@us.ibm.com"
|
||||||
@@ -89,21 +70,11 @@
|
|||||||
Email = "estesp@linux.vnet.ibm.com"
|
Email = "estesp@linux.vnet.ibm.com"
|
||||||
GitHub = "estesp"
|
GitHub = "estesp"
|
||||||
|
|
||||||
[people.icecrime]
|
|
||||||
Name = "Arnaud Porterie"
|
|
||||||
Email = "arnaud@docker.com"
|
|
||||||
GitHub = "icecrime"
|
|
||||||
|
|
||||||
[people.jhowardmsft]
|
[people.jhowardmsft]
|
||||||
Name = "John Howard"
|
Name = "John Howard"
|
||||||
Email = "jhoward@microsoft.com"
|
Email = "jhoward@microsoft.com"
|
||||||
GitHub = "jhowardmsft"
|
GitHub = "jhowardmsft"
|
||||||
|
|
||||||
[people.lk4d4]
|
|
||||||
Name = "Alexander Morozov"
|
|
||||||
Email = "lk4d4@docker.com"
|
|
||||||
GitHub = "lk4d4"
|
|
||||||
|
|
||||||
[people.mavenugo]
|
[people.mavenugo]
|
||||||
Name = "Madhu Venugopal"
|
Name = "Madhu Venugopal"
|
||||||
Email = "madhu@docker.com"
|
Email = "madhu@docker.com"
|
||||||
@@ -114,6 +85,11 @@
|
|||||||
Email = "mbauer@us.ibm.com"
|
Email = "mbauer@us.ibm.com"
|
||||||
GitHub = "mhbauer"
|
GitHub = "mhbauer"
|
||||||
|
|
||||||
|
[people.n4ss]
|
||||||
|
Name = "Nassim Eddequiouaq"
|
||||||
|
Email = "eddequiouaq.nassim@gmail.com"
|
||||||
|
GitHub = "n4ss"
|
||||||
|
|
||||||
[people.runcom]
|
[people.runcom]
|
||||||
Name = "Antonio Murdaca"
|
Name = "Antonio Murdaca"
|
||||||
Email = "runcom@redhat.com"
|
Email = "runcom@redhat.com"
|
||||||
|
|||||||
@@ -1,38 +1,48 @@
|
|||||||
.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 = 0.5.0
|
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:
|
clean:
|
||||||
rm -rf bin
|
rm -rf bin
|
||||||
rm -rf release
|
rm -rf release
|
||||||
|
|
||||||
osxkeychain:
|
osxkeychain:
|
||||||
mkdir bin
|
mkdir -p bin
|
||||||
go build -ldflags -s -o bin/docker-credential-osxkeychain osxkeychain/cmd/main_darwin.go
|
go build -ldflags -s -o bin/docker-credential-osxkeychain osxkeychain/cmd/main_darwin.go
|
||||||
|
|
||||||
codesign: osxkeychain
|
osxcodesign: osxkeychain
|
||||||
$(eval SIGNINGHASH = $(shell security find-identity -v -p codesigning | grep "Developer ID Application: Docker Inc" | cut -d ' ' -f 4))
|
$(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 -log codesign -s $(SIGNINGHASH) --force --verbose bin/docker-credential-osxkeychain
|
||||||
xcrun codesign --verify --deep --strict --verbose=2 --display bin/docker-credential-osxkeychain
|
xcrun codesign --verify --deep --strict --verbose=2 --display bin/docker-credential-osxkeychain
|
||||||
|
|
||||||
osxrelease: clean test codesign
|
osxrelease: clean vet_osx lint fmt test osxcodesign
|
||||||
mkdir -p release
|
mkdir -p release
|
||||||
|
@echo "\nPackaging version ${VERSION}\n"
|
||||||
cd bin && tar cvfz ../release/docker-credential-osxkeychain-v$(VERSION)-amd64.tar.gz docker-credential-osxkeychain
|
cd bin && tar cvfz ../release/docker-credential-osxkeychain-v$(VERSION)-amd64.tar.gz docker-credential-osxkeychain
|
||||||
|
|
||||||
secretservice:
|
secretservice:
|
||||||
mkdir 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 bin
|
mkdir -p bin
|
||||||
go build -o bin/docker-credential-wincred.exe 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
|
||||||
go test -v `go list ./... | grep -v /vendor/`
|
go test -v `go list ./... | grep -v /vendor/`
|
||||||
@@ -40,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)
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ You can see examples of each function in the [client](https://godoc.org/github.c
|
|||||||
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.
|
||||||
2. 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.
|
||||||
3. 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
|
||||||
|
|
||||||
|
|||||||
+12
-55
@@ -1,67 +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
|
|
||||||
description: "Visit the [Changelog](https://github.com/docker/docker-credential-helpers/blob/master/CHANGELOG.md) for a detailed description of what's new in this release."
|
|
||||||
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
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
+36
-2
@@ -9,12 +9,27 @@ import (
|
|||||||
"github.com/docker/docker-credential-helpers/credentials"
|
"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.
|
// Store uses an external program to save credentials.
|
||||||
func Store(program ProgramFunc, credentials *credentials.Credentials) error {
|
func Store(program ProgramFunc, creds *credentials.Credentials) error {
|
||||||
cmd := program("store")
|
cmd := program("store")
|
||||||
|
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
if err := json.NewEncoder(buffer).Encode(credentials); err != nil {
|
if err := json.NewEncoder(buffer).Encode(creds); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cmd.Input(buffer)
|
cmd.Input(buffer)
|
||||||
@@ -22,6 +37,11 @@ func Store(program ProgramFunc, credentials *credentials.Credentials) error {
|
|||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t := strings.TrimSpace(string(out))
|
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 fmt.Errorf("error storing credentials - err: %v, out: `%s`", err, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +61,10 @@ func Get(program ProgramFunc, serverURL string) (*credentials.Credentials, error
|
|||||||
return nil, credentials.NewErrCredentialsNotFound()
|
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)
|
return nil, fmt.Errorf("error getting credentials - err: %v, out: `%s`", err, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +86,11 @@ func Erase(program ProgramFunc, serverURL string) error {
|
|||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t := strings.TrimSpace(string(out))
|
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 fmt.Errorf("error erasing credentials - err: %v, out: `%s`", err, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +104,11 @@ func List(program ProgramFunc) (map[string]string, error) {
|
|||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t := strings.TrimSpace(string(out))
|
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)
|
return nil, fmt.Errorf("error listing credentials - err: %v, out: `%s`", err, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ func (m *mockProgram) Output() ([]byte, error) {
|
|||||||
return []byte(credentials.NewErrCredentialsNotFound().Error()), errProgramExited
|
return []byte(credentials.NewErrCredentialsNotFound().Error()), errProgramExited
|
||||||
case invalidServerAddress:
|
case invalidServerAddress:
|
||||||
return []byte("program failed"), errProgramExited
|
return []byte("program failed"), errProgramExited
|
||||||
|
case "":
|
||||||
|
return []byte(credentials.NewErrCredentialsMissingServerURL().Error()), errProgramExited
|
||||||
}
|
}
|
||||||
case "store":
|
case "store":
|
||||||
var c credentials.Credentials
|
var c credentials.Credentials
|
||||||
@@ -158,12 +160,16 @@ func TestGet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
missingServerURLErr := credentials.NewErrCredentialsMissingServerURL()
|
||||||
|
|
||||||
invalid := []struct {
|
invalid := []struct {
|
||||||
serverURL string
|
serverURL string
|
||||||
err string
|
err string
|
||||||
}{
|
}{
|
||||||
{missingCredsAddress, credentials.NewErrCredentialsNotFound().Error()},
|
{missingCredsAddress, credentials.NewErrCredentialsNotFound().Error()},
|
||||||
{invalidServerAddress, "error getting credentials - err: exited 1, out: `program failed`"},
|
{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 {
|
for _, v := range invalid {
|
||||||
|
|||||||
+20
-1
@@ -1,7 +1,9 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,11 +18,28 @@ type ProgramFunc func(args ...string) Program
|
|||||||
|
|
||||||
// NewShellProgramFunc creates programs that are executed in a Shell.
|
// NewShellProgramFunc creates programs that are executed in a Shell.
|
||||||
func NewShellProgramFunc(name string) ProgramFunc {
|
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 func(args ...string) Program {
|
||||||
return &Shell{cmd: exec.Command(name, args...)}
|
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.
|
// Shell invokes shell commands to talk with a remote credentials helper.
|
||||||
type Shell struct {
|
type Shell struct {
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
|
|||||||
@@ -17,11 +17,28 @@ type Credentials struct {
|
|||||||
Secret string
|
Secret string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Docker credentials should be labeled as such in credentials stores that allow labelling.
|
// 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,
|
// 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"
|
// Windows credentials manager and Linux libsecret. Default value is "Docker Credentials"
|
||||||
var CredsLabel = "Docker Credentials"
|
var CredsLabel = "Docker Credentials"
|
||||||
|
|
||||||
|
// SetCredsLabel is a simple setter for CredsLabel
|
||||||
func SetCredsLabel(label string) {
|
func SetCredsLabel(label string) {
|
||||||
CredsLabel = label
|
CredsLabel = label
|
||||||
}
|
}
|
||||||
@@ -34,7 +51,7 @@ func SetCredsLabel(label string) {
|
|||||||
func Serve(helper Helper) {
|
func Serve(helper Helper) {
|
||||||
var err error
|
var err error
|
||||||
if len(os.Args) != 2 {
|
if len(os.Args) != 2 {
|
||||||
err = fmt.Errorf("Usage: %s <store|get|erase|list>", os.Args[0])
|
err = fmt.Errorf("Usage: %s <store|get|erase|list|version>", os.Args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -58,6 +75,8 @@ func HandleCommand(helper Helper, key string, in io.Reader, out io.Writer) error
|
|||||||
return Erase(helper, in)
|
return Erase(helper, in)
|
||||||
case "list":
|
case "list":
|
||||||
return List(helper, out)
|
return List(helper, out)
|
||||||
|
case "version":
|
||||||
|
return PrintVersion(out)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Unknown credential action `%s`", key)
|
return fmt.Errorf("Unknown credential action `%s`", key)
|
||||||
}
|
}
|
||||||
@@ -81,6 +100,10 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +123,9 @@ 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 {
|
||||||
@@ -107,6 +133,7 @@ func Get(helper Helper, reader io.Reader, writer io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp := Credentials{
|
resp := Credentials{
|
||||||
|
ServerURL: serverURL,
|
||||||
Username: username,
|
Username: username,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
}
|
}
|
||||||
@@ -135,6 +162,9 @@ 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)
|
||||||
}
|
}
|
||||||
@@ -148,3 +178,9 @@ func List(helper Helper, writer io.Writer) error {
|
|||||||
}
|
}
|
||||||
return json.NewEncoder(writer).Encode(accts)
|
return json.NewEncoder(writer).Encode(accts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//PrintVersion outputs the current version.
|
||||||
|
func PrintVersion(writer io.Writer) error {
|
||||||
|
fmt.Fprintln(writer, Version)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -73,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{
|
||||||
@@ -115,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{
|
||||||
@@ -144,6 +210,30 @@ func TestErase(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
func TestList(t *testing.T) {
|
||||||
//This tests that there is proper input an output into the byte stream
|
//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
|
//Individual stores are very OS specific and have been tested in osxkeychain and secretservice respectively
|
||||||
|
|||||||
+68
-3
@@ -1,8 +1,15 @@
|
|||||||
package credentials
|
package credentials
|
||||||
|
|
||||||
// ErrCredentialsNotFound standarizes the not found error, so every helper returns
|
const (
|
||||||
// the same message and docker can handle it properly.
|
// ErrCredentialsNotFound standardizes the not found error, so every helper returns
|
||||||
const errCredentialsNotFoundMessage = "credentials not found in native keychain"
|
// 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
|
// errCredentialsNotFound represents an error
|
||||||
// raised when credentials are not in the store.
|
// raised when credentials are not in the store.
|
||||||
@@ -35,3 +42,61 @@ func IsErrCredentialsNotFound(err error) bool {
|
|||||||
func IsErrCredentialsNotFoundMessage(err string) bool {
|
func IsErrCredentialsNotFoundMessage(err string) bool {
|
||||||
return err == errCredentialsNotFoundMessage
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package credentials
|
||||||
|
|
||||||
|
// Version holds a string describing the current version
|
||||||
|
const Version = "0.6.0"
|
||||||
@@ -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
@@ -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
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
9
|
||||||
@@ -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
|
||||||
Executable
+17
@@ -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
|
||||||
|
|
||||||
@@ -135,30 +135,27 @@ func (h Osxkeychain) List() (map[string]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func splitServer(serverURL string) (*C.struct_Server, error) {
|
func splitServer(serverURL string) (*C.struct_Server, error) {
|
||||||
u, err := url.Parse(serverURL)
|
u, err := parseURL(serverURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hostAndPort := strings.Split(u.Host, ":")
|
|
||||||
host := hostAndPort[0]
|
|
||||||
var port int
|
|
||||||
if len(hostAndPort) == 2 {
|
|
||||||
p, err := strconv.Atoi(hostAndPort[1])
|
|
||||||
if err != nil {
|
|
||||||
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
|
||||||
@@ -168,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
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package osxkeychain
|
package osxkeychain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"github.com/docker/docker-credential-helpers/credentials"
|
"github.com/docker/docker-credential-helpers/credentials"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -54,6 +56,194 @@ func TestOSXKeychainHelper(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestOSXKeychainHelperParseURL verifies that a // "scheme" is added to URLs,
|
||||||
|
// and that invalid URLs produce an error.
|
||||||
|
func TestOSXKeychainHelperParseURL(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
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) {
|
func TestMissingCredentials(t *testing.T) {
|
||||||
helper := Osxkeychain{}
|
helper := Osxkeychain{}
|
||||||
_, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd")
|
_, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd")
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
@@ -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(":"):]
|
||||||
|
}
|
||||||
@@ -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{})
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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?")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -105,8 +105,11 @@ func (h Secretservice) List() (map[string]string, error) {
|
|||||||
if listLen == 0 {
|
if listLen == 0 {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
pathTmp := (*[1 << 30]*C.char)(unsafe.Pointer(pathsC))[:listLen:listLen]
|
// The maximum capacity of the following two slices is limited to (2^29)-1 to remain compatible
|
||||||
acctTmp := (*[1 << 30]*C.char)(unsafe.Pointer(acctsC))[:listLen:listLen]
|
// 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++ {
|
for i := 0; i < listLen; i++ {
|
||||||
resp[C.GoString(pathTmp[i])] = C.GoString(acctTmp[i])
|
resp[C.GoString(pathTmp[i])] = C.GoString(acctTmp[i])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package wincred
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"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"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Wincred handles secrets using the Windows credential service.
|
// Wincred handles secrets using the Windows credential service.
|
||||||
@@ -12,11 +13,12 @@ type Wincred struct{}
|
|||||||
|
|
||||||
// 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{{"label", []byte(credentials.CredsLabel)}}
|
g.Attributes = []winc.CredentialAttribute{{Keyword: "label", Value: credsLabels}}
|
||||||
|
|
||||||
return g.Write()
|
return g.Write()
|
||||||
}
|
}
|
||||||
@@ -39,7 +41,14 @@ func (h Wincred) Get(serverURL string) (string, string, error) {
|
|||||||
if g == nil {
|
if g == nil {
|
||||||
return "", "", credentials.NewErrCredentialsNotFound()
|
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.
|
// List returns the stored URLs and corresponding usernames for a given credentials label.
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package wincred
|
package wincred
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker-credential-helpers/credentials"
|
"github.com/docker/docker-credential-helpers/credentials"
|
||||||
)
|
)
|
||||||
@@ -63,7 +63,7 @@ func TestWinCredHelper(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auths, err := helper.List()
|
auths, err := helper.List()
|
||||||
if err != nil || len(auths) - len(oldauths) != 1 {
|
if err != nil || len(auths)-len(oldauths) != 1 {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user