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
shared/idmap: handle "both" idmappings in raw.idmap properly #12718
Merged
tomponline
merged 2 commits into
canonical:main
from
mihalicyn:lxc_file_push_raw_idmap_fix
Jan 18, 2024
Merged
shared/idmap: handle "both" idmappings in raw.idmap properly #12718
tomponline
merged 2 commits into
canonical:main
from
mihalicyn:lxc_file_push_raw_idmap_fix
Jan 18, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imagine container created with: lxc launch ubuntu:j c1 -c raw.idmap="both 1000 1000" Then "volatile.last_state.idmap" will be like: [ {"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000}, {"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1}, // <-- our custom idmapping {"Isuid":true,"Isgid":false,"Hostid":1001001,"Nsid":1001,"Maprange":999998999}, {"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000}, {"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1}, // <-- oops, 2nd time! {"Isuid":false,"Isgid":true,"Hostid":1001001,"Nsid":1001,"Maprange":999998999} ] This makes idmapset.ToUidMappings() output incorrect (because mapping will be reported 2 times) and breaks "lxc file push" functionality for containers with the root filesystem that doesn't support idmapped mounts (because if it supports idmapped mounts then volatile.last_state.idmap will be [] anyways). That explains why Simon was able to reproduce that with ZFS but I wasn't able to reproduce it with ext4-based "dir" storage driver. Fixes: canonical#12507 Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
@mihalicyn please can you add a test for this. |
I have added a test and validated that this test actually works and allows to reproduce the issue in our test environment. |
Big thanks to Simon Fels (@morphis) for providing us with a reproducer. Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
mihalicyn
force-pushed
the
lxc_file_push_raw_idmap_fix
branch
from
January 11, 2024 17:11
9e6bf3e
to
fdf9b9e
Compare
Thanks! |
tomponline
approved these changes
Jan 18, 2024
mihalicyn
added a commit
to mihalicyn/lxd
that referenced
this pull request
Apr 15, 2024
…mapping only if it's required Fix diskAddRootUserNSEntry logic to correcly handle case when we have not-groupped UID/GID mapping like this: [{true false 1000 0 1} {false true 1000 0 1}] because right now it assumes that mapping should be like [{true true 1000 0 1}] which is logically equivalent. This become noticable after my change in canonical#12718, before that this issue in logic was reproducible only if user will do something like this: cat << EOF uid $(id -u) 1000000 gid $(id -g) 1000000 EOF ) | lxc config set idmap raw.idmap - which is an extremely rare usecase. Fixes: canonical#13325 Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
tomponline
pushed a commit
to tomponline/lxd
that referenced
this pull request
Apr 16, 2024
…mapping only if it's required Fix diskAddRootUserNSEntry logic to correcly handle case when we have not-groupped UID/GID mapping like this: [{true false 1000 0 1} {false true 1000 0 1}] because right now it assumes that mapping should be like [{true true 1000 0 1}] which is logically equivalent. This become noticable after my change in canonical#12718, before that this issue in logic was reproducible only if user will do something like this: cat << EOF uid $(id -u) 1000000 gid $(id -g) 1000000 EOF ) | lxc config set idmap raw.idmap - which is an extremely rare usecase. Fixes: canonical#13325 Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
tomponline
pushed a commit
to tomponline/lxd
that referenced
this pull request
Apr 17, 2024
…mapping only if it's required Fix diskAddRootUserNSEntry logic to correcly handle case when we have not-groupped UID/GID mapping like this: [{true false 1000 0 1} {false true 1000 0 1}] because right now it assumes that mapping should be like [{true true 1000 0 1}] which is logically equivalent. This become noticable after my change in canonical#12718, before that this issue in logic was reproducible only if user will do something like this: cat << EOF uid $(id -u) 1000000 gid $(id -g) 1000000 EOF ) | lxc config set idmap raw.idmap - which is an extremely rare usecase. Fixes: canonical#13325 Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
tomponline
pushed a commit
to tomponline/lxd
that referenced
this pull request
Apr 17, 2024
…mapping only if it's required Fix diskAddRootUserNSEntry logic to correcly handle case when we have not-groupped UID/GID mapping like this: [{true false 1000 0 1} {false true 1000 0 1}] because right now it assumes that mapping should be like [{true true 1000 0 1}] which is logically equivalent. This become noticable after my change in canonical#12718, before that this issue in logic was reproducible only if user will do something like this: cat << EOF uid $(id -u) 1000000 gid $(id -g) 1000000 EOF ) | lxc config set idmap raw.idmap - which is an extremely rare usecase. Fixes: canonical#13325 Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
hamistao
pushed a commit
to hamistao/lxd
that referenced
this pull request
Apr 18, 2024
…mapping only if it's required Fix diskAddRootUserNSEntry logic to correcly handle case when we have not-groupped UID/GID mapping like this: [{true false 1000 0 1} {false true 1000 0 1}] because right now it assumes that mapping should be like [{true true 1000 0 1}] which is logically equivalent. This become noticable after my change in canonical#12718, before that this issue in logic was reproducible only if user will do something like this: cat << EOF uid $(id -u) 1000000 gid $(id -g) 1000000 EOF ) | lxc config set idmap raw.idmap - which is an extremely rare usecase. Fixes: canonical#13325 Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Imagine container created with:
lxc launch ubuntu:j c1 -c raw.idmap="both 1000 1000"
Then "volatile.last_state.idmap" will be like:
[
{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000},
{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1}, // <-- our custom idmapping
{"Isuid":true,"Isgid":false,"Hostid":1001001,"Nsid":1001,"Maprange":999998999},
{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000},
{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1}, // <-- oops, 2nd time!
{"Isuid":false,"Isgid":true,"Hostid":1001001,"Nsid":1001,"Maprange":999998999}
]
This makes idmapset.ToUidMappings() output incorrect (because mapping will be reported 2 times) and breaks "lxc file push" functionality for containers with the root filesystem that doesn't support idmapped mounts (because if it supports idmapped mounts then volatile.last_state.idmap will be [] anyways). That explains why Simon was able to reproduce that with ZFS but I wasn't able to reproduce it with ext4-based "dir" storage driver.
Fixes: #12507