0

我有一个lxd容器,名为master. 我发现它的根可以在以下位置找到:

/var/lib/lxd/containers/master/rootfs/home/ubuntu/

所以,我把我的文件夹转移tars到了这个地址。注意tars有两个文件。

现在,我知道用户 id 和组 idtarsroot. 另一方面,容器中每个其他文件的用户 ID 和组 ID 都是166536.

因此,对于文件夹和文件,我sudo chown 166536 <file/folder name>更改了用户 ID,并sudo chown :166536 <file/folder name>更改了组 ID。

有一次,我这样做了,我希望tars可以从 container 访问master,但这并没有发生。谁能告诉我我错过了什么?


这是我在reddit上找到的一种方法:

是的,这就是答案,使用非特权容器运行您无法看到 LXD 主机上的权限,因此它显示为“Nobody:Nobody”。在某种程度上是愚蠢的,因为您可以将文件夹安装到容器中并查看其中的文件..

供将来参考,对于遇到此问题的任何人,这是我所做的步骤(它可能不是正确的,但它有效)

sudo mkdir /tmp/share
adduser subsonic --shell=/bin/false --no-create-home --system --group --uid 6000 (this is a "service account")
sudo chown -R subsonic: /tmp/share
lxc exec Test -- /bin/bash
mkdir /mnt/share
adduser subsonic --shell=/bin/false --no-create-home --system --group --uid 6000 (important that the uid is the same)
exit
lxc stop Test
lxc config edit Test (add the line security.privileged: "true" right bellow config: save and exit)
lxc start Test
lxc config device add MyMusic MyLibrary disk source=/tmp/share path=/mnt/share
lxc exec Test -- /bin/bash
ls /mnt/share/ (note that the subsonic user is there)
exit

很遗憾我找不到将用户映射到非特权容器内的方法。如果有人知道让我知道。

基本上,为主机和容器创建一个通用用户。有什么比这种方法更好的吗?

4

1 回答 1

0

当你打开容器并做

whoami

你会得到结果:

root

所以,当前用户是root,而不是ubuntu。话虽如此,我将文件夹发送到的地址是错误的。当前地址是var/lib/lxd/containers/master/root/。发送文件夹后,检查 uid/gid(类似于 165536)。通过以下方式更改 uid:

sudo chmod 165536 <folder-name>

并通过:

sudo chmod :165536 <folder-name>

完成后,我们确信容器用户root将能够访问这些文件。

或者一步到位sudo chmod 165536:165536 <folder-name>

于 2019-03-22T09:34:07.667 回答