Skip to content

Commit 93cc2c7

Browse files
Merge pull request #9563 from adrianreber/2025-11-03-passwd
OCPBUGS-62150: server: ignore /etc/passwd mount
2 parents ba7bba6 + 9d7aa99 commit 93cc2c7

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
@@ -272,6 +272,8 @@ func (s *Server) CRImportCheckpoint(
272272
"/dev/shm": true,
273273
"/etc/resolv.conf": true,
274274
"/etc/hostname": true,
275+
"/etc/passwd": true,
276+
"/etc/group": true,
275277
"/run/secrets": true,
276278
"/run/.containerenv": true,
277279
}

test/checkpoint.bats

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,44 @@ function teardown() {
174174
[[ "$container_name" == "restored-sleep-container" ]]
175175
[[ "$pod_name" == "restoresandbox2" ]]
176176
}
177+
178+
@test "checkpoint and restore: /etc/passwd uses Kubernetes run_as_user on restore" {
179+
CONTAINER_ENABLE_CRIU_SUPPORT=true start_crio
180+
pod_id=$(crictl runp "$TESTDATA"/sandbox_config.json)
181+
# Create container with run_as_user=1001
182+
START_JSON=$(mktemp)
183+
jq '.linux.security_context.run_as_user.value = 1001
184+
| .command=["/bin/sh"]
185+
| .args=["-c","sleep inf"]' \
186+
"$TESTDATA"/container_sleep.json > "$START_JSON"
187+
ctr_id=$(crictl create "$pod_id" "$START_JSON" "$TESTDATA"/sandbox_config.json)
188+
crictl start "$ctr_id"
189+
# Verify the UID of the running process
190+
run crictl exec "$ctr_id" id
191+
[[ "$output" == *"uid=1001"* ]]
192+
# Verify /etc/passwd contains entry for UID 1001
193+
run crictl exec "$ctr_id" cat /etc/passwd
194+
[[ "$output" == *"1001"* ]]
195+
# Checkpoint the container
196+
crictl checkpoint --export="$TESTDIR"/cp.tar "$ctr_id"
197+
crictl rm -f "$ctr_id"
198+
crictl rmp -f "$pod_id"
199+
pod_id=$(crictl runp "$TESTDATA"/sandbox_config.json)
200+
RESTORE_JSON=$(mktemp)
201+
jq '.image.image="'"$TESTDIR"'/cp.tar"
202+
| .linux.security_context.run_as_user.value = 1001' \
203+
"$TESTDATA"/container_sleep.json > "$RESTORE_JSON"
204+
ctr_id=$(crictl create "$pod_id" "$RESTORE_JSON" "$TESTDATA"/sandbox_config.json)
205+
crictl start "$ctr_id"
206+
# Verify that the container was restored
207+
restored=$(crictl inspect --output go-template --template "{{(index .info.restored)}}" "$ctr_id")
208+
[[ "$restored" == "true" ]]
209+
# Verify the UID is still 1001
210+
run crictl exec "$ctr_id" id
211+
[[ "$output" == *"uid=1001"* ]]
212+
run crictl exec "$ctr_id" cat /etc/passwd
213+
[[ "$output" == *"1001"* ]]
214+
# Cleanup
215+
rm -f "$START_JSON"
216+
rm -f "$RESTORE_JSON"
217+
}

0 commit comments

Comments
 (0)