fix: avoid creating directory at file path in allowRead bwrap mounts
intermediaryDirs() was called with the full path including the leaf component, causing --dir to be emitted for files like ~/.npmrc. This created a directory at that path, making the subsequent --ro-bind fail with "Can't create file at ...: Is a directory". Now checks isDirectory() and uses filepath.Dir() for file paths so intermediary dirs are only created up to the parent.
This commit is contained in:
@@ -519,8 +519,14 @@ func buildDenyByDefaultMounts(cfg *config.Config, cwd string, debug bool) []stri
|
|||||||
if fileExists(p) && canMountOver(p) &&
|
if fileExists(p) && canMountOver(p) &&
|
||||||
!strings.HasPrefix(p, "/dev/") && !strings.HasPrefix(p, "/proc/") && !boundPaths[p] {
|
!strings.HasPrefix(p, "/dev/") && !strings.HasPrefix(p, "/proc/") && !boundPaths[p] {
|
||||||
boundPaths[p] = true
|
boundPaths[p] = true
|
||||||
// Create intermediary dirs if needed
|
// Create intermediary dirs if needed.
|
||||||
for _, dir := range intermediaryDirs("/", p) {
|
// For files, only create dirs up to the parent to avoid
|
||||||
|
// creating a directory at the file's path.
|
||||||
|
dirTarget := p
|
||||||
|
if !isDirectory(p) {
|
||||||
|
dirTarget = filepath.Dir(p)
|
||||||
|
}
|
||||||
|
for _, dir := range intermediaryDirs("/", dirTarget) {
|
||||||
if !isSystemMountPoint(dir) {
|
if !isSystemMountPoint(dir) {
|
||||||
args = append(args, "--dir", dir)
|
args = append(args, "--dir", dir)
|
||||||
}
|
}
|
||||||
@@ -533,7 +539,11 @@ func buildDenyByDefaultMounts(cfg *config.Config, cwd string, debug bool) []stri
|
|||||||
if !ContainsGlobChars(normalized) && fileExists(normalized) && canMountOver(normalized) &&
|
if !ContainsGlobChars(normalized) && fileExists(normalized) && canMountOver(normalized) &&
|
||||||
!strings.HasPrefix(normalized, "/dev/") && !strings.HasPrefix(normalized, "/proc/") && !boundPaths[normalized] {
|
!strings.HasPrefix(normalized, "/dev/") && !strings.HasPrefix(normalized, "/proc/") && !boundPaths[normalized] {
|
||||||
boundPaths[normalized] = true
|
boundPaths[normalized] = true
|
||||||
for _, dir := range intermediaryDirs("/", normalized) {
|
dirTarget := normalized
|
||||||
|
if !isDirectory(normalized) {
|
||||||
|
dirTarget = filepath.Dir(normalized)
|
||||||
|
}
|
||||||
|
for _, dir := range intermediaryDirs("/", dirTarget) {
|
||||||
if !isSystemMountPoint(dir) {
|
if !isSystemMountPoint(dir) {
|
||||||
args = append(args, "--dir", dir)
|
args = append(args, "--dir", dir)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user