diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2022-09-12 22:24:07 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-09-13 05:31:51 +0200 |
commit | eed17a47fe8291d449fd505d9a6b1f4a72be8d09 (patch) | |
tree | b88d226da816c7059f704b00206fad0788898112 /passt.h | |
parent | d9f889a55a8bf4dc2e0caf61f35bc15dd6a68e06 (diff) | |
download | passt-eed17a47fe8291d449fd505d9a6b1f4a72be8d09.tar passt-eed17a47fe8291d449fd505d9a6b1f4a72be8d09.tar.gz passt-eed17a47fe8291d449fd505d9a6b1f4a72be8d09.tar.bz2 passt-eed17a47fe8291d449fd505d9a6b1f4a72be8d09.tar.lz passt-eed17a47fe8291d449fd505d9a6b1f4a72be8d09.tar.xz passt-eed17a47fe8291d449fd505d9a6b1f4a72be8d09.tar.zst passt-eed17a47fe8291d449fd505d9a6b1f4a72be8d09.zip |
Handle userns isolation and dropping root at the same time
passt/pasta can interact with user namespaces in a number of ways:
1) With --netns-only we'll remain in our original user namespace
2) With --userns or a PID option to pasta we'll join either the given
user namespace or that of the PID
3) When pasta spawns a shell or command we'll start a new user namespace
for the command and then join it
4) With passt we'll create a new user namespace when we sandbox()
ourself
However (3) and (4) turn out to have essentially the same effect. In both
cases we create one new user namespace. The spawned command starts there,
and passt/pasta itself will live there from sandbox() onwards.
Because of this, we can simplify user namespace handling by moving the
userns handling earlier, to the same point we drop root in the original
namespace. Extend the drop_user() function to isolate_user() which does
both.
After switching UID and GID in the original userns, isolate_user() will
either join or create the userns we require. When we spawn a command with
pasta_start_ns()/pasta_setup_ns() we no longer need to create a userns,
because we're already made one. sandbox() likewise no longer needs to
create (or join) an userns because we're already in the one we need.
We no longer need c->pasta_userns_fd, since the fd is only used locally
in isolate_user(). Likewise we can replace c->netns_only with a local
in conf(), since it's not used outside there.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'passt.h')
-rw-r--r-- | passt.h | 4 |
1 files changed, 0 insertions, 4 deletions
@@ -145,8 +145,6 @@ struct ip6_ctx { * @pcap: Path for packet capture file * @pid_file: Path to PID file, empty string if not configured * @pasta_netns_fd: File descriptor for network namespace in pasta mode - * @pasta_userns_fd: Descriptor for user namespace to join, -1 once joined - * @netns_only: In pasta mode, don't join or create a user namespace * @no_netns_quit: In pasta mode, don't exit if fs-bound namespace is gone * @netns_base: Base name for fs-bound namespace, if any, in pasta mode * @netns_dir: Directory of fs-bound namespace, if any, in pasta mode @@ -197,8 +195,6 @@ struct ctx { char pid_file[PATH_MAX]; int pasta_netns_fd; - int pasta_userns_fd; - int netns_only; int no_netns_quit; char netns_base[PATH_MAX]; |