Skip to content

Commit 57b724a

Browse files
Merge #345
345: [PLAT-182] VME enclave runner r=raoulstrackx a=raoulstrackx Initial PR with the Fortanixvme runner and fortanix-vme-abi. It only provides support for outgoing connections. It works together with [this](fortanix/rust#2) standard library. Co-authored-by: Raoul Strackx <[email protected]>
2 parents 6410015 + 6465f81 commit 57b724a

File tree

14 files changed

+729
-45
lines changed

14 files changed

+729
-45
lines changed

Cargo.lock

Lines changed: 145 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[workspace]
22
members = [
3+
"fortanix-vme/fortanix-vme-abi",
4+
"fortanix-vme/fortanix-vme-runner",
5+
"fortanix-vme/tests/outgoing_connection",
36
"intel-sgx/aesm-client",
47
"intel-sgx/dcap-provider",
58
"intel-sgx/dcap-ql-sys",
@@ -8,13 +11,18 @@ members = [
811
"intel-sgx/enclave-runner",
912
"intel-sgx/fortanix-sgx-abi",
1013
"intel-sgx/fortanix-sgx-tools",
11-
"ipc-queue",
1214
"intel-sgx/report-test",
13-
"rs-libc",
1415
"intel-sgx/sgxs",
1516
"intel-sgx/sgx-isa",
1617
"intel-sgx/sgx-pkix",
1718
"intel-sgx/sgxs-loaders",
18-
"intel-sgx/sgxs-tools"
19+
"intel-sgx/sgxs-tools",
20+
"ipc-queue",
21+
"rs-libc",
1922
]
2023
exclude = ["examples"]
24+
25+
[patch.crates-io]
26+
libc = { git = "https://github.com/fortanix/libc.git", branch = "fortanixvme" }
27+
serde = { git = "https://github.com/fortanix/serde.git", branch = "master" }
28+
vsock = { git = "https://github.com/raoulstrackx/vsock-rs.git", branch = "raoul/fortanixvme" }

fortanix-vme/ci-common.sh

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!/bin/bash -ex
2+
repo_root=$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)
3+
4+
function kernel_version {
5+
kernel=$(uname -r)
6+
IFS='.' read -ra kernel <<< "${kernel}"
7+
8+
kernel_major=${kernel[0]}
9+
kernel_minor=${kernel[1]}
10+
}
11+
12+
function has_vsock_loopback {
13+
kernel_version
14+
vsock_loopback=0
15+
if [[ 5 -le ${kernel_major} ]]; then
16+
if [[ 6 -le ${kernel_minor} ]]; then
17+
if [[ $(lsmod | grep vsock_loopback) ]]; then
18+
vsock_loopback=1
19+
else
20+
echo "You have a vsock loopback capable kernel, but the vsock_loopback module isn't loaded. Please run \'sudo modprobe vsock_loopback\'"
21+
exit -1
22+
fi
23+
fi
24+
fi
25+
}
26+
27+
function toolchain_version {
28+
toolchain_version="nightly-2021-09-08-x86_64-unknown-linux-gnu"
29+
}
30+
31+
function has_tools {
32+
if [[ $(which musl-gcc) ]]; then
33+
echo "'musl-gcc' installed correctly"
34+
else
35+
echo "'musl-gcc' isn't found. Please run 'sudo apt install musl-tools'"
36+
exit -1
37+
fi
38+
}
39+
40+
function determine_platform {
41+
if [[ -z "${NITRO_CLI_BLOBS}" ]]; then
42+
platform="linux"
43+
else
44+
platform="nitro"
45+
fi
46+
}
47+
48+
function init {
49+
kernel_version
50+
has_vsock_loopback
51+
toolchain_version
52+
has_tools
53+
determine_platform
54+
}
55+
56+
function compile {
57+
name=$1
58+
VME_TARGET="${TOOLCHAIN_DIR}/rust/rustup/toolchains/${toolchain_version}/lib/rustlib/x86_64-unknown-linux-fortanixvme/x86_64-unknown-linux-fortanixvme.json"
59+
CC=musl-gcc \
60+
RUSTFLAGS="-Clink-self-contained=yes" \
61+
cargo +${toolchain_version} build --locked --release --target ${VME_TARGET} -Zbuild-std
62+
63+
# use elf as an output variable
64+
elf=${repo_root}/target/x86_64-unknown-linux-fortanixvme/release/${name}
65+
}
66+
67+
function cargo_test {
68+
name=$1
69+
pushd ${repo_root}/fortanix-vme/tests/$name
70+
out=$(mktemp /tmp/$name.out.XXXXX)
71+
err=$(mktemp /tmp/$name.err.XXXXX)
72+
73+
if [ -f ./test_interaction.sh ]; then
74+
./test_interaction.sh &
75+
test_interaction=$!
76+
fi
77+
78+
compile ${name}
79+
80+
if [ "${platform}" == "nitro" ]; then
81+
eif=$(mktemp /tmp/$name.eif.XXXXX)
82+
elf2eif ${elf} ${eif}
83+
eif_runner ${eif} ${out} ${err}
84+
nitro-cli terminate-enclave --all
85+
86+
out=$(tail +12 ${out})
87+
err=$(cat ${err} | grep -v "Start.*" || true)
88+
89+
if [ "${out}" != "" ]; then
90+
echo "Test ${name} Failed"
91+
echo "Got: ${out}"
92+
exit -1
93+
fi
94+
95+
if [ "${err}" != "" ]; then
96+
echo "Test ${name} Failed"
97+
echo "Got: ${err}"
98+
exit -1
99+
else
100+
echo "Success"
101+
fi
102+
else
103+
${elf} -- --nocapture
104+
${elf} -- --nocapture > ${out} 2> ${err}
105+
106+
out=$(cat ${out} | grep -v "#" || true)
107+
expected=$(cat ./out.expected)
108+
109+
if [ "${out}" == "${expected}" ]; then
110+
echo "Test ${name}: Success"
111+
else
112+
echo "Test ${name}: Failed"
113+
echo "Got: ${out}"
114+
echo "Expected: ${expected}"
115+
exit -1
116+
fi
117+
fi
118+
119+
if [ -f ./test_interaction.sh ]; then
120+
kill ${test_interaction}
121+
fi
122+
123+
popd
124+
}
125+
126+
function elf2eif {
127+
enclave_elf=$1
128+
enclave_eif=$2
129+
130+
tmpd=$(mktemp -d)
131+
echo "FROM alpine" >> ${tmpd}/Dockerfile
132+
echo "COPY enclave ." >> ${tmpd}/Dockerfile
133+
echo "CMD ./enclave" >> ${tmpd}/Dockerfile
134+
135+
# Build eif image
136+
cp ${enclave_elf} ${tmpd}/enclave
137+
nitro-cli build-enclave --docker-dir ${tmpd} --docker-uri enclave --output-file ${enclave_eif}
138+
}
139+
140+
function stop_enclaves {
141+
if [[ ${nitro_platform} -eq 1 ]]; then
142+
nitro-cli terminate-enclave --all || true
143+
fi
144+
}
145+
146+
function eif_runner {
147+
enclave_eif=$1
148+
out=$2
149+
err=$3
150+
151+
# Configure parent, if it hadn't been already
152+
nitro-cli-config -t 2 -m 512 > /dev/null 2> /dev/null || true
153+
154+
nitro-cli describe-enclaves
155+
156+
echo "running $1"
157+
# Run enclave
158+
nitro-cli run-enclave --eif-path ${enclave_eif} --cpu-count 2 --memory 512 --debug-mode > ${out} 2> ${err}
159+
}
160+
161+
init

fortanix-vme/ci-fortanixvme.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash -ex
2+
repo_root=$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)
3+
cd ${repo_root}/fortanix-vme
4+
5+
source ./ci-common.sh
6+
7+
function cleanup {
8+
stop_runner
9+
}
10+
11+
function setup_environment {
12+
if [[ -z "${TOOLCHAIN_DIR}" ]]; then
13+
echo 'The `TOOLCHAIN_DIR` environment variable isnt set. Make sure to source the `shell/env` script from the toolchain repo'
14+
exit -1
15+
fi
16+
trap cleanup err
17+
trap cleanup exit
18+
cargo +${toolchain_version} --locked clean
19+
}
20+
21+
function start_runner {
22+
pushd fortanix-vme-runner
23+
cargo +${toolchain_version} --locked run &
24+
pid_runner=$!
25+
popd
26+
}
27+
28+
function stop_runner {
29+
if [[ ${pid_runner} -ne 0 ]]; then
30+
echo "Stopping enclave runner"
31+
kill ${pid_runner}
32+
pid_runner=0
33+
fi
34+
}
35+
36+
function run_tests {
37+
tests=$@
38+
39+
setup_environment
40+
41+
if [[ ${vsock_loopback} -eq 1 ]]; then
42+
start_runner
43+
for name in ${tests}
44+
do
45+
cargo_test $name
46+
done
47+
stop_runner
48+
else
49+
echo "vsock loopback device not available, skipping these tests"
50+
fi
51+
}
52+
53+
run_tests outgoing_connection
54+
55+
echo "********************************"
56+
echo "** All tests succeeded! **"
57+
echo "********************************"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "fortanix-vme-abi"
3+
version = "0.1.0"
4+
edition = "2018"
5+
authors = ["Fortanix, Inc."]
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" }
11+
alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" }
12+
compiler_builtins = { version = "0.1.0", optional = true }
13+
# Avoid using patch section due to https://github.com/rust-lang/cargo/issues/10031
14+
serde = { git = "https://github.com/fortanix/serde.git", branch = "master", default-features = false, features = ["derive", "alloc"] }
15+
16+
[features]
17+
default = []
18+
docs = []
19+
rustc-dep-of-std = ["core", "alloc", "compiler_builtins/rustc-dep-of-std", "serde/rustc-dep-of-std"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![no_std]
2+
extern crate alloc;
3+
4+
use alloc::string::String;
5+
use serde::{Deserialize, Serialize};
6+
7+
pub const SERVER_PORT: u32 = 10000;
8+
9+
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
10+
pub enum Request {
11+
Connect {
12+
addr: String,
13+
},
14+
}
15+
16+
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
17+
pub enum Response {
18+
Connected {
19+
proxy_port: u32,
20+
},
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "fortanix-vme-runner"
3+
version = "0.1.0"
4+
edition = "2018"
5+
authors = ["Fortanix, Inc."]
6+
7+
[dependencies]
8+
fortanix-vme-abi = { path = "../fortanix-vme-abi" }
9+
nix = "0.22.1"
10+
serde = { version = "1.0", features = ["derive"] }
11+
serde_cbor = { version = "0.11" }
12+
vsock = "0.2.4"

0 commit comments

Comments
 (0)