Skip to content

Commit 6270718

Browse files
committed
feat: add support for gopass as a credential store
This change adds support for `gopass` as a credential store, based on the `pass` implementation. Closes: docker#138 Closes: docker#166 Signed-off-by: sudoforge <[email protected]>
1 parent 4ede49c commit 6270718

File tree

7 files changed

+395
-12
lines changed

7 files changed

+395
-12
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ jobs:
6363
run: |
6464
sudo apt-get update
6565
sudo apt-get install -y dbus-x11 gnome-keyring libsecret-1-dev pass
66+
-
67+
name: Install gopass
68+
env:
69+
GOPASS_VERSION: v1.15.5
70+
run: go install github.com/gopasspw/gopass@${{ env.GOPASS_VERSION }}
71+
6672
-
6773
name: GPG conf
6874
if: ${{ matrix.os == 'ubuntu-20.04' }}
@@ -92,8 +98,20 @@ jobs:
9298
run: |
9399
if [ "${{ matrix.os }}" = "ubuntu-20.04" ]; then
94100
echo -e "trust\n5\ny" | gpg --batch --no-tty --command-fd 0 --edit-key 7D851EB72D73BDA0
101+
# initialize password store for `pass`
95102
pass init 7D851EB72D73BDA0
96103
fi
104+
105+
# initialize password store for `gopass`
106+
gopass config mounts.path /root/.gopass-password-store 1>/dev/null
107+
gopass config core.autopush false 1>/dev/null
108+
gopass config core.autosync false 1>/dev/null
109+
gopass config core.exportkeys false 1>/dev/null
110+
gopass config core.notifications false 1>/dev/null
111+
gopass config core.color false 1>/dev/null
112+
gopass config core.nopager true 1>/dev/null
113+
gopass init --crypto gpgcli --storage fs 7D851EB72D73BDA0
114+
97115
go test -short -v -coverprofile=./coverage.txt -covermode=atomic ./...
98116
go tool cover -func=./coverage.txt
99117
shell: bash

Dockerfile

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ARG XX_VERSION=1.2.1
55
ARG OSXCROSS_VERSION=11.3-r7-debian
66
ARG GOLANGCI_LINT_VERSION=v1.51.1
77
ARG DEBIAN_FRONTEND=noninteractive
8+
ARG GOPASS_VERSION=v1.15.5
89

910
ARG PACKAGE=github.com/docker/docker-credential-helpers
1011

@@ -68,12 +69,19 @@ RUN xx-apt-get install -y binutils gcc libc6-dev libgcc-10-dev libsecret-1-dev p
6869

6970
FROM base AS test
7071
ARG DEBIAN_FRONTEND
72+
ARG GOPASS_VERSION
7173
RUN xx-apt-get install -y dbus-x11 gnome-keyring gpg-agent gpgconf libsecret-1-dev pass
74+
RUN --mount=type=bind,target=. \
75+
--mount=type=cache,target=/root/.cache \
76+
--mount=type=cache,target=/go/pkg/mod \
77+
GOFLAGS='' go install github.com/gopasspw/gopass@${GOPASS_VERSION}
7278
RUN --mount=type=bind,target=. \
7379
--mount=type=cache,target=/root/.cache \
7480
--mount=type=cache,target=/go/pkg/mod <<EOT
7581
set -e
82+
7683
cp -r .github/workflows/fixtures /root/.gnupg
84+
chmod 0400 /root/.gnupg
7785
gpg-connect-agent "RELOADAGENT" /bye
7886
gpg --import --batch --yes /root/.gnupg/7D851EB72D73BDA0.key
7987
gpg --update-trustdb
@@ -82,7 +90,20 @@ RUN --mount=type=bind,target=. \
8290
gpg-connect-agent "KEYINFO 3E2D1142AA59E08E16B7E2C64BA6DDC773B1A627" /bye
8391
gpg-connect-agent "PRESET_PASSPHRASE BA83FC8947213477F28ADC019F6564A956456163 -1 77697468207374757069642070617373706872617365" /bye
8492
gpg-connect-agent "KEYINFO BA83FC8947213477F28ADC019F6564A956456163" /bye
93+
94+
# initialize password store for `pass`
8595
pass init 7D851EB72D73BDA0
96+
97+
# initialize password store for `gopass`
98+
gopass config mounts.path /root/.gopass-password-store 1>/dev/null
99+
gopass config core.autopush false 1>/dev/null
100+
gopass config core.autosync false 1>/dev/null
101+
gopass config core.exportkeys false 1>/dev/null
102+
gopass config core.notifications false 1>/dev/null
103+
gopass config core.color false 1>/dev/null
104+
gopass config core.nopager true 1>/dev/null
105+
gopass init --crypto gpgcli --storage fs 7D851EB72D73BDA0
106+
86107
gpg -k
87108

88109
mkdir /out
@@ -106,7 +127,8 @@ RUN --mount=type=bind,target=. \
106127
--mount=type=bind,source=/tmp/.revision,target=/tmp/.revision,from=version <<EOT
107128
set -ex
108129
xx-go --wrap
109-
make build-pass build-secretservice PACKAGE=$PACKAGE VERSION=$(cat /tmp/.version) REVISION=$(cat /tmp/.revision) DESTDIR=/out
130+
make build-gopass build-pass build-secretservice PACKAGE=$PACKAGE VERSION=$(cat /tmp/.version) REVISION=$(cat /tmp/.revision) DESTDIR=/out
131+
xx-verify /out/docker-credential-gopass
110132
xx-verify /out/docker-credential-pass
111133
xx-verify /out/docker-credential-secretservice
112134
EOT
@@ -122,7 +144,8 @@ RUN --mount=type=bind,target=. \
122144
set -ex
123145
xx-go --wrap
124146
go install std
125-
make build-osxkeychain build-pass PACKAGE=$PACKAGE VERSION=$(cat /tmp/.version) REVISION=$(cat /tmp/.revision) DESTDIR=/out
147+
make build-gopass build-osxkeychain build-pass PACKAGE=$PACKAGE VERSION=$(cat /tmp/.version) REVISION=$(cat /tmp/.revision) DESTDIR=/out
148+
xx-verify /out/docker-credential-gopass
126149
xx-verify /out/docker-credential-osxkeychain
127150
xx-verify /out/docker-credential-pass
128151
EOT
@@ -136,7 +159,9 @@ RUN --mount=type=bind,target=. \
136159
--mount=type=bind,source=/tmp/.revision,target=/tmp/.revision,from=version <<EOT
137160
set -ex
138161
xx-go --wrap
139-
make build-wincred PACKAGE=$PACKAGE VERSION=$(cat /tmp/.version) REVISION=$(cat /tmp/.revision) DESTDIR=/out
162+
make build-gopass build-wincred PACKAGE=$PACKAGE VERSION=$(cat /tmp/.version) REVISION=$(cat /tmp/.revision) DESTDIR=/out
163+
mv /out/docker-credential-gopass /out/docker-credential-gopass.exe
164+
xx-verify /out/docker-credential-gopass.exe
140165
mv /out/docker-credential-wincred /out/docker-credential-wincred.exe
141166
xx-verify /out/docker-credential-wincred.exe
142167
EOT

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ clean:
1616
rm -rf bin
1717

1818
.PHONY: build-%
19-
build-%: # build, can be one of build-osxkeychain build-pass build-secretservice build-wincred
19+
build-%: # build, can be one of build-gopass build-osxkeychain build-pass build-secretservice build-wincred
2020
go build -trimpath -ldflags="$(GO_LDFLAGS) -X ${GO_PKG}/credentials.Name=docker-credential-$*" -o "$(DESTDIR)/docker-credential-$*" ./$*/cmd/
2121

2222
# aliases for build-* targets
23-
.PHONY: osxkeychain secretservice pass wincred
23+
.PHONY: gopass osxkeychain secretservice pass wincred
24+
gopass: build-gopass
2425
osxkeychain: build-osxkeychain
2526
secretservice: build-secretservice
2627
pass: build-pass

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,26 @@ You can see examples of each function in the [client](https://godoc.org/github.c
7777

7878
### Available programs
7979

80-
1. osxkeychain: Provides a helper to use the OS X keychain as credentials store.
81-
2. secretservice: Provides a helper to use the D-Bus secret service as credentials store.
82-
3. wincred: Provides a helper to use Windows credentials manager as store.
83-
4. pass: Provides a helper to use `pass` as credentials store.
80+
- gopass: Provides a helper to use `gopass` as credentials store.
81+
- osxkeychain: Provides a helper to use the OS X keychain as credentials store.
82+
- pass: Provides a helper to use `pass` as credentials store.
83+
- secretservice: Provides a helper to use the D-Bus secret service as credentials store.
84+
- wincred: Provides a helper to use Windows credentials manager as store.
8485

85-
#### Note
86+
#### Note regarding `gopass`
8687

87-
`pass` needs to be configured for `docker-credential-pass` to work properly.
88-
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`.
88+
`gopass` requires manual intervention in order for `docker-credential-gopass` to
89+
work properly: a password store must be initialized. Please ensure to review the
90+
upstream [quick start guide][gopass-quick-start] for more information.
91+
92+
[gopass-quick-start]: https://github.com/gopasspw/gopass#quick-start-guide
93+
94+
#### Note regarding `pass`
95+
96+
`pass` requires manual interview in order for `docker-credential-pass` to
97+
work properly. It must be initialized with a `gpg2` key ID. Make sure your GPG
98+
key exists is in `gpg2` keyring as `pass` uses `gpg2` instead of the regular
99+
`gpg`.
89100

90101
## Development
91102

gopass/cmd/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import (
4+
"github.com/docker/docker-credential-helpers/credentials"
5+
"github.com/docker/docker-credential-helpers/gopass"
6+
)
7+
8+
func main() {
9+
credentials.Serve(gopass.Gopass{})
10+
}

0 commit comments

Comments
 (0)