mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-28 15:21:29 +05:30
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a9f93a99f | |||
| 063cca0a6d | |||
| 152d64310b | |||
| 77e30bd9dd | |||
| 74636a1592 | |||
| a3c1b5b757 | |||
| 6f4b0a7c06 | |||
| 1546024a83 | |||
| ecb01138bd | |||
| df92c83808 | |||
| 123ba1b7cd | |||
| 9c18f033f7 | |||
| d6c1f136e4 | |||
| 73e5f5dbfe | |||
| 5241b46610 | |||
| 3cba3913ea | |||
| 8502b53592 | |||
| 5da09fd251 | |||
| dd27c246bd | |||
| 26deb2937d | |||
| a13ff50017 | |||
| 1c295f7de8 | |||
| 093af814ee | |||
| d499cf5cb9 | |||
| b049338a6b | |||
| 91fc39d57a | |||
| 317219f3a6 | |||
| 21f4937ebc | |||
| 19b711cc92 | |||
| 1f635a73ad | |||
| 302e4ae938 | |||
| d68f9aeca3 | |||
| 05a9d4c50d | |||
| c2eec534ee | |||
| 5be80ca212 | |||
| f00de1b72f | |||
| 72f0375e37 | |||
| 3cce61446f | |||
| ec0d036273 | |||
| d3d9934897 | |||
| f212ea17df | |||
| 09e536a128 | |||
| 3c90bd29a4 | |||
| b8fb9690c8 | |||
| 7efaffb4c4 | |||
| 6338c06ba4 | |||
| 86c94d3e30 | |||
| 1ab1037707 | |||
| c69c0725bb | |||
| a8de4f6e8a | |||
| 4fbc86d7d0 | |||
| 79f93e5e69 |
+5
-3
@@ -3,19 +3,21 @@
|
|||||||
sudo: required
|
sudo: required
|
||||||
language: go
|
language: go
|
||||||
dist: trusty
|
dist: trusty
|
||||||
|
osx_image: xcode10.1
|
||||||
os:
|
os:
|
||||||
- linux
|
- linux
|
||||||
- osx
|
- osx
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
go:
|
go:
|
||||||
- 1.8
|
- 1.12.x
|
||||||
install: make deps
|
|
||||||
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
|
||||||
@@ -27,7 +29,7 @@
|
|||||||
deploy:
|
deploy:
|
||||||
provider: releases
|
provider: releases
|
||||||
api_key:
|
api_key:
|
||||||
secure: "cGs5cao/MeVQVnum+Pr/Tpv+w83NsqGVS3wxvi3LYEf2ON4Kkmtd+Alwi0YFkGPJmSY0jZOct8NVK/M70qSnIU4l+AAq9+3KSMv23u4xrmy2sQog3AF+Ve3Rac+iYwZHOWwGs9I67CSuVv0vjJNVsDsTVefc25lHJImjRvXIS4p9xYzRPeUDCoqAo/QMVE+vFiMyxydsvt8fhd0gZCjPYWEpyHe9tjZ1tr1HsHZKFAjVb6AmF45d8rvadPoVUuLaOtr35wDC3XRKEvCZUefQpwLkrNj7j2L1rVGlY1xTE2APpLtvfd7R1Mx6kSfS1Gm3Pwcv3mugadXIhecL0lsdnU+BANjX3VUiv4ryzTPbsge966mv9ZQYwAzgCQTWRtMNJqsAnPZTeAkiOntd+HMQbPpxljOxv1sjDPY+EIZesyB3yQRJI8vMxqFcAjxeRyLcBqEnRFC2nd/Ln0KZ7ZFu16FcpNqRojdBayyypuXKqAiBNwtp4ti/65x8eHfBJuNjJtNZkRsJEYam4CYMRLxds9plKQfkaZ8045PKpyXO8fMpUhrfqSVID4IrYvD+io6XoXtdR4Lk6isZ2EgrjdrqgdG70S5lwKihL4iAi2F2ZCWhngFhkeNVOZunEWE6qZMk5wKODajR9sixGDApGPZQVojHwCNRGILZaHZ39JCIj3s="
|
secure: "$GITHUB_TOKEN"
|
||||||
# upload file artifacts using a glob expression.
|
# upload file artifacts using a glob expression.
|
||||||
# It requires both options `file_glob` and `file`:
|
# It requires both options `file_glob` and `file`:
|
||||||
# https://github.com/travis-ci/dpl/blob/master/lib/dpl/provider/releases.rb#L47-L53
|
# https://github.com/travis-ci/dpl/blob/master/lib/dpl/provider/releases.rb#L47-L53
|
||||||
|
|||||||
@@ -4,6 +4,17 @@ 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)
|
## v0.5.2 (Mac OS X, Windows, Linux)
|
||||||
|
|
||||||
- Add a `version` command to output the version
|
- Add a `version` command to output the version
|
||||||
|
|||||||
-30
@@ -11,18 +11,13 @@
|
|||||||
[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",
|
"n4ss",
|
||||||
@@ -45,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"
|
||||||
@@ -75,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"
|
||||||
@@ -90,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"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.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 }')
|
VERSION := $(shell grep 'const Version' credentials/version.go | awk -F'"' '{ print $$2 }')
|
||||||
@@ -6,14 +6,14 @@ VERSION := $(shell grep 'const Version' credentials/version.go | awk -F'"' '{ pr
|
|||||||
all: test
|
all: test
|
||||||
|
|
||||||
deps:
|
deps:
|
||||||
go get github.com/golang/lint/golint
|
go get -u golang.org/x/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
|
||||||
|
|
||||||
osxcodesign: osxkeychain
|
osxcodesign: osxkeychain
|
||||||
@@ -27,13 +27,22 @@ osxrelease: clean vet_osx lint fmt test osxcodesign
|
|||||||
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/`
|
||||||
@@ -59,3 +68,15 @@ fmt:
|
|||||||
gofmt -s -l `ls **/*.go | grep -v vendor`
|
gofmt -s -l `ls **/*.go | grep -v vendor`
|
||||||
|
|
||||||
validate: vet lint fmt
|
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)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ The programs in this repository are written with the Go programming language. Th
|
|||||||
$ go get github.com/docker/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 an executable in the `bin` directory inside the repository.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cd $GOPATH/docker/docker-credentials-helpers
|
$ cd $GOPATH/docker/docker-credentials-helpers
|
||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,13 +2,13 @@ image: Visual Studio 2015
|
|||||||
environment:
|
environment:
|
||||||
GOPATH: c:\gopath
|
GOPATH: c:\gopath
|
||||||
|
|
||||||
|
stack: go 1.8.7
|
||||||
|
|
||||||
clone_folder: c:\gopath\src\github.com\docker\docker-credential-helpers
|
clone_folder: c:\gopath\src\github.com\docker\docker-credential-helpers
|
||||||
clone_depth: 10
|
clone_depth: 10
|
||||||
|
|
||||||
before_build:
|
before_build:
|
||||||
- set PATH=%PATH%;C:\MinGW\bin;
|
- set PATH=%PATH%;C:\MinGW\bin;
|
||||||
- set PATH=%PATH%;C:\go18\bin;
|
|
||||||
- set GOROOT=C:\go18
|
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- mingw32-make vet_win wincred
|
- mingw32-make vet_win wincred
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
+17
-5
@@ -1,6 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -17,15 +18,26 @@ 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: newCmdRedirectErr(name, args)}
|
return &Shell{cmd: createProgramCmdRedirectErr(name, args, env)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCmdRedirectErr(name string, args []string) *exec.Cmd {
|
func createProgramCmdRedirectErr(commandName string, args []string, env *map[string]string) *exec.Cmd {
|
||||||
newCmd := exec.Command(name, args...)
|
programCmd := exec.Command(commandName, args...)
|
||||||
newCmd.Stderr = os.Stderr
|
programCmd.Env = os.Environ()
|
||||||
return newCmd
|
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.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package credentials
|
package credentials
|
||||||
|
|
||||||
// Version holds a string describing the current version
|
// Version holds a string describing the current version
|
||||||
const Version = "0.5.2"
|
const Version = "0.6.2"
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package osxkeychain
|
package osxkeychain
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo CFLAGS: -x objective-c -mmacosx-version-min=10.10
|
#cgo CFLAGS: -x objective-c -mmacosx-version-min=10.11
|
||||||
#cgo LDFLAGS: -framework Security -framework Foundation -mmacosx-version-min=10.10
|
#cgo LDFLAGS: -framework Security -framework Foundation -mmacosx-version-min=10.11
|
||||||
|
|
||||||
#include "osxkeychain_darwin.h"
|
#include "osxkeychain_darwin.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -10,12 +10,11 @@ package osxkeychain
|
|||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/url"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/docker/docker-credential-helpers/credentials"
|
"github.com/docker/docker-credential-helpers/credentials"
|
||||||
|
"github.com/docker/docker-credential-helpers/registryurl"
|
||||||
)
|
)
|
||||||
|
|
||||||
// errCredentialsNotFound is the specific error message returned by OS X
|
// errCredentialsNotFound is the specific error message returned by OS X
|
||||||
@@ -113,6 +112,10 @@ func (h Osxkeychain) List() (map[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 {
|
||||||
|
return make(map[string]string), nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil, errors.New(goMsg)
|
return nil, errors.New(goMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +138,7 @@ 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 := parseURL(serverURL)
|
u, err := registryurl.Parse(serverURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -145,7 +148,7 @@ func splitServer(serverURL string) (*C.struct_Server, error) {
|
|||||||
proto = C.kSecProtocolTypeHTTP
|
proto = C.kSecProtocolTypeHTTP
|
||||||
}
|
}
|
||||||
var port int
|
var port int
|
||||||
p := getPort(u)
|
p := registryurl.GetPort(u)
|
||||||
if p != "" {
|
if p != "" {
|
||||||
port, err = strconv.Atoi(p)
|
port, err = strconv.Atoi(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -155,7 +158,7 @@ func splitServer(serverURL string) (*C.struct_Server, error) {
|
|||||||
|
|
||||||
return &C.struct_Server{
|
return &C.struct_Server{
|
||||||
proto: C.SecProtocolType(proto),
|
proto: C.SecProtocolType(proto),
|
||||||
host: C.CString(getHostname(u)),
|
host: C.CString(registryurl.GetHostname(u)),
|
||||||
port: C.uint(port),
|
port: C.uint(port),
|
||||||
path: C.CString(u.Path),
|
path: C.CString(u.Path),
|
||||||
}, nil
|
}, nil
|
||||||
@@ -165,32 +168,3 @@ 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,10 +1,10 @@
|
|||||||
package osxkeychain
|
package osxkeychain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/docker/docker-credential-helpers/credentials"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker-credential-helpers/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOSXKeychainHelper(t *testing.T) {
|
func TestOSXKeychainHelper(t *testing.T) {
|
||||||
@@ -56,46 +56,6 @@ 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
|
// TestOSXKeychainHelperRetrieveAliases verifies that secrets can be accessed
|
||||||
// through variations on the URL
|
// through variations on the URL
|
||||||
func TestOSXKeychainHelperRetrieveAliases(t *testing.T) {
|
func TestOSXKeychainHelperRetrieveAliases(t *testing.T) {
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
//+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,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,192 @@
|
|||||||
|
// 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
|
||||||
|
}
|
||||||
|
// We just run a `pass ls`, if it fails then pass is not initialized.
|
||||||
|
_, err := p.runPassHelper("", "ls")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("pass not initialized: %v", err)
|
||||||
|
}
|
||||||
|
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?")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package registryurl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Parse 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 Parse(registryURL string) (*url.URL, error) {
|
||||||
|
// Check if registryURL has a scheme, otherwise add `//` as scheme.
|
||||||
|
if !strings.Contains(registryURL, "://") && !strings.HasPrefix(registryURL, "//") {
|
||||||
|
registryURL = "//" + registryURL
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := url.Parse(registryURL)
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package registryurl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestHelperParseURL verifies that a // "scheme" is added to URLs,
|
||||||
|
// and that invalid URLs produce an error.
|
||||||
|
func TestHelperParseURL(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 := Parse(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
//+build go1.8
|
||||||
|
|
||||||
|
package registryurl
|
||||||
|
|
||||||
|
import (
|
||||||
|
url "net/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetHostname(u *url.URL) string {
|
||||||
|
return u.Hostname()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPort(u *url.URL) string {
|
||||||
|
return u.Port()
|
||||||
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
//+build !go1.8
|
//+build !go1.8
|
||||||
|
|
||||||
package osxkeychain
|
package registryurl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
url "net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getHostname(u *url.URL) string {
|
func GetHostname(u *url.URL) string {
|
||||||
return stripPort(u.Host)
|
return stripPort(u.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPort(u *url.URL) string {
|
func GetPort(u *url.URL) string {
|
||||||
return portOnly(u.Host)
|
return portOnly(u.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ func (h Secretservice) List() (map[string]string, error) {
|
|||||||
var listLenC C.uint
|
var listLenC C.uint
|
||||||
err := C.list(credsLabelC, &pathsC, &acctsC, &listLenC)
|
err := C.list(credsLabelC, &pathsC, &acctsC, &listLenC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
defer C.free(unsafe.Pointer(err))
|
defer C.g_error_free(err)
|
||||||
return nil, errors.New("Error from list function in secretservice_linux.c likely due to error in secretservice library")
|
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(&pathsC, listLenC)
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ package wincred
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"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"
|
||||||
|
"github.com/docker/docker-credential-helpers/registryurl"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Wincred handles secrets using the Windows credential service.
|
// Wincred handles secrets using the Windows credential service.
|
||||||
@@ -13,11 +15,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()
|
||||||
}
|
}
|
||||||
@@ -36,10 +39,18 @@ 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)
|
target, err := getTarget(serverURL)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
} else if target == "" {
|
||||||
|
return "", "", credentials.NewErrCredentialsNotFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
g, _ := winc.GetGenericCredential(target)
|
||||||
if g == nil {
|
if g == nil {
|
||||||
return "", "", credentials.NewErrCredentialsNotFound()
|
return "", "", credentials.NewErrCredentialsNotFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, attr := range g.Attributes {
|
for _, attr := range g.Attributes {
|
||||||
if strings.Compare(attr.Keyword, "label") == 0 &&
|
if strings.Compare(attr.Keyword, "label") == 0 &&
|
||||||
bytes.Compare(attr.Value, []byte(credentials.CredsLabel)) == 0 {
|
bytes.Compare(attr.Value, []byte(credentials.CredsLabel)) == 0 {
|
||||||
@@ -50,6 +61,71 @@ func (h Wincred) Get(serverURL string) (string, string, error) {
|
|||||||
return "", "", credentials.NewErrCredentialsNotFound()
|
return "", "", credentials.NewErrCredentialsNotFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTarget(serverURL string) (string, error) {
|
||||||
|
s, err := registryurl.Parse(serverURL)
|
||||||
|
if err != nil {
|
||||||
|
return serverURL, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
creds, err := winc.List()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var targets []string
|
||||||
|
for i := range creds {
|
||||||
|
attrs := creds[i].Attributes
|
||||||
|
for _, attr := range attrs {
|
||||||
|
if attr.Keyword == "label" && bytes.Equal(attr.Value, []byte(credentials.CredsLabel)) {
|
||||||
|
targets = append(targets, creds[i].TargetName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if target, found := findMatch(s, targets, exactMatch); found {
|
||||||
|
return target, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if target, found := findMatch(s, targets, approximateMatch); found {
|
||||||
|
return target, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func findMatch(serverUrl *url.URL, targets []string, matches func(url.URL, url.URL) bool) (string, bool) {
|
||||||
|
for _, target := range targets {
|
||||||
|
tURL, err := registryurl.Parse(target)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if matches(*serverUrl, *tURL) {
|
||||||
|
return target, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
func exactMatch(serverURL, target url.URL) bool {
|
||||||
|
return serverURL.String() == target.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func approximateMatch(serverURL, target url.URL) bool {
|
||||||
|
//if scheme is missing assume it is the same as target
|
||||||
|
if serverURL.Scheme == "" {
|
||||||
|
serverURL.Scheme = target.Scheme
|
||||||
|
}
|
||||||
|
//if port is missing assume it is the same as target
|
||||||
|
if serverURL.Port() == "" && target.Port() != "" {
|
||||||
|
serverURL.Host = serverURL.Host + ":" + target.Port()
|
||||||
|
}
|
||||||
|
//if path is missing assume it is the same as target
|
||||||
|
if serverURL.Path == "" {
|
||||||
|
serverURL.Path = target.Path
|
||||||
|
}
|
||||||
|
return serverURL.String() == target.String()
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
func (h Wincred) List() (map[string]string, error) {
|
func (h Wincred) List() (map[string]string, error) {
|
||||||
creds, err := winc.List()
|
creds, err := winc.List()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package wincred
|
package wincred
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -86,6 +87,154 @@ func TestWinCredHelper(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestWinCredHelperRetrieveAliases verifies that secrets can be accessed
|
||||||
|
// through variations on the URL
|
||||||
|
func TestWinCredHelperRetrieveAliases(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", "foobar.docker.io"},
|
||||||
|
|
||||||
|
// stored with path, retrieved without
|
||||||
|
{"https://foobar.docker.io/one/two", "https://foobar.docker.io"},
|
||||||
|
}
|
||||||
|
|
||||||
|
helper := Wincred{}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestWinCredHelperRetrieveStrict verifies that only matching secrets are
|
||||||
|
// returned.
|
||||||
|
func TestWinCredHelperRetrieveStrict(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 := Wincred{}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestWinCredHelperStoreRetrieve verifies that secrets stored in the
|
||||||
|
// the keychain can be read back using the URL that was used to store them.
|
||||||
|
func TestWinCredHelperStoreRetrieve(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 := Wincred{}
|
||||||
|
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 := Wincred{}
|
helper := Wincred{}
|
||||||
_, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd")
|
_, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd")
|
||||||
|
|||||||
Reference in New Issue
Block a user