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

runc run: resolve tmpfs mount dest in container scope #2715

Merged
merged 3 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string, enableCgroupns b
case "tmpfs":
copyUp := m.Extensions&configs.EXT_COPYUP == configs.EXT_COPYUP
tmpDir := ""
// dest might be an absolute symlink, so it needs
// to be resolved under rootfs.
dest, err := securejoin.SecureJoin(rootfs, m.Destination)
if err != nil {
return err
}
m.Destination = dest
stat, err := os.Stat(dest)
if err != nil {
if err := os.MkdirAll(dest, 0755); err != nil {
Expand Down
34 changes: 29 additions & 5 deletions tests/integration/mounts.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,47 @@ function setup() {

function teardown() {
teardown_busybox
teardown_running_container test_bind_mount
}

@test "runc run [bind mount]" {
update_config ' .mounts += [{"source": ".", "destination": "/tmp/bind", "options": ["bind"]}]
update_config ' .mounts += [{
source: ".",
destination: "/tmp/bind",
options: ["bind"]
}]
| .process.args |= ["ls", "/tmp/bind/config.json"]'

runc run test_bind_mount
runc run test_busybox
[ "$status" -eq 0 ]
[[ "${lines[0]}" == *'/tmp/bind/config.json'* ]]
}

@test "runc run [ro tmpfs mount]" {
update_config ' .mounts += [{"source": "tmpfs", "destination": "/mnt", "type": "tmpfs", "options": ["ro", "nodev", "nosuid", "mode=755"]}]
update_config ' .mounts += [{
source: "tmpfs",
destination: "/mnt",
type: "tmpfs",
options: ["ro", "nodev", "nosuid", "mode=755"]
}]
| .process.args |= ["grep", "^tmpfs /mnt", "/proc/mounts"]'

runc run test_ro_tmpfs_mount
runc run test_busybox
[ "$status" -eq 0 ]
[[ "${lines[0]}" == *'ro,'* ]]
}

# https://github.com/opencontainers/runc/issues/2683
@test "runc run [tmpfs mount with absolute symlink]" {
# in container, /conf -> /real/conf
mkdir -p rootfs/real/conf
ln -s /real/conf rootfs/conf
update_config ' .mounts += [{
type: "tmpfs",
source: "tmpfs",
destination: "/conf/stack",
options: ["ro", "nodev", "nosuid"]
}]
| .process.args |= ["true"]'
runc run test_busybox
[ "$status" -eq 0 ]
}