Skip to content

Commit

Permalink
Copy NSS libraries to the Docker image. (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
igankevich authored May 9, 2024
1 parent 4b8c028 commit 96f108f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
5 changes: 5 additions & 0 deletions ci/containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ EOF

do_test_docker_image() {
docker build --tag "$tag"-test:latest - <"$workdir"/Dockerfile
# test whether patchelf worked for cijail
docker run --rm "$tag"-test:latest /usr/local/bin/cijail --version
# test whether patchelf worked for cijail-proxy
timeout --signal=KILL 30s \
docker run --rm --cap-add CAP_SYS_PTRACE "$tag"-test:latest /usr/local/bin/cijail true
# test DNS name resolution via NSS libraries
docker run --rm "$tag"-test:latest \
env CIJAIL_ENDPOINTS=https://github.com /usr/local/bin/cijail true
docker rmi "$tag"-test:latest
}

Expand Down
37 changes: 29 additions & 8 deletions ci/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,48 @@
install_dependencies() {
export DEBIAN_FRONTEND=noninteractive
apt-get -qq update
apt-get -qq install -y ca-certificates patchelf
apt-get -qq install -y \
ca-certificates \
patchelf \
libnss-myhostname
}

copy_libraries() {
ldd "$1" |
sed -rne 's/.*=> (.*) \(.*\)$/\1/p' |
while read -r path; do
cp -n "$path" "$lib"/ || true
done
}

make_chroot() {
lib=/usr/local/lib/cijail
mkdir -p "$lib"
for name in cijail cijail-proxy; do
ldd /usr/local/bin/$name |
sed -rne 's/.*=> (.*) \(.*\)$/\1/p' |
while read -r path; do
cp -n "$path" "$lib"/ || true
done
copy_libraries /usr/local/bin/$name
done
# nss modules
ls -l /lib/x86_64-linux-gnu/libnss*
for name in files dns myhostname; do
file=/lib/x86_64-linux-gnu/libnss_$name.so.2
if ! test -e "$file"; then
file="/usr$file"
fi
copy_libraries "$file"
cp "$file" "$lib"/
done
cp /lib64/ld-linux-x86-64.so.2 "$lib"/
find "$lib"
for name in cijail cijail-proxy; do
patchelf \
--set-interpreter "$lib"/ld-linux-x86-64.so.2 \
--set-rpath "$lib" /usr/local/bin/$name
--set-rpath "$lib" \
/usr/local/bin/$name
ldd /usr/local/bin/$name
done
for file in "$lib"/lib*.so*; do
patchelf --set-rpath "$lib" "$file"
ldd "$file"
done
cijail --version
find /usr/local -type d -empty -delete
find /usr/local
Expand Down

0 comments on commit 96f108f

Please sign in to comment.