github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/tests/integration/hooks_so.bats (about) 1 #!/usr/bin/env bats 2 3 load helpers 4 5 function setup() { 6 requires root no_systemd 7 8 setup_debian 9 # CR = CreateRuntime, CC = CreateContainer 10 HOOKLIBCR=librunc-hooks-create-runtime.so 11 HOOKLIBCC=librunc-hooks-create-container.so 12 LIBPATH="$(pwd)/rootfs/lib/" 13 } 14 15 function teardown() { 16 if [ -v LIBPATH ]; then 17 umount "$LIBPATH/$HOOKLIBCR".1.0.0 &>/dev/null || true 18 umount "$LIBPATH/$HOOKLIBCC".1.0.0 &>/dev/null || true 19 rm -f "$HOOKLIBCR".1.0.0 "$HOOKLIBCC".1.0.0 20 unset LIBPATH HOOKLIBCR HOOKLIBCC 21 fi 22 teardown_bundle 23 } 24 25 @test "runc run (hooks library tests)" { 26 # setup some dummy libs 27 gcc -shared -Wl,-soname,librunc-hooks-create-runtime.so.1 -o "$HOOKLIBCR.1.0.0" 28 gcc -shared -Wl,-soname,librunc-hooks-create-container.so.1 -o "$HOOKLIBCC.1.0.0" 29 30 bundle=$(pwd) 31 32 # To mount $HOOKLIBCR we need to do that in the container namespace 33 create_runtime_hook=$( 34 cat <<-EOF 35 pid=\$(cat - | jq -r '.pid') 36 touch "$LIBPATH/$HOOKLIBCR.1.0.0" 37 nsenter -m \$ns -t \$pid mount --bind "$bundle/$HOOKLIBCR.1.0.0" "$LIBPATH/$HOOKLIBCR.1.0.0" 38 EOF 39 ) 40 41 create_container_hook="touch ./lib/$HOOKLIBCC.1.0.0 && mount --bind $bundle/$HOOKLIBCC.1.0.0 ./lib/$HOOKLIBCC.1.0.0" 42 43 # shellcheck disable=SC2016 44 update_config --arg create_runtime_hook "$create_runtime_hook" --arg create_container_hook "$create_container_hook" ' 45 .hooks |= . + {"createRuntime": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", $create_runtime_hook]}]} | 46 .hooks |= . + {"createContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", $create_container_hook]}]} | 47 .hooks |= . + {"startContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", "ldconfig"]}]} | 48 .root.readonly |= false | 49 .process.args = ["/bin/sh", "-c", "ldconfig -p | grep librunc"]' 50 51 runc run test_debian 52 [ "$status" -eq 0 ] 53 54 echo "Checking create-runtime library" 55 echo "$output" | grep "$HOOKLIBCR" 56 57 echo "Checking create-container library" 58 echo "$output" | grep "$HOOKLIBCC" 59 }