Use v2 capabilities in layer archives#41724
Conversation
|
Hi, I would rather this went via buildkit first as that is where we are doing the work in build. We might port it to the legacy builder, but this is not where we are largely doing build development work. |
|
@justincormack , thanks I'll take a look. Would you be able to point me to where in buildkit this should go? Trying to get to grips with the buildkit code: IIUC buildkit leverages containerd to write out image layers, correct? Would this be the right place to make the equivalent change? |
|
@justincormack I've come to realise BuildKit is using the same block of code to build the tarballs, so this PR is also the fix for BuildKit. Or am I missing something? |
|
@tonistiigi PTAL |
|
Could you add integration tests? |
|
@dmcgowan @estesp would containerd's archive package also need similar changes? https://github.com/containerd/containerd/tree/master/archive |
|
@AkihiroSuda is there an image I can use in the integration tests that would support the I might be able to get away without this, however it would be a lot uglier: basically |
|
Alpine's libcap looks to have it, but don't think we include it in the frozen images. |
|
@thaJeztah in integration tests, are we supposed to use only the frozen images, or is it considered OK to use e.g. Alpine for cases such as this? From what I've seen, integration tests only use scratch or frozen images, so my guess was I'm not supposed to use anything else. And if I should only use frozen images, would it be acceptable for me to add Alpine to the list? |
d07ded3 to
72bf86a
Compare
|
Integration test implemented in #41740. Switching this PR to draft for now as it will require an update to the test once that has merged. |
72bf86a to
01d3a17
Compare
When building images in a user-namespaced container, v3 capabilities are stored including the root UID of the creator of the user-namespace. This UID does not make sense outside the build environment however. If the image is run in a non-user-namespaced runtime, or if a user-namespaced runtime uses a different UID, the capabilities requested by the effective bit will not be honoured by `execve(2)` due to this mismatch. Instead, we convert v3 capabilities to v2, dropping the root UID on the fly. Signed-off-by: Eric Mountain <eric.mountain@datadoghq.com>
01d3a17 to
95eb490
Compare
|
Test in #41740 merged, the fix is now ready for review. |
|
Hi @thaJeztah , @AkihiroSuda might I get a review now the integration test PR has merged? Thanks! |
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM
ping @AkihiroSuda @tonistiigi PTAL
|
do we need similar changes in containerd as well, @AkihiroSuda ? |
Better to have, but not urgent |
@EricMountain perhaps you're interested in contributing to containerd as well? (Or to open a tracking issue, describing the problem)? |
@thaJeztah sure, I'll take a look. |
|
@AkihiroSuda Do we need to cherry-pick this? Is this breaking existing users? Should we strip to v3 part on extraction if it is node specific. |
|
@AkihiroSuda ^ could you have a look? |
|
Seems safe to cherry-pick, but if we can have v21.xx soon, I guess cherry-picking is not necessary. |
|
Cherry-picked as #42352 |
- What I did
Fixes #41723
When building images in a user-namespaced container, v3 capabilities are
stored including the root UID of the creator of the user-namespace.
This UID does not make sense outside the build environment however. If
the image is run in a non-user-namespaced runtime, or if a user-namespaced
runtime uses a different UID, the capabilities requested by the effective
bit will not be honoured by
execve(2)due to this mismatch.Instead, we convert v3 capabilities to v2, dropping the root UID on the
fly.
- How I did it
Patched
ReadSecurityXattrToTarHeader()to automatically convert v3 capabilities to v2 by switching the version identifier and dropping the root UID data.- How to verify it
This reproducer can be used.
Compared with the output in issue #41723 this produces:
So we see that in the 2nd case also
execve(2)honoured the effective bit.- Description for the changelog
Capabilities in image layers are stored in v2 format even when built inside a non-root user-namespace.
- A picture of a cute animal (not mandatory but encouraged)