diff --git a/cache/contenthash/checksum.go b/cache/contenthash/checksum.go index 7b592c794f8ed..25b6643af2515 100644 --- a/cache/contenthash/checksum.go +++ b/cache/contenthash/checksum.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "crypto/sha256" + "github.com/Microsoft/go-winio" "io" "os" "path" @@ -1034,7 +1035,7 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow scanPath = resolvedPath } - err = filepath.Walk(scanPath, func(itemPath string, fi os.FileInfo, err error) error { + walkFn := func(itemPath string, fi os.FileInfo, err error) error { if scanCounterEnable { scanCounter.Add(1) } @@ -1073,7 +1074,13 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow txn.Insert(k, cr) } return nil + } + + privileges := []string{winio.SeBackupPrivilege} + err = winio.RunWithPrivileges(privileges, func() error { + return filepath.Walk(scanPath, walkFn) }) + if err != nil { return err }