You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debian 12环境下LXD/LXC设置security.idmap.isolated=true后容器文件所有者/组映射失效问题求助

Debian 12环境下LXD/LXC设置security.idmap.isolated=true后容器文件所有者/组映射失效问题求助

大家好,我遇到了一个LXD/LXC的权限映射问题,想请各位帮忙分析下:

我在**Debian 12.1(内核6.1.0-11-amd64)**上运行LXD/LXC,给非特权容器设置security.idmap.isolated=true后,容器文件的所有者/组没有被正确映射,还是宿主的root用户。

复现步骤

  • 启动一个Debian 12容器:
lxc launch images:debian/12 debian
  • 查看容器的idmap基准值:
lxc config get debian volatile.idmap.base
# 输出:296608
  • 停止容器(确认已停止)后开启隔离idmap:
lxc stop debian
# 提示:Error: The instance is already stopped
lxc config set debian security.idmap.isolated true
lxc config get debian security.idmap.isolated
# 输出:true
  • 启动容器后,查看容器rootfs目录下的文件权限:
ls -la /mnt/NVME1/lxd/containers/debian/rootfs/

输出显示所有文件都属于宿主的root用户:

total 24
drwxr-xr-x 1 root   root  154 Sep  5 06:28 .
d--x------ 1 296608 root   78 Sep  5 15:59 ..
lrwxrwxrwx 1 root   root    7 Sep  5 06:25 bin -> usr/bin
drwxr-xr-x 1 root   root    0 Jul 14 17:00 boot
drwxr-xr-x 1 root   root    0 Sep  5 06:28 dev
drwxr-xr-x 1 root   root 1570 Sep  5 06:28 etc

对比其他Debian版本的正常情况

我测试了多个LXD版本(apt源的5.0.2、snap的4.0和最新5.17),都出现这个问题。但在**Debian 10(内核4.19.0-25-amd64,snap版LXD 4)和Debian 11(内核5.10.0-25-amd64)**上,设置security.idmap.isolated=true后,容器文件会正确映射到隔离的UID/GID(比如1065536:1065536):

Debian 10的文件权限输出:

ls -la /mnt/NVME1/lxd/containers/debian/rootfs/
total 0
drwxr-xr-x 1 1065536 1065536  138 Oct 29  2020 .
d--x------ 1 1065536 root      78 Oct 14  2020 ..
drwxr-xr-x 1 1065536 1065536 1328 Jul 24 19:07 bin
drwxr-xr-x 1 1065536 1065536    0 Sep 19  2020 boot
drwxr-xr-x 1 1065536 1065536    0 Oct 14  2020 dev
drwxr-xr-x 1 1065536 1065536 1716 Jul 24 19:08 etc

排查到的idmap配置差异

对比两台机器的容器配置(lxc config show debian),发现Debian 12的容器缺少了volatile.last_state.idmap的映射规则:

  • Debian 10的容器关键配置:
    security.idmap.isolated: "true"
    volatile.idmap.base: "1065536"
    volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":1065536,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1065536,"Nsid":0,"Maprange":65536}]'
    volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":1065536,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1065536,"Nsid":0,"Maprange":65536}]'
    volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":1065536,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1065536,"Nsid":0,"Maprange":65536}]'
    
  • Debian 12的容器关键配置:
    security.idmap.isolated: "true"
    volatile.idmap.base: "231072"
    volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":231072,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":231072,"Nsid":0,"Maprange":65536}]'
    volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":231072,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":231072,"Nsid":0,"Maprange":65536}]'
    volatile.last_state.idmap: '[]'
    

我猜测这个问题可能和Debian 12的新内核或者内核配置有关,但不确定具体原因。有没有朋友遇到过类似问题?或者知道怎么修复这个映射失效的问题?麻烦指点一下,谢谢!

备注:内容来源于stack exchange,提问作者TCB13

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 14:28:10