Skip to content

Commit 7f583ea

Browse files
committed
fix failure to start container with networking enabled
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent b7fc692 commit 7f583ea

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

internal/shim/task/ctrnetworking.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,11 @@ func addResolvConf(ctx context.Context, b *bundle.Bundle, fallbackToHostRC bool)
187187
_, _ = rcBuf.WriteRune('\n')
188188
}
189189
rcBytes = rcBuf.Bytes()
190-
} else if fallbackToHostRC {
190+
} else {
191191
// Try giving the VM a copy of the host's resolv.conf.
192+
// This is always attempted (not only as a fallback) because on some
193+
// platforms (e.g., macOS) the host path /etc/resolv.conf may contain
194+
// symlinks that prevent it from being shared via virtiofs.
192195
if c, err := os.ReadFile("/etc/resolv.conf"); err == nil {
193196
rcBytes = c
194197
}

internal/shim/task/mount.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,24 @@ func (bm *bindMounter) FromBundle(ctx context.Context, b *bundle.Bundle) error {
230230
tag := fmt.Sprintf("bind-%x", hash[:8])
231231
vmTarget := "/mnt/" + tag
232232

233+
// Resolve symlinks in the source path because libkrun opens shared
234+
// directories with O_NOFOLLOW, which rejects symlinks
235+
// (e.g., /etc -> /private/etc and /etc/resolv.conf -> ../var/run/resolv.conf on macOS).
236+
resolvedSource, err := filepath.EvalSymlinks(m.Source)
237+
if err != nil {
238+
return fmt.Errorf("failed to resolve symlinks for bind mount source %s: %w", m.Source, err)
239+
}
240+
233241
// For files, share the parent directory via virtiofs since virtiofs
234242
// operates on directories. The spec source points to the file within
235243
// the mounted directory.
236-
hostSrc := m.Source
244+
hostSrc := resolvedSource
237245
specSrc := vmTarget
238246
if !fi.IsDir() {
239-
hostSrc = filepath.Dir(m.Source)
247+
hostSrc = filepath.Dir(resolvedSource)
240248
// Use path.Join (not filepath.Join) because this path is used
241249
// inside the Linux VM where forward slashes are required.
242-
specSrc = path.Join(vmTarget, filepath.Base(m.Source))
250+
specSrc = path.Join(vmTarget, filepath.Base(resolvedSource))
243251
}
244252

245253
transformed := bindMount{

0 commit comments

Comments
 (0)