-
Notifications
You must be signed in to change notification settings - Fork 21
fix failure to start container with networking enabled #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -187,8 +187,11 @@ func addResolvConf(ctx context.Context, b *bundle.Bundle, fallbackToHostRC bool) | |||||||||||||||||||||
| _, _ = rcBuf.WriteRune('\n') | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| rcBytes = rcBuf.Bytes() | ||||||||||||||||||||||
| } else if fallbackToHostRC { | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| // Try giving the VM a copy of the host's resolv.conf. | ||||||||||||||||||||||
| // This is always attempted (not only as a fallback) because on some | ||||||||||||||||||||||
| // platforms (e.g., macOS) the host path /etc/resolv.conf may contain | ||||||||||||||||||||||
| // symlinks that prevent it from being shared via virtiofs. | ||||||||||||||||||||||
|
Comment on lines
+190
to
+194
|
||||||||||||||||||||||
| } else { | |
| // Try giving the VM a copy of the host's resolv.conf. | |
| // This is always attempted (not only as a fallback) because on some | |
| // platforms (e.g., macOS) the host path /etc/resolv.conf may contain | |
| // symlinks that prevent it from being shared via virtiofs. | |
| } else if fallbackToHostRC { | |
| // Try giving the VM a copy of the host's resolv.conf when enabled. | |
| // Copying the file contents (rather than sharing the host path) avoids | |
| // issues on platforms where /etc/resolv.conf may be a symlink that | |
| // cannot be shared via virtiofs. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,16 +230,24 @@ func (bm *bindMounter) FromBundle(ctx context.Context, b *bundle.Bundle) error { | |
| tag := fmt.Sprintf("bind-%x", hash[:8]) | ||
| vmTarget := "/mnt/" + tag | ||
|
|
||
| // Resolve symlinks in the source path because libkrun opens shared | ||
| // directories with O_NOFOLLOW, which rejects symlinks | ||
| // (e.g., /etc -> /private/etc and /etc/resolv.conf -> ../var/run/resolv.conf on macOS). | ||
| resolvedSource, err := filepath.EvalSymlinks(m.Source) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm always wary of blindly following symlinks due to the security risks they pose. I think nerdbox users should evaluate any symlinks if and when that makes sense instead. |
||
| if err != nil { | ||
| return fmt.Errorf("failed to resolve symlinks for bind mount source %s: %w", m.Source, err) | ||
| } | ||
|
Comment on lines
+233
to
+239
|
||
|
|
||
| // For files, share the parent directory via virtiofs since virtiofs | ||
| // operates on directories. The spec source points to the file within | ||
| // the mounted directory. | ||
| hostSrc := m.Source | ||
| hostSrc := resolvedSource | ||
| specSrc := vmTarget | ||
| if !fi.IsDir() { | ||
| hostSrc = filepath.Dir(m.Source) | ||
| hostSrc = filepath.Dir(resolvedSource) | ||
| // Use path.Join (not filepath.Join) because this path is used | ||
| // inside the Linux VM where forward slashes are required. | ||
| specSrc = path.Join(vmTarget, filepath.Base(m.Source)) | ||
| specSrc = path.Join(vmTarget, filepath.Base(resolvedSource)) | ||
| } | ||
|
Comment on lines
+244
to
251
|
||
|
|
||
| transformed := bindMount{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC all that code was added before nerdbox had proper support for bind-mounts.
I think the shim should be minimal and have less magic, i.e. we should remove this function and the
io.containerd.nerdbox.ctr.dnsannotation, and let higher-level runtimes inject their custom resolv.conf through standard bind-mounts.