Skip to content

Commit c814ddc

Browse files
author
Joe Ellis
committed
Add Docker image for testing Parsec as a systemd service
Signed-off-by: Joe Ellis <[email protected]>
1 parent 9530d64 commit c814ddc

File tree

4 files changed

+182
-0
lines changed

4 files changed

+182
-0
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ jobs:
4242
run: docker build -t tpm-provider e2e_tests/provider_cfg/tpm
4343
- name: Run the container to execute the test script
4444
run: docker run -v $(pwd):/tmp/parsec -w /tmp/parsec tpm-provider /tmp/parsec/ci.sh tpm
45+
46+
installation-tests:
47+
name: Installation tests
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v1
51+
- name: Build and run the container
52+
run: e2e_tests/installation_tests/run-installation-tests.sh
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM ubuntu:18.04
2+
3+
ENV container docker
4+
5+
RUN apt-get update
6+
RUN apt-get install -y git make gcc python3 python curl wget cmake \
7+
automake autoconf libtool pkg-config libssl-dev \
8+
# These libraries are needed for bindgen as it uses
9+
# libclang.so
10+
clang libclang-dev libc6-dev-i386
11+
RUN apt-get install -y systemd systemd-sysv
12+
RUN apt-get clean
13+
14+
RUN useradd -m parsec
15+
RUN groupadd parsec-clients
16+
RUN usermod -a -G parsec-clients parsec
17+
18+
USER parsec
19+
WORKDIR /home/parsec
20+
21+
# Install Rust toolchain.
22+
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
23+
ENV PATH "/home/parsec/.cargo/bin:$PATH"
24+
25+
# Install Parsec.
26+
RUN cargo install parsec-service --features mbed-crypto-provider
27+
RUN git clone https://github.com/parallaxsecond/parsec.git
28+
RUN cp parsec/config.toml config.toml
29+
30+
# Install the systemd unit files.
31+
RUN mkdir -p .config/systemd/user
32+
RUN cp parsec/systemd-daemon/parsec.service .config/systemd/user/parsec.service
33+
34+
USER root
35+
WORKDIR /root
36+
COPY context/run-tests.sh ./
37+
VOLUME [ "/sys/fs/cgroup" ]
38+
CMD [ "/lib/systemd/systemd" ]
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
function test_ping_parsec() {
6+
# Creates a new test user, adds them to the parsec-clients group, and
7+
# checks that the Parsec service can be pinged.
8+
9+
useradd -m test-user-1
10+
usermod -a -G parsec-clients test-user-1
11+
12+
su test-user-1 <<' EOSU'
13+
set -eu
14+
cd ${HOME}
15+
curl https://sh.rustup.rs -sSf | bash -s -- -y
16+
export PATH="${HOME}/.cargo/bin:$PATH"
17+
18+
git clone https://github.com/parallaxsecond/parsec-tool.git
19+
cd parsec-tool
20+
cargo build
21+
22+
set +e
23+
cargo run -- ping
24+
25+
# This test passes if the above command pinged the Parsec service
26+
# successfully.
27+
[ $? -eq 0 ]
28+
EOSU
29+
}
30+
31+
function test_ping_parsec_not_in_group() {
32+
# Creates a new test user, and tries to ping the Parsec service. This
33+
# should fail, since the user is not in the appropriate group.
34+
35+
useradd -m test-user-2
36+
37+
su test-user-2 <<' EOSU'
38+
set -eu
39+
cd ${HOME}
40+
curl https://sh.rustup.rs -sSf | bash -s -- -y
41+
export PATH="${HOME}/.cargo/bin:$PATH"
42+
43+
git clone https://github.com/parallaxsecond/parsec-tool.git
44+
cd parsec-tool
45+
cargo build
46+
47+
set +e
48+
cargo run -- ping
49+
50+
# This test passes if the above command failed to ping the Parsec service.
51+
[ $? -ne 0 ]
52+
EOSU
53+
}
54+
55+
function install_parsec() {
56+
mkdir /tmp/parsec
57+
chown parsec:parsec-clients /tmp/parsec
58+
chown -R parsec:parsec /home/parsec
59+
chmod 750 /tmp/parsec
60+
61+
# Configure and start the Parsec service as user `parsec`.
62+
su parsec << ' EOSU'
63+
set -eu
64+
export PATH="${HOME}/.cargo/bin:$PATH"
65+
cargo install --path ${HOME}/parsec --features 'mbed-crypto-provider'
66+
mkdir -p ${HOME}/.config/systemd/user
67+
cp ${HOME}/parsec/systemd-daemon/parsec.service \
68+
${HOME}/.config/systemd/user/parsec.service
69+
70+
systemctl --user daemon-reload
71+
systemctl --user start parsec
72+
EOSU
73+
}
74+
75+
function main() {
76+
install_parsec
77+
78+
# Register tests.
79+
declare -a TESTS
80+
TESTS[1]="test_ping_parsec"
81+
TESTS[2]="test_ping_parsec_not_in_group"
82+
83+
# Run tests.
84+
NUM_FAILED=0
85+
for i in "${!TESTS[@]}"; do
86+
TEST_NAME="${TESTS[$i]}"
87+
echo "=== RUNNING TEST ${TEST_NAME} ==="
88+
if ${TESTS[$i]}; then
89+
echo "${TEST_NAME} passed."
90+
else
91+
echo "${TEST_NAME} failed!"
92+
NUM_FAILED=$((NUM_FAILED + 1))
93+
fi
94+
echo "" # spacing
95+
done
96+
97+
if [[ ${NUM_FAILED} -eq 0 ]]; then
98+
echo "All tests passed!"
99+
else
100+
echo "${NUM_FAILED} test(s) failed!"
101+
fi
102+
103+
return ${NUM_FAILED}
104+
}
105+
106+
main "${@}" || exit 1
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6+
7+
DOCKER_IMAGE_DIR="$SCRIPT_DIR"
8+
DOCKER_IMAGE_NAME="parsec"
9+
10+
docker build -t ${DOCKER_IMAGE_NAME} ${DOCKER_IMAGE_DIR}
11+
DOCKER_CONTAINER_ID=$(docker run -d \
12+
--rm \
13+
--tmpfs /run \
14+
--tmpfs /run/lock \
15+
--tmpfs /tmp:exec \
16+
-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
17+
-v $(git rev-parse --show-toplevel):/home/parsec/parsec \
18+
${DOCKER_IMAGE_NAME})
19+
20+
# Give the systemd daemon some time to spin up.
21+
sleep 3
22+
23+
echo "Running tests inside container..."
24+
docker exec ${DOCKER_CONTAINER_ID} /root/run-tests.sh
25+
TEST_STATUS=$?
26+
27+
echo "Testing complete, stopping container."
28+
docker stop ${DOCKER_CONTAINER_ID}
29+
30+
exit ${TEST_STATUS}

0 commit comments

Comments
 (0)