mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-28 07:11:36 +05:30
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5241b46610 | |||
| 3cba3913ea | |||
| 8502b53592 | |||
| 5da09fd251 | |||
| dd27c246bd | |||
| 26deb2937d | |||
| a13ff50017 | |||
| 1c295f7de8 | |||
| 093af814ee | |||
| d499cf5cb9 | |||
| b049338a6b | |||
| 91fc39d57a | |||
| 317219f3a6 | |||
| 21f4937ebc | |||
| 19b711cc92 | |||
| 1f635a73ad |
+8
-2
@@ -3,20 +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.8
|
- 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
|
- 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
|
||||||
|
|||||||
-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"
|
||||||
|
|||||||
+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
|
||||||
|
|||||||
+61
-93
@@ -5,6 +5,7 @@
|
|||||||
package pass
|
package pass
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -13,139 +14,114 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/docker/docker-credential-helpers/credentials"
|
"github.com/docker/docker-credential-helpers/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
const PASS_FOLDER = "docker-credential-helpers"
|
const PASS_FOLDER = "docker-credential-helpers"
|
||||||
|
|
||||||
var (
|
// Pass handles secrets using Linux secret-service as a store.
|
||||||
PassInitialized bool
|
type Pass struct{}
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
// 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
|
// 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
|
// 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
|
// 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
|
// just explictily check that pass actually can store and retreive a
|
||||||
// password.
|
// password.
|
||||||
password := "pass is initialized"
|
password := "pass is initialized"
|
||||||
name := path.Join(PASS_FOLDER, "docker-pass-initialized-check")
|
name := path.Join(getPassDir(), "docker-pass-initialized-check")
|
||||||
|
|
||||||
_, err := runPass(password, "insert", "-f", "-m", name)
|
_, err := p.runPassHelper(password, "insert", "-f", "-m", name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return fmt.Errorf("error initializing pass: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stored, err := runPass("", "show", name)
|
stored, err := p.runPassHelper("", "show", name)
|
||||||
PassInitialized = err == nil && stored == password
|
if err != nil {
|
||||||
|
return fmt.Errorf("error fetching password during initialization: %v", err)
|
||||||
if PassInitialized {
|
|
||||||
runPass("", "rm", "-rf", name)
|
|
||||||
}
|
}
|
||||||
|
if stored != password {
|
||||||
|
return fmt.Errorf("error round-tripping password during initialization: %q != %q", password, stored)
|
||||||
|
}
|
||||||
|
passInitialized = true
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func runPass(stdinContent string, args ...string) (string, error) {
|
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 := exec.Command("pass", args...)
|
||||||
|
cmd.Stdin = strings.NewReader(stdinContent)
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
|
||||||
stdin, err := cmd.StdinPipe()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", fmt.Errorf("%s: %s", err, stderr.String())
|
||||||
}
|
|
||||||
defer stdin.Close()
|
|
||||||
|
|
||||||
stderr, err := cmd.StderrPipe()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer stderr.Close()
|
|
||||||
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer stdout.Close()
|
|
||||||
|
|
||||||
err = cmd.Start()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = stdin.Write([]byte(stdinContent))
|
// trim newlines; pass v1.7.1+ includes a newline at the end of `show` output
|
||||||
if err != nil {
|
return strings.TrimRight(stdout.String(), "\n\r"), nil
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
stdin.Close()
|
|
||||||
|
|
||||||
errContent, err := ioutil.ReadAll(stderr)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("error reading stderr: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := ioutil.ReadAll(stdout)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("Error reading stdout: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdErr := cmd.Wait()
|
|
||||||
if cmdErr != nil {
|
|
||||||
return "", fmt.Errorf("%s: %s", cmdErr, errContent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(result), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass handles secrets using Linux secret-service as a store.
|
|
||||||
type Pass struct{}
|
|
||||||
|
|
||||||
// Add adds new credentials to the keychain.
|
// Add adds new credentials to the keychain.
|
||||||
func (h Pass) Add(creds *credentials.Credentials) error {
|
func (h Pass) Add(creds *credentials.Credentials) error {
|
||||||
if !PassInitialized {
|
|
||||||
return errors.New("pass store is uninitialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
if creds == nil {
|
if creds == nil {
|
||||||
return errors.New("missing credentials")
|
return errors.New("missing credentials")
|
||||||
}
|
}
|
||||||
|
|
||||||
encoded := base64.URLEncoding.EncodeToString([]byte(creds.ServerURL))
|
encoded := base64.URLEncoding.EncodeToString([]byte(creds.ServerURL))
|
||||||
|
|
||||||
_, err := runPass(creds.Secret, "insert", "-f", "-m", path.Join(PASS_FOLDER, encoded, creds.Username))
|
_, err := h.runPass(creds.Secret, "insert", "-f", "-m", path.Join(PASS_FOLDER, encoded, creds.Username))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete removes credentials from the store.
|
// Delete removes credentials from the store.
|
||||||
func (h Pass) Delete(serverURL string) error {
|
func (h Pass) Delete(serverURL string) error {
|
||||||
if !PassInitialized {
|
|
||||||
return errors.New("pass store is uninitialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
if serverURL == "" {
|
if serverURL == "" {
|
||||||
return errors.New("missing server url")
|
return errors.New("missing server url")
|
||||||
}
|
}
|
||||||
|
|
||||||
encoded := base64.URLEncoding.EncodeToString([]byte(serverURL))
|
encoded := base64.URLEncoding.EncodeToString([]byte(serverURL))
|
||||||
_, err := runPass("", "rm", "-rf", path.Join(PASS_FOLDER, encoded))
|
_, err := h.runPass("", "rm", "-rf", path.Join(PASS_FOLDER, encoded))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPassDir() string {
|
func getPassDir() string {
|
||||||
passDir := os.ExpandEnv("$HOME/.password-store")
|
passDir := "$HOME/.password-store"
|
||||||
for _, e := range os.Environ() {
|
if envDir := os.Getenv("PASSWORD_STORE_DIR"); envDir != "" {
|
||||||
parts := strings.SplitN(e, "=", 2)
|
passDir = envDir
|
||||||
if len(parts) < 2 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if parts[0] != "PASSWORD_STORE_DIR" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
passDir = parts[1]
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
return os.ExpandEnv(passDir)
|
||||||
return passDir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// listPassDir lists all the contents of a directory in the password store.
|
// listPassDir lists all the contents of a directory in the password store.
|
||||||
@@ -168,10 +144,6 @@ func listPassDir(args ...string) ([]os.FileInfo, error) {
|
|||||||
|
|
||||||
// Get returns the username and secret to use for a given registry server URL.
|
// Get returns the username and secret to use for a given registry server URL.
|
||||||
func (h Pass) Get(serverURL string) (string, string, error) {
|
func (h Pass) Get(serverURL string) (string, string, error) {
|
||||||
if !PassInitialized {
|
|
||||||
return "", "", errors.New("pass store is uninitialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
if serverURL == "" {
|
if serverURL == "" {
|
||||||
return "", "", errors.New("missing server url")
|
return "", "", errors.New("missing server url")
|
||||||
}
|
}
|
||||||
@@ -180,7 +152,7 @@ func (h Pass) Get(serverURL string) (string, string, error) {
|
|||||||
|
|
||||||
if _, err := os.Stat(path.Join(getPassDir(), PASS_FOLDER, encoded)); err != nil {
|
if _, err := os.Stat(path.Join(getPassDir(), PASS_FOLDER, encoded)); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return "", "", nil;
|
return "", "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", "", err
|
return "", "", err
|
||||||
@@ -196,16 +168,12 @@ func (h Pass) Get(serverURL string) (string, string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actual := strings.TrimSuffix(usernames[0].Name(), ".gpg")
|
actual := strings.TrimSuffix(usernames[0].Name(), ".gpg")
|
||||||
secret, err := runPass("", "show", path.Join(PASS_FOLDER, encoded, actual))
|
secret, err := h.runPass("", "show", path.Join(PASS_FOLDER, encoded, actual))
|
||||||
return actual, secret, err
|
return actual, secret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 Pass) List() (map[string]string, error) {
|
func (h Pass) List() (map[string]string, error) {
|
||||||
if !PassInitialized {
|
|
||||||
return nil, errors.New("pass store is uninitialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
servers, err := listPassDir()
|
servers, err := listPassDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -13,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()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user