diff options
author | Paul Holzinger <pholzing@redhat.com> | 2021-09-14 11:13:28 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2021-09-14 11:13:28 +0200 |
commit | d3f0f09ad94af1d67b4f7baa83036dc851edee18 (patch) | |
tree | 9006dc1d567b7554371c2a79f3717add22e0c2b4 /libpod/oci_util.go | |
parent | 6221f269a8936876034a342010b89bc71f8bbe95 (diff) | |
download | podman-d3f0f09ad94af1d67b4f7baa83036dc851edee18.tar.gz podman-d3f0f09ad94af1d67b4f7baa83036dc851edee18.tar.bz2 podman-d3f0f09ad94af1d67b4f7baa83036dc851edee18.zip |
libpod: rootful close binded ports
For rootful users ports are forwarded via iptables. To make sure no
other process tries to use them, libpod will bind the ports and pass the
fds to conmon. There seems to be race when a container is restarted
because libpod tries to bind the port before the conmon process exited.
The problem only hapens with the podman service because it keeps the
connection open. Once we have the fd and passed it to conmon the
podman service should close the connection.
To verify run `sudo ss -tulpn` and check that only the conmon process
keeps the port open. Previously you would also see the podman server
process listed.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod/oci_util.go')
-rw-r--r-- | libpod/oci_util.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libpod/oci_util.go b/libpod/oci_util.go index 1cafd5863..f2843b09b 100644 --- a/libpod/oci_util.go +++ b/libpod/oci_util.go @@ -68,6 +68,12 @@ func bindPorts(ports []ocicni.PortMapping) ([]*os.File, error) { return nil, errors.Wrapf(err, "cannot get file for UDP socket") } files = append(files, f) + // close the listener + // note that this does not affect the fd, see the godoc for server.File() + err = server.Close() + if err != nil { + logrus.Warnf("failed to close connection: %v", err) + } case "tcp": var ( @@ -96,6 +102,13 @@ func bindPorts(ports []ocicni.PortMapping) ([]*os.File, error) { return nil, errors.Wrapf(err, "cannot get file for TCP socket") } files = append(files, f) + // close the listener + // note that this does not affect the fd, see the godoc for server.File() + err = server.Close() + if err != nil { + logrus.Warnf("failed to close connection: %v", err) + } + case "sctp": if !notifySCTP { notifySCTP = true |