rootless: fix open /etc/docker/plugins: permission denied

Fix issue 47436

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2024-03-14 14:32:01 +09:00
parent 1f539a6e85
commit d742659877
No known key found for this signature in database
GPG key ID: 49524C6F9F638F1A

View file

@ -10,6 +10,8 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/containerd/containerd/pkg/userns"
"github.com/containerd/log"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -56,10 +58,16 @@ func (l *LocalRegistry) Scan() ([]string, error) {
for _, p := range l.specsPaths { for _, p := range l.specsPaths {
dirEntries, err = os.ReadDir(p) dirEntries, err = os.ReadDir(p)
if err != nil && !os.IsNotExist(err) { if err != nil {
if os.IsNotExist(err) {
continue
}
if os.IsPermission(err) && userns.RunningInUserNS() {
log.L.Debug(err.Error())
continue
}
return nil, errors.Wrap(err, "error reading dir entries") return nil, errors.Wrap(err, "error reading dir entries")
} }
for _, entry := range dirEntries { for _, entry := range dirEntries {
if entry.IsDir() { if entry.IsDir() {
infos, err := os.ReadDir(filepath.Join(p, entry.Name())) infos, err := os.ReadDir(filepath.Join(p, entry.Name()))