Skip to content

Skip over directory entries with no read permission#228

Open
dtolnay wants to merge 2 commits intorustls:mainfrom
dtolnay-contrib:eperm
Open

Skip over directory entries with no read permission#228
dtolnay wants to merge 2 commits intorustls:mainfrom
dtolnay-contrib:eperm

Conversation

@dtolnay
Copy link

@dtolnay dtolnay commented Feb 18, 2026

Some systems have certificates that are intended to be only readable by root. I came across this with the following error from rustls-native-certs:

Error {
    context: "failed to read PEM from file",
    kind: Io {
        inner: Os {
            code: 13,
            kind: PermissionDenied,
            message: "Permission denied",
        },
        path: "/etc/pki/tls/certs/sendmail.pem",
    },
}

In my experience, at least with Linux, it is an expectation that tools that load information from arbitrarily many files in a directory will skip over files lacking read permission for the current user. For example the /etc/profile in Debian systems contains the following logic using [ -r ("True if file is readable by you") to skip unreadable files — this makes it convenient to disable individual scripts temporarily using chmod -r and re-enable using chmod +r.
https://salsa.debian.org/sanvila/base-files/-/blob/master/share/profile

if [ -d /etc/profile.d ]; then
  for i in $(run-parts --list --regex '^[a-zA-Z0-9_][a-zA-Z0-9._-]*\.sh$' /etc/profile.d); do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

Another example, fc-cache skips font files without read permission in .local/share/fonts.

This is not something that can be implemented downstream of this crate, because the caller of rustls_native_certs::load_native_certs() cannot tell in general whether a PermissionDenied error in CertificateResult.errors originates from loading SSL_CERT_FILE (which we do not want to ignore) vs SSL_CERT_DIR (this PR ignores), without reimplementing much of rustls-native-certs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant