From 6be8fce6f8c1f3b16b8b39f5e163839205bfe43d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 25 Jun 2019 00:12:01 +0200 Subject: [PATCH] Windows: skip permissions check on key This code was attempting to check Linux file permissions to determine if the key was accessible by other users, which doesn't work, and therefore prevented users on Windows to load keys. Skipping this check on Windows (correspinding tests were already skipped). Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 15d361fd77d69514aa544fbcb5cb7ce15c3184f4) Signed-off-by: Sebastiaan van Stijn --- cli/command/trust/key_load.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cli/command/trust/key_load.go b/cli/command/trust/key_load.go index 9263cbda47..3b2c04bac9 100644 --- a/cli/command/trust/key_load.go +++ b/cli/command/trust/key_load.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "os" + "runtime" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" @@ -69,12 +70,14 @@ func loadPrivKey(streams command.Streams, keyPath string, options keyLoadOptions } func getPrivKeyBytesFromPath(keyPath string) ([]byte, error) { - fileInfo, err := os.Stat(keyPath) - if err != nil { - return nil, err - } - if fileInfo.Mode()&nonOwnerReadWriteMask != 0 { - return nil, fmt.Errorf("private key file %s must not be readable or writable by others", keyPath) + if runtime.GOOS != "windows" { + fileInfo, err := os.Stat(keyPath) + if err != nil { + return nil, err + } + if fileInfo.Mode()&nonOwnerReadWriteMask != 0 { + return nil, fmt.Errorf("private key file %s must not be readable or writable by others", keyPath) + } } from, err := os.OpenFile(keyPath, os.O_RDONLY, notary.PrivExecPerms)