Skip to content

Commit

Permalink
chore: Skip hidden folders from custom-ca registration (#4332)
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>
  • Loading branch information
JorTurFer authored Mar 8, 2023
1 parent 7238408 commit 7b7a96b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/util/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io/fs"
"os"
"path"
"strings"

logf "sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -55,17 +56,20 @@ func getRootCAs() *x509.CertPool {
}

for _, file := range files {
if file.IsDir() {
if file.IsDir() || strings.HasPrefix(file.Name(), "..") {
logger.V(1).Info(fmt.Sprintf("%s isn't a valid certificate", file.Name()))
continue
}

certs, err := os.ReadFile(path.Join(customCAPath, file.Name()))
if err != nil {
logger.Error(err, fmt.Sprintf("Failed to append %q to certPool", file.Name()))
logger.Error(err, fmt.Sprintf("error reading %q", file.Name()))
continue
}

if ok := rootCAs.AppendCertsFromPEM(certs); !ok {
logger.Error(fmt.Errorf("no certs appended"), fmt.Sprintf("the certificate %s hasn't been added to the pool", file.Name()))
continue
}
logger.V(1).Info(fmt.Sprintf("the certificate %s has been added to the pool", file.Name()))
}
Expand Down

0 comments on commit 7b7a96b

Please sign in to comment.