From bea87a5a20031ec213db9a14de991c3fe00b7b69 Mon Sep 17 00:00:00 2001 From: Lenin Alevski Date: Wed, 30 Sep 2020 08:21:30 -0700 Subject: [PATCH] fix: reading multiple TLS certificates when deployed in K8S (#10601) Ignore all regular files, CAs directory and any directory that starts with `..` inside the `.minio/certs` folder --- cmd/common-main.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/cmd/common-main.go b/cmd/common-main.go index 3ad126435..5078355f4 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -334,14 +334,23 @@ func getTLSConfig() (x509Certs []*x509.Certificate, manager *certs.Manager, secu return nil, nil, false, err } for _, file := range files { - // We exclude any regular file and the "CAs/" directory. - // The "CAs/" directory contains (root) CA certificates - // that MinIO adds to its list of trusted roots (tls.Config.RootCAs). - // Therefore, "CAs/" does not contain X.509 certificates that - // are meant to be served by MinIO. - if !file.IsDir() || file.Name() == "CAs" { + // Ignore all + // - regular files + // - "CAs" directory + // - any directory which starts with ".." + if file.Mode().IsRegular() || file.Name() == "CAs" || strings.HasPrefix(file.Name(), "..") { continue } + if file.Mode()&os.ModeSymlink == os.ModeSymlink { + file, err = os.Stat(filepath.Join(root.Name(), file.Name())) + if err != nil { + // not accessible ignore + continue + } + if !file.IsDir() { + continue + } + } var ( certFile = filepath.Join(root.Name(), file.Name(), publicCertFile) @@ -350,8 +359,8 @@ func getTLSConfig() (x509Certs []*x509.Certificate, manager *certs.Manager, secu if !isFile(certFile) || !isFile(keyFile) { continue } - if err := manager.AddCertificate(certFile, keyFile); err != nil { - err = fmt.Errorf("Failed to load TLS certificate '%s': %v", certFile, err) + if err = manager.AddCertificate(certFile, keyFile); err != nil { + err = fmt.Errorf("Unable to load TLS certificate '%s,%s': %w", certFile, keyFile, err) logger.LogIf(GlobalContext, err, logger.Minio) } }