Skip to content

syscall,net: tests fail within a Podman container #58114

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

Closed
userid0x0 opened this issue Jan 27, 2023 · 8 comments
Closed

syscall,net: tests fail within a Podman container #58114

userid0x0 opened this issue Jan 27, 2023 · 8 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Testing An issue that has been verified to require only test changes, not just a test failure.
Milestone

Comments

@userid0x0
Copy link

What version of Go are you using (go version)?

I want to compile the latest version within podman. Debian bullseye is shipped with go 1.15 .

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.15"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.15/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/golang/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build928199845=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I tried to build Go within a Podman Container

apt install podman
cat << EOF > Dockerfile
FROM debian:bullseye-slim

ARG DEBIAN_FRONTEND=noninteractive

# see also https://podman.io/getting-started/installation#building-missing-dependencies
RUN apt update \
  && apt install -y \
    btrfs-progs \
    crun \
    git \
    golang-go \
    go-md2man \
    iptables \
    libassuan-dev \
    libbtrfs-dev \
    libc6-dev \
    libdevmapper-dev \
    libglib2.0-dev \
    libgpgme-dev \
    libgpg-error-dev \
    libprotobuf-dev \
    libprotobuf-c-dev \
    libseccomp-dev \
    libselinux1-dev \
    libsystemd-dev \
    make \
    pkg-config \
    uidmap \
  && rm -rf /var/lib/{apt,dpkg,cache,log}/

run git clone --branch go1.19.5 https://github.com/golang/go.git ~/golang
EOF
podman build --tag testme .
podman run --rm --tty --interactive testme bash -c "cd ~/golang/src; ./all.bash"

The following tests fail:

--- FAIL: TestIPConnLocalName (0.00s)
    iprawsock_test.go:98: listen ip4:icmp 127.0.0.1: socket: operation not permitted
--- FAIL: TestIPConnRemoteName (0.00s)
    iprawsock_test.go:115: dial ip:tcp 127.0.0.1->127.0.0.1: socket: operation not permitted
--- FAIL: TestIPConnSpecificMethods (0.00s)
    protoconn_test.go:174: listen ip4:icmp 127.0.0.1: socket: operation not permitted
FAIL
FAIL    net
...
--- FAIL: TestUnshareMountNameSpace (0.00s)
    exec_linux_test.go:343: unshare failed: , fork/exec /tmp/go-build1623837725/b1558/syscall.test: operation not permitted
--- FAIL: TestUnshareMountNameSpaceChroot (2.80s)
    exec_linux_test.go:394: unshare failed: , fork/exec /syscall.test: operation not permitted
--- FAIL: TestAmbientCaps (0.00s)
    exec_linux_test.go:632: fork/exec /tmp/gotest1670826556: errno 0
FAIL
FAIL    syscall

What did you expect to see?

I expect that Go detects it's running within a (podman) container and the tests succeed. Such a test might look as follows:

func isPodman() bool {
	return os.Getenv("container") == "podman"
}

Adding it to exec_linux_test.go should be straight forward:
https://github.com/golang/go/blob/master/src/syscall/exec_linux_test.go#L38
. For the other tests i am using --cap-add NET_RAW for the moment.

What did you see instead?

@bcmills
Copy link
Contributor

bcmills commented Jan 27, 2023

syscall in particular should pass once CL 456375 is merged — could you try running it with that change patched in?

I would suggest filing separate issues for each of the three packages, since the fixes are presumably independent.

@bcmills bcmills added Testing An issue that has been verified to require only test changes, not just a test failure. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 27, 2023
@bcmills bcmills added this to the Backlog milestone Jan 27, 2023
@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 27, 2023
@bcmills bcmills changed the title syscall/exec_linux_test net/iprawsock_test net/protoconn_test: fail within a Podman container syscall,net: tests fail within a Podman container Jan 27, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 27, 2023
@bcmills
Copy link
Contributor

bcmills commented Jan 27, 2023

The net failure is probably from here:
https://cs.opensource.google/go/go/+/master:src/net/platform_test.go;l=45-47;drc=627f12868c4c3e714bbb4ce4a418f918c1935dc2

The test is assuming that UID 0 implies “able to open raw IP sockets”, but that assumption does not hold in a container environment.

@bcmills bcmills added help wanted and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jan 27, 2023
@bcmills
Copy link
Contributor

bcmills commented Jan 27, 2023

@userid0x0, want to send a CL to fix the net tests?
https://go.dev/doc/contribute

(CC @ianlancetaylor @neild)

@userid0x0
Copy link
Author

userid0x0 commented Jan 30, 2023

@bcmills I am neither a Go nor capabilities expert - I tried to setup a build job to build the latest version of podman (within a podman container). Does it make sense to check the capabilities of the current process instead of checking for UID==0?
I saw there is a capabilities module for Go.

@bcmills
Copy link
Contributor

bcmills commented Jan 30, 2023

Does it make sense to check the capabilities of the current process instead of checking for UID==0?

Probably not: the POSIX extension specifying cap_get_proc was withdrawn, and cap_get_pid is a Linux-specific extension.

In general, the more robust approach is to just go ahead and make the system calls and then check the return values for error codes that look like container permission errors (EPERM, ENOSYS, ENOTSUPP, EOPNOTSUPP, perhaps EINVAL).

@userid0x0
Copy link
Author

userid0x0 commented Feb 1, 2023

syscall in particular should pass once CL 456375 is merged — could you try running it with that change patched in?

I would suggest filing separate issues for each of the three packages, since the fixes are presumably independent.

I tested against 23c0121e4eb259cc1087d0f79a0803cbc71f500b (HEAD 31st January 2023) and can confirm the issues related to exec_linux_test.go are solved.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/476216 mentions this issue: internal/testenv, syscall: move isNotSupported to internal/testenv

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/476217 mentions this issue: net: skip tests if creating a socket is disallowed

gopherbot pushed a commit that referenced this issue Mar 15, 2023
This allows to use this helper function in packages other than syscall,
namely package net.

For #58114

Change-Id: I72c59ab013e9195801ff1315019ae1aef4396287
Reviewed-on: https://go-review.googlesource.com/c/go/+/476216
Auto-Submit: Tobias Klauser <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Tobias Klauser <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
@github-project-automation github-project-automation bot moved this from Todo to Done in Go Compiler / Runtime Mar 15, 2023
@tklauser tklauser self-assigned this Mar 21, 2023
@golang golang locked and limited conversation to collaborators Mar 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Testing An issue that has been verified to require only test changes, not just a test failure.
Projects
None yet
Development

No branches or pull requests

4 participants