-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
idmap.bats
168 lines (142 loc) · 4.35 KB
/
idmap.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env bats
load helpers
function setup() {
requires root
requires_kernel 5.12
requires_idmap_fs /tmp
setup_debian
# Prepare source folders for bind mount
mkdir -p source-{1,2}/
touch source-{1,2}/foo.txt
# Use other owner for source-2
chown 1:1 source-2/foo.txt
mkdir -p rootfs/{proc,sys,tmp}
mkdir -p rootfs/tmp/mount-{1,2}
mkdir -p rootfs/mnt/bind-mount-{1,2}
update_config ' .linux.namespaces += [{"type": "user"}]
| .linux.uidMappings += [{"hostID": 100000, "containerID": 0, "size": 65536}]
| .linux.gidMappings += [{"hostID": 100000, "containerID": 0, "size": 65536}]
| .process.args += ["-c", "stat -c =%u=%g= /tmp/mount-1/foo.txt"]
| .mounts += [
{
"source": "source-1/",
"destination": "/tmp/mount-1",
"options": ["bind"],
"uidMappings": [ {
"containerID": 0,
"hostID": 100000,
"size": 65536
}
],
"gidMappings": [ {
"containerID": 0,
"hostID": 100000,
"size": 65536
}
]
}
] '
}
function teardown() {
teardown_bundle
}
@test "simple idmap mount" {
runc run test_debian
[ "$status" -eq 0 ]
[[ "$output" == *"=0=0="* ]]
}
@test "write to an idmap mount" {
update_config ' .process.args = ["sh", "-c", "touch /tmp/mount-1/bar && stat -c =%u=%g= /tmp/mount-1/bar"]'
runc run test_debian
[ "$status" -eq 0 ]
[[ "$output" == *"=0=0="* ]]
}
@test "idmap mount with propagation flag" {
update_config ' .process.args = ["sh", "-c", "findmnt -o PROPAGATION /tmp/mount-1"]'
# Add the shared option to the idmap mount
update_config ' .mounts |= map((select(.source == "source-1/") | .options += ["shared"]) // .)'
runc run test_debian
[ "$status" -eq 0 ]
[[ "$output" == *"shared"* ]]
}
@test "idmap mount with relative path" {
update_config ' .mounts |= map((select(.source == "source-1/") | .destination = "tmp/mount-1") // .)'
runc run test_debian
[ "$status" -eq 0 ]
[[ "$output" == *"=0=0="* ]]
}
@test "idmap mount with bind mount" {
update_config ' .mounts += [
{
"source": "source-2/",
"destination": "/tmp/mount-2",
"options": ["bind"]
}
] '
runc run test_debian
[ "$status" -eq 0 ]
[[ "$output" == *"=0=0="* ]]
}
@test "two idmap mounts with two bind mounts" {
update_config ' .process.args = ["sh", "-c", "stat -c =%u=%g= /tmp/mount-1/foo.txt /tmp/mount-2/foo.txt"]
| .mounts += [
{
"source": "source-1/",
"destination": "/mnt/bind-mount-1",
"options": ["bind"]
},
{
"source": "source-2/",
"destination": "/mnt/bind-mount-2",
"options": ["bind"]
},
{
"source": "source-2/",
"destination": "/tmp/mount-2",
"options": ["bind"],
"uidMappings": [ {
"containerID": 0,
"hostID": 100000,
"size": 65536
}
],
"gidMappings": [ {
"containerID": 0,
"hostID": 100000,
"size": 65536
}
]
}
] '
runc run test_debian
[ "$status" -eq 0 ]
[[ "$output" == *"=0=0="* ]]
# source-2/ is owned by 1:1, so we expect this with the idmap mount too.
[[ "$output" == *"=1=1="* ]]
}
@test "idmap mount without gidMappings fails" {
update_config ' .mounts |= map((select(.source == "source-1/") | del(.gidMappings) ) // .)'
runc run test_debian
[ "$status" -eq 1 ]
[[ "${output}" == *"invalid mount"* ]]
}
@test "idmap mount without uidMappings fails" {
update_config ' .mounts |= map((select(.source == "source-1/") | del(.uidMappings) ) // .)'
runc run test_debian
[ "$status" -eq 1 ]
[[ "${output}" == *"invalid mount"* ]]
}
@test "idmap mount without bind fails" {
update_config ' .mounts |= map((select(.source == "source-1/") | .options = [""]) // .)'
runc run test_debian
[ "$status" -eq 1 ]
[[ "${output}" == *"invalid mount"* ]]
}
@test "idmap mount with different mapping than userns fails" {
# Let's modify the containerID to be 1, instead of 0 as it is in the
# userns config.
update_config ' .mounts |= map((select(.source == "source-1/") | .uidMappings[0]["containerID"] = 1 ) // .)'
runc run test_debian
[ "$status" -eq 1 ]
[[ "${output}" == *"invalid mount"* ]]
}