Skip to content

Commit 3f17e2e

Browse files
committed
ignore ENOENT errors when parsing .crt files
As always listing files in a dir to then read them is racy as the file might have been removed in the meantime. Thus we must ignore ENOENT errors when the file is opened. Now here the code already did not cause an hard error but it will cause a spurious warning in such case. There is really no need to log that as it can cause flakes for podman. Now there is the case here for .cert and .key files where both files must be present for a valid config. Ignoring ENOENT there seems wrong as it would hide a common misconfiguration where only one of the files exists. That mean the race can still cause a failure when these files are removed from the dir. Signed-off-by: Paul Holzinger <[email protected]>
1 parent c9771a8 commit 3f17e2e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

pkg/tlsclientconfig/tlsclientconfig.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tlsclientconfig
33
import (
44
"crypto/tls"
55
"crypto/x509"
6+
"errors"
67
"fmt"
78
"net"
89
"net/http"
@@ -36,12 +37,9 @@ func SetupCertificates(dir string, tlsc *tls.Config) error {
3637
logrus.Debugf(" crt: %s", fullPath)
3738
data, err := os.ReadFile(fullPath)
3839
if err != nil {
39-
if os.IsNotExist(err) {
40-
// Dangling symbolic link?
41-
// Race with someone who deleted the
42-
// file after we read the directory's
43-
// list of contents?
44-
logrus.Warnf("error reading certificate %q: %v", fullPath, err)
40+
if errors.Is(err, os.ErrNotExist) {
41+
// file must have been removed between the directory listing
42+
// and the open call, ignore that as it is a expected race
4543
continue
4644
}
4745
return err

0 commit comments

Comments
 (0)