network: distinguish nested root from rootless user#932
Conversation
f6306a4 to
297e73d
Compare
Luap99
left a comment
There was a problem hiding this comment.
This also does not fix anything for podman-container-tools/podman#18783
| } | ||
|
|
||
| // HasCapNetAdmin returns whether the current process has CAP_NET_ADMIN. | ||
| func HasCapNetAdmin() (bool, error) { |
There was a problem hiding this comment.
we do not need this, if there is just a single user it should not be put here where we have to commit stable APIs more or less.
But as I said on the Podman PR I do not think it is worth it.
| if unshare.IsRootless() { | ||
| // Use the original caller UID here: UID 0 in a nested user namespace | ||
| // should still use rootful network paths. | ||
| if unshare.GetRootlessUID() > 0 { |
There was a problem hiding this comment.
While I would agree with this change based on recent config file rework doing this now is to late as this is a breaking change for anyone who already uses podman in such a env, using the per user directories in a userns is not really a problem overall.
297e73d to
ffb737a
Compare
|
Thanks, I updated this to narrow the behavior change. The PR no longer adds The network path selection also no longer treats UID 0 in a user namespace as rootful unconditionally. It preserves the existing rootless path layout unless all of these are true:
If I also updated the netavark mode decision itself. So the intended behavior is:
I agree this should not be a broad rootless-directory migration. The updated version only switches networking behavior when the environment has the capability required to manage rootful netavark bridge state. Could you please take another look? |
Signed-off-by: Yuxiang Zhu <vfreex@gmail.com>
ffb737a to
06a4c4c
Compare
Luap99
left a comment
There was a problem hiding this comment.
If we are re-execed in a user namesapce we have new caps which always have NET_ADMIN there, we cannot just say we have the cap and not use the rootless logic as we no longer own the parent namesapaces.
once we are in the userns we always have to use the rootless logic.
There is really no way to recover this AFAICT. If we are root with SYS_ADMIN but no NET_ADMIN then we cannot even use the rootlessnetns logic as we would need to trigger the rexec logic first but this is all way to far at this point and not possible.
So overall I do not see how this cap check gets us anywhere to fix the LXC issues, either a user has both caps already or they don't and we use rexec, just SYS_ADMIN without NET_ADMIN looks unsupportable so I rather not deal with these speical cases
The users in podman-container-tools/podman#18783 ponly talk about the aardvark-dns problem which is the systemd user session problem and unrelated to having caps so this will not bring us one thing closer to fixing this either. Hence I think we should just close this
Dependency support for the main Podman fix: podman-container-tools/podman#28995
Bug report: podman-container-tools/podman#18783
Summary
Network config/runtime path selection should distinguish a real rootless user from UID 0 running inside a nested user namespace. UID 0 in a delegated container environment should continue to use rootful network paths.
This also adds
unshare.HasCapNetAdmin(), matching the existing cachedHasCapSysAdmin()helper, so callers can check effectiveCAP_NET_ADMINwithout duplicating capability-loading code.Rationale
Podman's rootful bridge-networking preflight needs to check
CAP_NET_ADMINseparately fromCAP_SYS_ADMIN. Once this is merged and vendored, the Podman PR can replace its temporary local helper withunshare.HasCapNetAdmin().For network path selection, the relevant question is whether the original caller was a non-root user. The network path decision now uses
unshare.GetRootlessUID() > 0directly so UID 0 keeps rootful paths, including UID 0 inside a nested user namespace.Tests
GOOS=linux go test -c -o /private/tmp/container-libs-common-network.test ./libnetwork/networkfromcommon/GOOS=linux go test -c -o /private/tmp/container-libs-storage-unshare.test ./pkg/unsharefromstorage/