浏览代码

Merge pull request #40243 from sh7dm/40236-cert-permission

Use certs.d from XDG_CONFIG_HOME when in rootless mode (fixes #40236)
Sebastiaan van Stijn 5 年之前
父节点
当前提交
7c3d53ed64
共有 1 个文件被更改,包括 17 次插入2 次删除
  1. 17 2
      registry/registry.go

+ 17 - 2
registry/registry.go

@@ -16,6 +16,9 @@ import (
 	"github.com/docker/distribution/registry/client/transport"
 	"github.com/docker/distribution/registry/client/transport"
 	"github.com/docker/go-connections/tlsconfig"
 	"github.com/docker/go-connections/tlsconfig"
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
+
+	"github.com/docker/docker/pkg/homedir"
+	"github.com/docker/docker/rootless"
 )
 )
 
 
 var (
 var (
@@ -31,7 +34,19 @@ func newTLSConfig(hostname string, isSecure bool) (*tls.Config, error) {
 	tlsConfig.InsecureSkipVerify = !isSecure
 	tlsConfig.InsecureSkipVerify = !isSecure
 
 
 	if isSecure && CertsDir != "" {
 	if isSecure && CertsDir != "" {
-		hostDir := filepath.Join(CertsDir, cleanPath(hostname))
+		certsDir := CertsDir
+
+		if rootless.RunningWithRootlessKit() {
+			configHome, err := homedir.GetConfigHome()
+			if err != nil {
+				return nil, err
+			}
+
+			certsDir = filepath.Join(configHome, "docker/certs.d")
+		}
+
+		hostDir := filepath.Join(certsDir, cleanPath(hostname))
+
 		logrus.Debugf("hostDir: %s", hostDir)
 		logrus.Debugf("hostDir: %s", hostDir)
 		if err := ReadCertsDirectory(tlsConfig, hostDir); err != nil {
 		if err := ReadCertsDirectory(tlsConfig, hostDir); err != nil {
 			return nil, err
 			return nil, err
@@ -55,7 +70,7 @@ func hasFile(files []os.FileInfo, name string) bool {
 // provided TLS configuration.
 // provided TLS configuration.
 func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error {
 func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error {
 	fs, err := ioutil.ReadDir(directory)
 	fs, err := ioutil.ReadDir(directory)
-	if err != nil && !os.IsNotExist(err) {
+	if err != nil && !os.IsNotExist(err) && !os.IsPermission(err) {
 		return err
 		return err
 	}
 	}