Skip to content

Commit 6e967e4

Browse files
Merge #360
360: [PLAT-388] Bugfix `ftxvme-elf2eif` r=Pagten a=raoulstrackx The `ftxvme-elf2eif` used to generate eif files based on the `scratch` Docker image. That is causing problems for Nitro enclaves. Reverted back to the `alpine` image for now. CI has also been modified to facilitate easier testing in the future. Co-authored-by: Raoul Strackx <[email protected]>
2 parents 5124191 + fd9b36c commit 6e967e4

File tree

8 files changed

+68
-15
lines changed

8 files changed

+68
-15
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"fortanix-vme/eif-tools",
44
"fortanix-vme/fortanix-vme-abi",
55
"fortanix-vme/fortanix-vme-runner",
6+
"fortanix-vme/tests/hello_world",
67
"fortanix-vme/tests/outgoing_connection",
78
"fortanix-vme/tests/incoming_connection",
89
"fortanix-vme/tests/iron",

fortanix-vme/ci-common.sh

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ function cargo_test {
7676
fi
7777

7878
compile ${name}
79+
eif=$(mktemp /tmp/$name.eif.XXXXX)
7980

8081
if [ "${platform}" == "nitro" ]; then
81-
eif=$(mktemp /tmp/$name.eif.XXXXX)
8282
elf2eif ${elf} ${eif}
8383
eif_runner ${eif} ${out} ${err}
8484
nitro-cli terminate-enclave --all
@@ -100,6 +100,14 @@ function cargo_test {
100100
echo "Success"
101101
fi
102102
else
103+
if [[ -v AWS_VM ]]; then
104+
elf2eif ${elf} ${eif}
105+
ssh ubuntu@${AWS_VM} "mkdir -p /home/ubuntu/ci-fortanixvme/${name}/"
106+
scp ${enclave_eif} ubuntu@${AWS_VM}:/home/ubuntu/ci-fortanixvme/${name}/
107+
if [ -f ./test_interaction.sh ]; then
108+
scp ./test_interaction.sh ubuntu@${AWS_VM}:/home/ubuntu/ci-fortanixvme/${name}/
109+
fi
110+
fi
103111
RUST_BACKTRACE=full ${elf} -- --nocapture > ${out} 2> ${err}
104112

105113
out=$(cat ${out} | grep -v "#" || true)
@@ -126,14 +134,22 @@ function elf2eif {
126134
enclave_elf=$1
127135
enclave_eif=$2
128136

129-
tmpd=$(mktemp -d)
130-
echo "FROM alpine" >> ${tmpd}/Dockerfile
131-
echo "COPY enclave ." >> ${tmpd}/Dockerfile
132-
echo "CMD ./enclave" >> ${tmpd}/Dockerfile
137+
if [[ -z "${NITRO_RESOURCES}" ]]; then
138+
dir=$(mktemp -d /tmp/aws_cli.XXXXX)
139+
pushd ${dir}
140+
git clone https://github.com/aws/aws-nitro-enclaves-cli.git
141+
resources=${dir}/aws-nitro-enclaves-cli/blobs/x86_64
142+
NITRO_RESOURCES=${resources}
143+
popd
144+
else
145+
resources=${NITRO_RESOURCES}
146+
fi
133147

134-
# Build eif image
135-
cp ${enclave_elf} ${tmpd}/enclave
136-
nitro-cli build-enclave --docker-dir ${tmpd} --docker-uri enclave --output-file ${enclave_eif}
148+
# Newly compiled ftxvme-elf2eif from this repo
149+
pushd ${repo_root}/fortanix-vme
150+
cargo run --bin ftxvme-elf2eif -- --input-file ${enclave_elf} --output-file ${enclave_eif} --resource-path ${resources} --verbose
151+
ls -lh ${enclave_eif}
152+
popd
137153
}
138154

139155
function stop_enclaves {
@@ -156,5 +172,3 @@ function eif_runner {
156172
# Run enclave
157173
nitro-cli run-enclave --eif-path ${enclave_eif} --cpu-count 2 --memory 512 --debug-mode > ${out} 2> ${err}
158174
}
159-
160-
init

fortanix-vme/ci-fortanixvme.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
repo_root=$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)
33
cd ${repo_root}/fortanix-vme
44

5+
# Options:
6+
# AWS_VM: When this environment variable is set, binaries will be sent to this AWS VM
7+
# NITRO_RESOURCES: The location of the nitro resources (e.g., kernel, ...) required for
8+
# the elf2eif tool. When this environment variable isn't set, the
9+
# resources will be downloaded
10+
511
source ./ci-common.sh
12+
init
613

714
function cleanup {
815
stop_runner
@@ -21,7 +28,14 @@ function setup_environment {
2128

2229
function start_runner {
2330
pushd fortanix-vme-runner
31+
cargo +${toolchain_version} --locked build
2432
cargo +${toolchain_version} --locked run &
33+
34+
if [[ -v AWS_VM ]]; then
35+
ssh ubuntu@${AWS_VM} 'mkdir -p /home/ubuntu/ci-fortanixvme'
36+
scp ${repo_root}/target/debug/fortanix-vme-runner ubuntu@${AWS_VM}:/home/ubuntu/ci-fortanixvme
37+
fi
38+
2539
pid_runner=$!
2640
popd
2741
}
@@ -52,9 +66,10 @@ function run_tests {
5266
}
5367

5468
run_tests\
55-
outgoing_connection \
56-
incoming_connection \
57-
iron
69+
hello_world \
70+
outgoing_connection \
71+
incoming_connection \
72+
iron
5873

5974
echo "********************************"
6075
echo "** All tests succeeded! **"

fortanix-vme/eif-tools/src/bin/ftxvme-elf2eif.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn setup_docker_dir(elf_path: &str) -> Result<TempDir> {
1616
const DOCKERFILE: &str = "
1717
FROM scratch
1818
COPY enclave .
19-
CMD ./enclave
19+
CMD [\"./enclave\"]
2020
";
2121
info!("Setting up docker directory");
2222
let docker_dir = TempDir::new("elf2eif_docker_dir")?;
@@ -79,7 +79,7 @@ fn main() {
7979
let mut logger = env_logger::Builder::from_default_env();
8080
let logger = logger.format(|buf, record| writeln!(buf, "{}", record.args()));
8181
if verbose {
82-
logger.filter_level(LevelFilter::Info).init();
82+
logger.filter_level(LevelFilter::Debug).init();
8383
} else {
8484
logger.filter_level(LevelFilter::Error).init();
8585
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "hello_world"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::{thread, time};
2+
3+
fn main() {
4+
for i in 0..30 {
5+
println!("{}: Hello, world!", i);
6+
thread::sleep(time::Duration::from_secs(1));
7+
}
8+
9+
println!("Byte bye!");
10+
}

fortanix-vme/tests/outgoing_connection/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::net::{Ipv4Addr, TcpStream};
22
use std::io::{Read, Write};
33

44
fn main() {
5+
println!("# Running outgoing connection test");
56
let mut socket = TcpStream::connect(format!("google.com:80")).unwrap();
67
// `socket.local_addr()` may return the actual local IP address, not 127.0.0.1
78
assert!(socket.local_addr().unwrap().port() != 80);

0 commit comments

Comments
 (0)