Skip to content

Commit 5962cd7

Browse files
adrianreberopenshift-cherrypick-robot
authored andcommitted
OCPBUGS-62150: server: ignore /etc/passwd mount
Ignore /etc/passwd when checking for mounts. Always rely on the mount as defined from Kubernetes. This follows existing practice like for /etc/hosts or /etc/resolv.conf Signed-off-by: Adrian Reber <[email protected]>
1 parent 3053632 commit 5962cd7

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

server/container_restore.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ func (s *Server) CRImportCheckpoint(
273273
"/dev/shm": true,
274274
"/etc/resolv.conf": true,
275275
"/etc/hostname": true,
276+
"/etc/passwd": true,
277+
"/etc/group": true,
276278
"/run/secrets": true,
277279
"/run/.containerenv": true,
278280
}

test/checkpoint.bats

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,44 @@ function teardown() {
154154
[[ "$container_name" == "restored-sleep-container" ]]
155155
[[ "$pod_name" == "restoresandbox2" ]]
156156
}
157+
158+
@test "checkpoint and restore: /etc/passwd uses Kubernetes run_as_user on restore" {
159+
CONTAINER_ENABLE_CRIU_SUPPORT=true start_crio
160+
pod_id=$(crictl runp "$TESTDATA"/sandbox_config.json)
161+
# Create container with run_as_user=1001
162+
START_JSON=$(mktemp)
163+
jq '.linux.security_context.run_as_user.value = 1001
164+
| .command=["/bin/sh"]
165+
| .args=["-c","sleep inf"]' \
166+
"$TESTDATA"/container_sleep.json > "$START_JSON"
167+
ctr_id=$(crictl create "$pod_id" "$START_JSON" "$TESTDATA"/sandbox_config.json)
168+
crictl start "$ctr_id"
169+
# Verify the UID of the running process
170+
run crictl exec "$ctr_id" id
171+
[[ "$output" == *"uid=1001"* ]]
172+
# Verify /etc/passwd contains entry for UID 1001
173+
run crictl exec "$ctr_id" cat /etc/passwd
174+
[[ "$output" == *"1001"* ]]
175+
# Checkpoint the container
176+
crictl checkpoint --export="$TESTDIR"/cp.tar "$ctr_id"
177+
crictl rm -f "$ctr_id"
178+
crictl rmp -f "$pod_id"
179+
pod_id=$(crictl runp "$TESTDATA"/sandbox_config.json)
180+
RESTORE_JSON=$(mktemp)
181+
jq '.image.image="'"$TESTDIR"'/cp.tar"
182+
| .linux.security_context.run_as_user.value = 1001' \
183+
"$TESTDATA"/container_sleep.json > "$RESTORE_JSON"
184+
ctr_id=$(crictl create "$pod_id" "$RESTORE_JSON" "$TESTDATA"/sandbox_config.json)
185+
crictl start "$ctr_id"
186+
# Verify that the container was restored
187+
restored=$(crictl inspect --output go-template --template "{{(index .info.restored)}}" "$ctr_id")
188+
[[ "$restored" == "true" ]]
189+
# Verify the UID is still 1001
190+
run crictl exec "$ctr_id" id
191+
[[ "$output" == *"uid=1001"* ]]
192+
run crictl exec "$ctr_id" cat /etc/passwd
193+
[[ "$output" == *"1001"* ]]
194+
# Cleanup
195+
rm -f "$START_JSON"
196+
rm -f "$RESTORE_JSON"
197+
}

0 commit comments

Comments
 (0)