Skip to content

Commit

Permalink
Create directories with 755 and not 644
Browse files Browse the repository at this point in the history
checkpointctl was creating directories with 644 which broke usage when
running as non-root as checkpointctl was not able to access the
directories it created itself. Switching to 755 fixes it.

This comes with a test to verify that checkpointctl works as non-root.

Signed-off-by: Adrian Reber <[email protected]>
  • Loading branch information
adrianreber committed Dec 14, 2024
1 parent 8a3ffb9 commit 5666a4c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func UntarFiles(src, dest string, files []string) error {
for _, file := range files {
if strings.Contains(header.Name, file) {
// Create the destination folder
if err := os.MkdirAll(filepath.Join(dest, filepath.Dir(header.Name)), 0o644); err != nil {
if err := os.MkdirAll(filepath.Join(dest, filepath.Dir(header.Name)), 0o755); err != nil {
return err
}
// Create the destination file
Expand Down
27 changes: 27 additions & 0 deletions test/checkpointctl.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ function checkpointctl() {
function setup() {
TEST_TMP_DIR1=$(mktemp -d)
TEST_TMP_DIR2=$(mktemp -d)
NON_ROOT_TMP1=$(sudo -u 'nobody' mktemp -d)
}

function teardown() {
[ "$TEST_TMP_DIR1" != "" ] && rm -rf "$TEST_TMP_DIR1"
[ "$TEST_TMP_DIR2" != "" ] && rm -rf "$TEST_TMP_DIR2"
[ "$NON_ROOT_TMP1" != "" ] && rm -rf "$NON_ROOT_TMP1"
}

@test "Run checkpointctl" {
Expand Down Expand Up @@ -301,6 +303,31 @@ function teardown() {
[[ ${lines[10]} == *"piggie/piggie"* ]]
}

@test "Run checkpointctl inspect with tar file and --ps-tree-cmd as non-root" {
if [ "$CHECKPOINTCTL" == "../checkpointctl.coverage" ]; then
skip "non-root test cannot access the coverage directory"
fi
cp data/config.dump \
data/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
cp test-imgs/pstree.img \
test-imgs/core-*.img \
test-imgs/pagemap-*.img \
test-imgs/pages-*.img \
test-imgs/mm-*.img "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$NON_ROOT_TMP1"/test.tar . )
chmod 644 "$NON_ROOT_TMP1"/test.tar
NON_ROOT_BIN=$(mktemp)
cp "$CHECKPOINTCTL" "$NON_ROOT_BIN"
chmod 755 "$NON_ROOT_BIN"
run sudo -u 'nobody' "$NON_ROOT_BIN" inspect "$NON_ROOT_TMP1"/test.tar --ps-tree-cmd
echo "$output"
rm -f "$NON_ROOT_BIN"
[ "$status" -eq 0 ]
[[ ${lines[9]} == *"Process tree"* ]]
[[ ${lines[10]} == *"piggie/piggie"* ]]
}

@test "Run checkpointctl inspect with tar file and --ps-tree-cmd and missing pages-*.img" {
cp data/config.dump \
data/spec.dump "$TEST_TMP_DIR1"
Expand Down

0 comments on commit 5666a4c

Please sign in to comment.