-
Notifications
You must be signed in to change notification settings - Fork 99
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
Let pasta configure interface, fix IPv6 outbound connectivity #458
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 |
---|---|---|
|
@@ -17,7 +17,6 @@ import ( | |
"github.com/rootless-containers/rootlesskit/v2/pkg/messages" | ||
"github.com/rootless-containers/rootlesskit/v2/pkg/network" | ||
"github.com/rootless-containers/rootlesskit/v2/pkg/network/iputils" | ||
"github.com/rootless-containers/rootlesskit/v2/pkg/network/parentutils" | ||
) | ||
|
||
// NewParentDriver instantiates new parent driver. | ||
|
@@ -92,9 +91,6 @@ func (d *parentDriver) MTU() int { | |
func (d *parentDriver) ConfigureNetwork(childPID int, stateDir, detachedNetNSPath string) (*messages.ParentInitNetworkDriverCompleted, func() error, error) { | ||
tap := d.ifname | ||
var cleanups []func() error | ||
if err := parentutils.PrepareTap(childPID, detachedNetNSPath, tap); err != nil { | ||
return nil, common.Seq(cleanups), fmt.Errorf("setting up tap %s: %w", tap, err) | ||
} | ||
|
||
address, err := iputils.AddIPInt(d.ipnet.IP, 100) | ||
if err != nil { | ||
|
@@ -111,12 +107,10 @@ func (d *parentDriver) ConfigureNetwork(childPID int, stateDir, detachedNetNSPat | |
} | ||
|
||
opts := []string{ | ||
"--foreground", | ||
"--stderr", | ||
"--ns-ifname=" + d.ifname, | ||
"--mtu=" + strconv.Itoa(d.mtu), | ||
"--no-dhcp", | ||
"--no-ra", | ||
"--config-net", | ||
"--address=" + address.String(), | ||
"--netmask=" + strconv.Itoa(netmask), | ||
"--gateway=" + gateway.String(), | ||
|
@@ -147,21 +141,18 @@ func (d *parentDriver) ConfigureNetwork(childPID int, stateDir, detachedNetNSPat | |
// `Couldn't open user namespace /proc/51813/ns/user: Permission denied` | ||
// Possibly related to AppArmor. | ||
cmd := exec.Command(d.binary, opts...) | ||
cmd.Stdout = d.logWriter | ||
cmd.Stderr = d.logWriter | ||
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. Where is the stderr now ? 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. It's all in 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. |
||
cleanups = append(cleanups, func() error { | ||
logrus.Debugf("killing pasta") | ||
if cmd.Process != nil { | ||
_ = cmd.Process.Kill() | ||
} | ||
wErr := cmd.Wait() | ||
logrus.Debugf("killed pasta: %v", wErr) | ||
return nil | ||
}) | ||
logrus.Debugf("Executing %v", cmd.Args) | ||
if err := cmd.Start(); err != nil { | ||
out, err := cmd.CombinedOutput() | ||
if err != nil { | ||
exitErr := &exec.ExitError{} | ||
if errors.As(err, &exitErr) { | ||
return nil, common.Seq(cleanups), | ||
fmt.Errorf("pasta failed with exit code %d:\n%s", | ||
exitErr.ExitCode(), string(out)) | ||
} | ||
return nil, common.Seq(cleanups), fmt.Errorf("executing %v: %w", cmd, err) | ||
} | ||
|
||
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. What will happen if the background pasta process dies after several minutes/hours/days? 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. It can't, but if it happens (even though we haven't received this kind of "stability" bug reports for quite a long time now), we would like users to report an issue, because anyway context will be lost (TCP connections, at least), rather than hide this by restarting the process or similar. 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. The pasta process can be killed by the kernel mostly due to OOM, and in that case RootlessKit should probably abort, or at least print an error message. 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. It's pretty much impossible because it doesn't allocate memory dynamically, so I don't think it can actually be picked as a candidate by the OOM killer. Anyway, the network interface will go away in that case, because we close the tap file descriptor, so something like that could actually be added. I don't think it's actually needed, because the network interface going away is very obvious, but I guess I can implement it if needed (that will take a bit longer though). 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. @AkihiroSuda I'm trying to implement this with the That part looks trivial, but I don't know where to add this kind of monitor in rootlesskit. I thought there was something like that for slirp4netns' 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. Looks like we lack the death detection for slirp4netns too 😅 Maybe we can use pidfd for kernel >= 5.3.
If we want to implement this too for old kernel, probably just watch SIGCHLD and see if the PID of 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 feel better now. 😄 I think we should leave out PID tracking, because it keeps the interface to pasta very simple (also in terms of AppArmor and SELinux), and we have a valid, solid alternative (netlink monitor on the network interface). Anyway, this is the simple part. The complicated part for me, whatever we choose as monitor, is where and how to add this to rootlesskit. I really don't know how it works with... threads? Should we spawn a thread somewhere? Is there something like that already in rootlesskit? 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. We don't seem to have any monitoring stuff in the current code base, but it can be probably spawned as a goroutine 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. Thanks for the tip, I'll give it a try, but with very low priority, so it might take a while. |
||
netmsg := messages.ParentInitNetworkDriverCompleted{ | ||
Dev: tap, | ||
MTU: d.mtu, | ||
|
@@ -191,6 +182,12 @@ func NewChildDriver() network.ChildDriver { | |
type childDriver struct { | ||
} | ||
|
||
func (d *childDriver) ChildDriverInfo() (*network.ChildDriverInfo, error) { | ||
return &network.ChildDriverInfo { | ||
ConfiguresInterface: true, | ||
}, nil | ||
} | ||
|
||
func (d *childDriver) ConfigureNetworkChild(netmsg *messages.ParentInitNetworkDriverCompleted, detachedNetNSPath string) (string, error) { | ||
// NOP | ||
return netmsg.Dev, nil | ||
|
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.
?
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.
See commit message:
That was deprecated in passt's commit bca0fefa32e0 ("conf, passt: Make --stderr do nothing, and deprecate it"), included in upstream version
2024_06_24.1ee2eca
. We can leave it for backwards compatibility, but in general we were already printing most stuff on stderr when running with--foreground
anyway.