Skip to content
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
merged 2 commits into from Jan 18, 2024

Conversation

mihalicyn
Copy link
Member

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

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>
@tomponline
Copy link
Member

@mihalicyn please can you add a test for this.

@mihalicyn
Copy link
Member Author

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>
@tomponline
Copy link
Member

Thanks!

@tomponline tomponline merged commit 2e1f30e into canonical:main Jan 18, 2024
25 of 26 checks passed
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pushing files to a stopped container with raw.idmap set does not work
2 participants