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

Doc: Rootless Podman networked via WireGuard Client #7816

Closed
bbros-dev opened this issue Sep 29, 2020 · 9 comments
Closed

Doc: Rootless Podman networked via WireGuard Client #7816

bbros-dev opened this issue Sep 29, 2020 · 9 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. stale-issue

Comments

@bbros-dev
Copy link

bbros-dev commented Sep 29, 2020

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind feature

Description

This arose in the course of preparing series on rootless Podman related documentation for Vultr.
The first part is How to Install and Use Podman on Ubuntu 20.04.

This is likely a documentation example/feature.

There are many blog posts showing how to connect a (rootful)Docker container to WireGuard via the WG client on the Docker host .

It is useful to direct rootless container traffic via the hosts WireGuard, without directing all the hosts traffic via WG.

The WireGuard home page addresses Docker containers (rootful).

However, that approach, i.e. --network=ns:/var/run/netns/container, does not work with podman rootless containers - or at least I couldn't get it to work, and at least one other person also could not.
For other's coming this way issue #4473 is related, and the document rootless.md
The result there is:

podman run --network=ns:/var/run/netns/gitea-drone -it --rm busybox sh
Error: container_linux.go:349: starting container process caused "process_linux.go:319: getting the final child's pid from pipe caused \"EOF\"": OCI runtime error

This partially works when the client has AllowedIP=0.0.0.0/0, i.e. works only when all host traffic is sent tvia WG:

wg-quick up wgclient.conf
podman run --network=slirp4netns:outbound_addr=wgclient -it --rm busybox sh

It does not seem possible to route only the container traffic via WG, e.g. when AllowedIP=10.0.0.0/10, etc.
If this is correct, it should be documented.
If it is possible the settings could be documented - given WG is now part of the kernel.

Steps to reproduce the issue:

  1. Set up WG server:
[Interface]
PrivateKey = ....
Address = 10.200.200.1/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o ens3 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o ens3 -j MASQUERADE; iptables -t nat -A POSTROUTING
-s 10.200.200.0/24 -o ens3 -j MASQUERADE; ping -c1 10.200.200.1
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o ens3 -j MASQUERADE; ip6tables-D FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o ens3 -j MASQUERADE; iptables -t nat -D POSTROUTING -s 10.200.200.0/24 -o ens3 -j MASQUERADE
SaveConfig = true

[Peer] # gitea
PublicKey = ....
AllowedIPs = 10.200.200.3/32
  1. Setup WG client
[Interface]
Address = 10.200.200.3/32
PrivateKey = .....

[Peer]
PublicKey = .....
Endpoint = <i.p.a.d>:51820
#AllowedIPs = 10.0.0.0/10
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 21

Describe the results you received:

Rootless podman can connect via WireGuard only if the client setting is AllowedIPs = 0.0.0.0/0, that is all internet traffic on the Podman host is directed via WG.

Describe the results you expected:

To be able to direct the only rootless Podman container traffic via WG.

Additional information you deem important (e.g. issue happens only occasionally):

Output of podman version:

$ podman version
Version:      2.1.0
API Version:  2.0.0
Go Version:   go1.15.2
Built:        Thu Jan  1 10:00:00 1970
OS/Arch:      linux/amd64

Output of podman info --debug:

NA

Package info (e.g. output of rpm -q podman or apt list podman):

$ apt list podman
Listing... Done
podman/unknown,now 2.1.0~1 amd64 [installed]

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide?

Yes, I have checked the troubleshooting guide.

Additional environment details (AWS, VirtualBox, physical, etc.):

Physical

@openshift-ci-robot openshift-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 29, 2020
@bbros-dev
Copy link
Author

bbros-dev commented Sep 29, 2020

Hmm, IIUC, this functionality is added by this commit f82abc7

$ podman network create foo
$ podman run -d --name web --hostname web --network foo nginx:alpine
$ podman run --rm --network foo alpine wget -O - http://web.dns.podman

So it may be possible to move the WG interface into the rootless podman generated netns? As opposed to creating a netns by hand as the WireGuard documents describes.
However, there is no indication whether the requirement, set out in this comment still applies.

Either way there does seem to be some documentation required:

Commit f82abc7 removes the rootless.md note on the lack of CNI support but I can't see where any documentation is added.

@mheon
Copy link
Member

mheon commented Sep 29, 2020 via email

@bbros-dev
Copy link
Author

bbros-dev commented Sep 29, 2020

you're seeing up the Wireguard network namespace as root and then trying to join it with rootless Podman?

Correct.

You could attempt to do the configuration of the new network namespace from within a 'podman unshare' shell but I suspect you will also run into permissions issues there.

Will try that.

@bbros-dev
Copy link
Author

bbros-dev commented Sep 30, 2020

@mheon, Correct there are permissions issues trying to create the network namespace with the rootless Podman user namespace:

$ podman unshare
# ip netns add gitea-drone
Cannot create namespace file "/var/run/netns/gitea-drone": Permission denied
# sudo ip netns add gitea-drone
sudo: error in /etc/sudo.conf, line 0 while loading plugin "sudoers_policy"
sudo: /usr/lib/sudo/sudoers.so must be owned by uid 0
sudo: fatal error, unable to load plugins

Would also be useful to document what the sudo setup might need to look like?

@rhatdan
Copy link
Member

rhatdan commented Oct 1, 2020

The issue here is the permissions on /var/run/netns/gitea-drone It has to be accessible Perhaps read/write by the user that is logged in. If the socket is owned by root:root with permissions like 0600, then the rootless user can not use it. Whether they are in a user namespace or not. When you do podman unshare, you are still your user, you don't gain access to anything extra on the system. You do gain access to the UIDs and GIDs listed in /etc/subuid, that is about it.

@bbros-dev
Copy link
Author

The issue here is the permissions on /var/run/netns/gitea-drone It has to be accessible Perhaps read/write by the user that is logged in.

Hmm, interesting. Tried chown and chmod and always get Operation not permitted.
Something more funky - need to dig in when have the time. Right now running rootful with --user.

@github-actions
Copy link

github-actions bot commented Nov 1, 2020

A friendly reminder that this issue had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Nov 3, 2020

I am going to close, since I don't believe this is a podman issue.

@SuitespaceDev
Copy link

Though this is closed; I'll note that someone has managed to run rootless using a namespace from a pod created with --network=none to get around permission issues in subsequent pods

https://github.com/jcarrano/wg-podman

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 15, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. stale-issue
Projects
None yet
Development

No branches or pull requests

5 participants