Skip to content
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

Allow creation of a rootless netns backed by Pasta #1846

Merged

Conversation

mheon
Copy link
Member

@mheon mheon commented Feb 6, 2024

This makes the code for setting up rootless network namespaces dependent on what the default rootless network provider is, and allows Pasta to be used for traffic forwarding on the rootless netns.

@openshift-ci openshift-ci bot added the approved label Feb 6, 2024
@mheon mheon force-pushed the allow_rootless_netns_pasta branch 3 times, most recently from e06bf83 to a202476 Compare February 6, 2024 20:46
// rootlessNetNsSilrp4netnsPidFile is the name of the rootless netns slirp4netns pid file
rootlessNetNsSilrp4netnsPidFile = "rootless-netns-slirp4netns.pid"
// rootlessNetNsConnPidFile is the name of the rootless netns slirp4netns/pasta pid file
rootlessNetNsConnPidFile = "rootless-netns-slirp4netns.pid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well rename the file, this code was only add during 5.0-dev so it is fine to break this here

@@ -113,7 +114,14 @@ func (n *Netns) getOrCreateNetns() (ns.NetNS, bool, error) {
if err != nil {
return nil, false, wrapError("create netns", err)
}
err = n.setupSlirp4netns(nsPath)
switch strings.ToLower(n.config.Network.DefaultRootlessNetworkCmd) {
case "slirp4netns":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use constant, slirp4netns.BinaryName
also match "" as well because we allow this in podman,buildah atm

switch strings.ToLower(n.config.Network.DefaultRootlessNetworkCmd) {
case "slirp4netns":
err = n.setupSlirp4netns(nsPath)
case "pasta":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use pasta.BinaryName

multiErr = multierror.Append(multiErr, wrapError("kill slirp4netns", err))
// Pasta does not require teardown, it will tear itself down so long as
// we get rid of the netns.
if n.config.Network.DefaultRootlessNetworkCmd == "slirp4netns" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the constant here as well

pastaOpts := pasta.SetupOptions{
Config: n.config,
Netns: nsPath,
ExtraOptions: []string{"-p", rootlessNetNsConnPidFile},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this create the file in the cwd? It must be wrapped in n.getPath() to get a proper absolute path.


if systemd.RunsOnSystemd() {
// Treat these as fatal - if pasta failed to write a PID file something is probably wrong.
pidfile, err := os.ReadFile(rootlessNetNsConnPidFile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@rhatdan rhatdan added the 5.0 label Feb 7, 2024
@mheon mheon force-pushed the allow_rootless_netns_pasta branch from a202476 to 3a37c0b Compare February 7, 2024 18:14
@mheon
Copy link
Member Author

mheon commented Feb 7, 2024

Comments addressed

@@ -113,7 +114,14 @@ func (n *Netns) getOrCreateNetns() (ns.NetNS, bool, error) {
if err != nil {
return nil, false, wrapError("create netns", err)
}
err = n.setupSlirp4netns(nsPath)
switch strings.ToLower(n.config.Network.DefaultRootlessNetworkCmd) {
case "", slirp4netns.BinaryName:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be switched to default to pasta?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters, it should always be explicitly set in containers.conf

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some distributions do not ship a containers.conf, or was the default modified in common/pkg/config/default.go?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like not yet.

		DefaultRootlessNetworkCmd: "slirp4netns",

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging this needs to be vendored into podman and tested there, I guess you can either switch the default directly in this PR to test or write a containers.conf in podman CI.
Either way I expect failing tests in podman as some likely depend on certain slirp behaviours.

pastaOpts := pasta.SetupOptions{
Config: n.config,
Netns: nsPath,
ExtraOptions: []string{"-p", pidPath},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-p is actually not the pid file, -P is, but I recommend to use --pid

}
pid, err := strconv.Atoi(string(pidfile))
if err != nil {
return fmt.Errorf("unable to decode pasta PID (got %q): %w", string(pidfile), err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to include the pidfile data in the error as the Atoi error already includes this so you would stutter the error.

@mheon mheon force-pushed the allow_rootless_netns_pasta branch 7 times, most recently from af15ea1 to a9fe405 Compare February 9, 2024 14:59
@rhatdan
Copy link
Member

rhatdan commented Feb 9, 2024

LGTM
@Luap99 PTAL
@mheon has the tests passed for Podman?

@mheon
Copy link
Member Author

mheon commented Feb 9, 2024

Tests are here: containers/podman#21563

Mostly passing now (minor issue in APIv2) but the system tests are timing out. Potentially could be Pasta being slower to start than slirp4netns?

@Luap99
Copy link
Member

Luap99 commented Feb 9, 2024

If you change the default here in the same commit then this needs docs changes as well for it.

Anyhow I would think we can merge this without making pasta default here in this PR. And figure out the remaining test problems next week as the timeouts are very concerning. If pasta is actually so much slower than I am not sure if we want to continue to make it the default given it adds at least 10 mins to the system tests.

@mheon mheon force-pushed the allow_rootless_netns_pasta branch 9 times, most recently from e9c35ad to 1a6727c Compare February 14, 2024 19:28
@mheon mheon force-pushed the allow_rootless_netns_pasta branch from 1a6727c to dd99f6c Compare February 15, 2024 13:35
@sbrivio-rh
Copy link

Potentially could be Pasta being slower to start than slirp4netns?

$ time for i in `seq 1 100`; do podman run --net=pasta --rm -it alpine true; done
real	0m15.358s
user	0m4.360s
sys	0m2.823s
$ time for i in `seq 1 100`; do podman run --net=slirp4netns --rm -it alpine true; done
real	0m14.399s
user	0m4.285s
sys	0m1.640s

I'd call that "the same". Is there any particular configuration or sequence I should look into?

@Luap99
Copy link
Member

Luap99 commented Feb 16, 2024

Potentially could be Pasta being slower to start than slirp4netns?

$ time for i in `seq 1 100`; do podman run --net=pasta --rm -it alpine true; done
real	0m15.358s
user	0m4.360s
sys	0m2.823s
$ time for i in `seq 1 100`; do podman run --net=slirp4netns --rm -it alpine true; done
real	0m14.399s
user	0m4.285s
sys	0m1.640s

I'd call that "the same". Is there any particular configuration or sequence I should look into?

No looks good to me as well. I wouldn't worry about that, the problem in podman PR clearly shows the problem is leaking pasta processes not speed.

@sbrivio-rh
Copy link

No looks good to me as well. I wouldn't worry about that, the problem in podman PR clearly shows the problem is leaking pasta processes not speed.

Okay, let me prepare a release with the fix then. We don't know if it fixes that issue or not, but I think it's a critical fix anyway, as the inotify watch setup can semi-silently fail.

@mheon mheon force-pushed the allow_rootless_netns_pasta branch from 4965bb8 to 328022e Compare February 21, 2024 13:18
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just so it is not forgotten, you have to update the docs if you change the default (i.e. see #1854)

@mheon
Copy link
Member Author

mheon commented Feb 22, 2024

Ack, will do

@mheon mheon force-pushed the allow_rootless_netns_pasta branch 2 times, most recently from 45f4aee to dd24d75 Compare February 26, 2024 14:30
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One final, nit. Rest looks good here and podman tests seem to be happy as well.

One last ask would be to make sure this vendors into buildah as well without breaking tests there. Might need to users newer VM images there first (not sure if they got updated for the latest pasta)

Comment on lines 143 to 144
if err := n.cleanupRootlessNetns(); err != nil {
multiErr = multierror.Append(multiErr, wrapError("kill slirp4netns", err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the wrapError message needs to change as well, maybe to kill networking process?

This makes the code for setting up rootless network namespaces
dependent on what the default rootless network provider is, and
allows Pasta to be used for traffic forwarding on the rootless
netns.

This also switches the default rootless network provider to Pasta

Signed-off-by: Matt Heon <mheon@redhat.com>
@mheon mheon force-pushed the allow_rootless_netns_pasta branch from dd24d75 to fdf91cd Compare February 27, 2024 13:17
@mheon
Copy link
Member Author

mheon commented Feb 27, 2024

Fixed & force-pushed. Let's get this landed.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

/hold
Please do not merge this yet, c/common seems to be blocked in podman (containers/podman#21828), lets not add more changes on top of that require large changes in podman. Once the latest common is merged in podman we can merged this and do another vendor with all your test fixes in the PR.
Also please do a buildah test run I suspect you may need some test changes there as well.

@mheon
Copy link
Member Author

mheon commented Feb 27, 2024

Buildah run is a good call, will do that now.

@mheon
Copy link
Member Author

mheon commented Feb 27, 2024

containers/buildah#5359 for Buildah

@mheon
Copy link
Member Author

mheon commented Feb 28, 2024

@Luap99 I think we decided we can merge this as-is now, yes?

@Luap99
Copy link
Member

Luap99 commented Feb 28, 2024

If we vendor the latest c/common already in podman then yes, however looks like there are failing test in containers/podman#21774 which sounds like c/storage regressions to me but haven't really looked closely. I can do so tomorrow morning.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

/lgtm
/hold
containers/podman#21774 is about to merge,
remove the hold when you are ready to rebase your podman PR against c/common@main

Copy link
Contributor

openshift-ci bot commented Feb 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, mheon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mheon
Copy link
Member Author

mheon commented Feb 29, 2024

/hold cancel

@openshift-merge-bot openshift-merge-bot bot merged commit 2c4ea34 into containers:main Feb 29, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants