Skip to content

Fix runc run "permission denied" when rootless#3753

Merged
AkihiroSuda merged 3 commits intoopencontainers:mainfrom
kolyshkin:user-exec
Mar 28, 2023
Merged

Fix runc run "permission denied" when rootless#3753
AkihiroSuda merged 3 commits intoopencontainers:mainfrom
kolyshkin:user-exec

Conversation

@kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Feb 28, 2023

Fixes: #3715

Since PR #3522 (commit 957d97b) was made to fix issue #3520,
a few things happened:

  • a similar functionality appeared in go 1.20 [1], so the issue
    mentioned in the comment (being removed) is no longer true;
  • a bug in runc was found [2], which also affects go [3];
  • the bug was fixed in go 1.21 [4] and 1.20.2 [5];
  • a similar fix was made to x/sys/unix.Faccessat [6].

The essense of the bug #3715 is, even if a (non-root) user that the container is
run as does not have execute permission bit set for the executable, it
should still work in case runc has the CAP_DAC_OVERRIDE capability set.

To fix #3715 without reintroducing the older bug [7]:

  • drop own Eaccess implementation;
  • use the one from x/sys/unix for Go 1.19 (depends on [6]);
  • do not use anything when Go 1.20+ is used.

Add a test case to make sure we won't regress.

NOTE it is virtually impossible to fix the bug [2] when Go 1.20 or Go
1.20.1 is used because of [3].

[1] https://go-review.googlesource.com/c/go/+/414824
[2] #3715
[3] https://go.dev/issue/58552
[4] https://go-review.googlesource.com/c/go/+/468735
[5] https://go-review.googlesource.com/c/go/+/469956
[6] https://go-review.googlesource.com/c/sys/+/468877
[7] #3520

@kolyshkin kolyshkin added this to the 1.2.0 milestone Feb 28, 2023
@kolyshkin kolyshkin added regression backport/1.1-todo A PR in main branch which needs to be backported to release-1.1 labels Feb 28, 2023
@kolyshkin kolyshkin force-pushed the user-exec branch 2 times, most recently from ab28e5c to 10c0299 Compare February 28, 2023 01:38
@AkihiroSuda
Copy link
Member

Go 1.20.2 seems released

@kolyshkin
Copy link
Contributor Author

Reworked to not re-introduced #3520. Description updated.

@kolyshkin kolyshkin changed the title Revert "Fix error from runc run on noexec fs" Fix runc run "permission denied" when rootless Mar 9, 2023
@kolyshkin kolyshkin marked this pull request as ready for review March 16, 2023 17:38
@kolyshkin
Copy link
Contributor Author

@opencontainers/runc-maintainers PTAL (this needs to be merged then backported to 1.1, and since it is a regression in 1.1.4 I want to fix it in time for 1.1.5).

mrunalp
mrunalp previously approved these changes Mar 20, 2023
Copy link
Contributor

@mrunalp mrunalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kolyshkin kolyshkin requested a review from a team March 20, 2023 21:41
Go 1.20.2 has an important fix to an issue described in [1].

Switch from using Go 1.19 from Dockerfile, which is used for release
binaries and some CI.

[1] golang/go#58624

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Since commit 957d97b was made to fix issue [7],
a few things happened:

- a similar functionality appeared in go 1.20 [1], so the issue
  mentioned in the comment (being removed) is no longer true;
- a bug in runc was found [2], which also affects go [3];
- the bug was fixed in go 1.21 [4] and 1.20.2 [5];
- a similar fix was made to x/sys/unix.Faccessat [6].

The essense of [2] is, even if a (non-root) user that the container is
run as does not have execute permission bit set for the executable, it
should still work in case runc has the CAP_DAC_OVERRIDE capability set.

To fix this [2] without reintroducing the older bug [7]:
- drop own Eaccess implementation;
- use the one from x/sys/unix for Go 1.19 (depends on [6]);
- do not use anything when Go 1.20+ is used.

NOTE it is virtually impossible to fix the bug [2] when Go 1.20 or Go
1.20.1 is used because of [3].

A test case is added by a separate commit.

Fixes: opencontainers#3715.

[1] https://go-review.googlesource.com/c/go/+/414824
[2] opencontainers#3715
[3] https://go.dev/issue/58552
[4] https://go-review.googlesource.com/c/go/+/468735
[5] https://go-review.googlesource.com/c/go/+/469956
[6] https://go-review.googlesource.com/c/sys/+/468877
[7] opencontainers#3520

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This is a test case for issue reported as opencontainers#3715. In short, even if a
(non-root) user that the container is run as does not have execute
permission bit set for the executable, it should still work in case runc
has the CAP_DAC_OVERRIDE capability set.

Note that since the upstream golang is also broken (see [1]), this test
will fail for Go 1.20 and 1.20.1 (fix is in Go 1.20.2 as per [2]).

[1] https://go.dev/issue/58552
[2] https://go-review.googlesource.com/c/go/+/469956

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
Copy link
Contributor Author

@AkihiroSuda @thaJeztah addressed your review comments, PTAAL.

@AkihiroSuda AkihiroSuda merged commit 7f3f4be into opencontainers:main Mar 28, 2023
@kolyshkin kolyshkin added backport/1.1-done A PR in main branch which has been backported to release-1.1 and removed backport/1.1-todo A PR in main branch which needs to be backported to release-1.1 labels Apr 6, 2023
@kolyshkin
Copy link
Contributor Author

1.1 backport: #3817

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/1.1-done A PR in main branch which has been backported to release-1.1 regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runc 1.1.4 container fails with permission denied: unknown when relying on capabilities

4 participants