Skip to content

Commit f026db3

Browse files
committed
fix(scripts): fix and refactor setup scripts
1 parent 1e7bd4c commit f026db3

File tree

6 files changed

+40
-24
lines changed

6 files changed

+40
-24
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
.DS_Store
22

3+
AWS_NitroEnclaves_Root-G1.zip
4+
root.pem
5+
36
target/
47
debug/

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL := /bin/bash
22

3-
.PHONY: help setup-docker setup-nitro-cli setup-client build-enclave build-proxy build-client run-enclave run-proxy run-client terminate-enclave
3+
.PHONY: help setup-docker setup-nitro-cli setup-client download-root-ca build-enclave build-proxy build-client run-enclave run-proxy run-client terminate-enclave
44

55
ENCLAVE_CID ?= 16
66
ENCLAVE_MEMORY ?= 512
@@ -13,16 +13,17 @@ help:
1313
@echo "Targets:"
1414
@echo " help Show this help message"
1515
@echo " For Parent VM:"
16-
@echo " setup-docker Install Docker (requires Ubuntu + sudo) for Parent VM"
17-
@echo " setup-nitro-cli Install Nitro Enclaves Driver and CLI for Parent VM"
16+
@echo " setup-docker Install Docker (requires Ubuntu + sudo)"
17+
@echo " setup-nitro-cli Install Nitro Enclaves Driver and CLI"
1818
@echo " build-enclave Build enclave Docker image and create EIF file"
1919
@echo " build-proxy Build vsock proxy"
2020
@echo " run-enclave Run Nitro Enclave"
2121
@echo " run-proxy Run vsock proxy"
2222
@echo " terminate-enclave Terminate Nitro Enclave"
2323
@echo " For Client:"
24-
@echo " setup-client Install Rust and AWS Nitro Enclaves root certificate"
24+
@echo " setup-client Install Rust and dependencies"
2525
@echo " build-client Build client application"
26+
@echo " download-root-ca Download AWS Nitro Enclaves root CA certificate"
2627
@echo " run-client Run client"
2728

2829
setup-docker:
@@ -37,6 +38,10 @@ setup-client:
3738
@echo "Running scripts/setup-client.sh"
3839
@bash ./scripts/setup-client.sh
3940

41+
download-root-ca:
42+
@echo "Running scripts/download-root-ca.sh"
43+
@bash ./scripts/download-root-ca.sh
44+
4045
build-enclave:
4146
@echo "Building Docker image"
4247
@docker build -t rafwne-enclave ./enclave

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ This repository demonstrates a simple end-to-end flow against an AWS Nitro Encla
2020
- **Kernel**: 6.14.0-1018-aws
2121
- **Nitro Enclaves**: Enabled
2222
- **Nitro Enclaves CLI / driver**: v1.4.4
23-
- **Rust toolchain**: v1.90.0
2423

2524
### Enclave
2625

2726
- **OS**: Ubuntu 24.04
2827
- **Allocated vCPUs**: 2
2928
- **Allocated Memory**: 512 MiB
3029
- **OS**: Ubuntu 24.04
31-
- **Rust toolchain**: v1.90.0
3230

3331
### Client
3432

@@ -40,7 +38,7 @@ This repository demonstrates a simple end-to-end flow against an AWS Nitro Encla
4038
- `proxy/`: **untrusted** HTTP → vsock proxy (listens on HTTP `ip:port`, forwards to vsock `port=5000`)
4139
- `client/`: Client app (POSTs JSON to the proxy, verifies attestation, then calls the confidential computing API)
4240

43-
## Quick start (all on the Parent VM)
41+
## Quick start
4442

4543
Clone the repository:
4644

@@ -49,17 +47,18 @@ git clone <THIS_REPOSITORY>
4947
cd <THIS_REPOSITORY>
5048
```
5149

52-
### 1. Parent VM setup (Ubuntu 24.04)
50+
### 1. Parent VM setup
5351

5452
```bash
5553
make setup-docker
5654
make setup-nitro-cli
5755
```
5856

59-
### 2. Client setup (this README runs it on the Parent VM)
57+
### 2. Client setup
6058

6159
```bash
6260
make setup-client
61+
make download-root-ca
6362
```
6463

6564
### 3. Build the Enclave image and copy PCRs into `client-configs.json`

scripts/download-root-ca.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Download AWS Nitro Enclaves root certificate
6+
AWS_CA_ZIP_FILE="AWS_NitroEnclaves_Root-G1.zip"
7+
curl -fsSL https://aws-nitro-enclaves.amazonaws.com/"$AWS_CA_ZIP_FILE" -o "$AWS_CA_ZIP_FILE"
8+
9+
# Extract the first *.pem found inside the zip directly to ./root.pem
10+
CA_PEM_PATH="$(unzip -Z1 "$AWS_CA_ZIP_FILE" | grep -Ei '\.pem$' | head -n1)"
11+
if [ -z "$CA_PEM_PATH" ]; then
12+
echo "ERROR: no .pem file found inside $AWS_CA_ZIP_FILE" >&2
13+
unzip -Z1 "$AWS_CA_ZIP_FILE" >&2 || true
14+
exit 1
15+
fi
16+
unzip -p "$AWS_CA_ZIP_FILE" "$CA_PEM_PATH" > ./root.pem
17+
chmod +r ./root.pem
18+
rm -f "$AWS_CA_ZIP_FILE"

scripts/setup-client.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,4 @@ sudo apt-get install -y build-essential pkg-config libssl-dev git unzip
88

99
# Install Rust
1010
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
11-
source $HOME/.cargo/env
12-
13-
# Download AWS Nitro Enclaves root certificate
14-
curl https://aws-nitro-enclaves.amazonaws.com/AWS_NitroEnclaves_Root-G1.zip -o AWS_NitroEnclaves_Root-G1.zip
15-
unzip -o AWS_NitroEnclaves_Root-G1.zip -d .
16-
rm AWS_NitroEnclaves_Root-G1.zip
17-
18-
# Make a stable filename expected by the Rust client (`root.pem`).
19-
#./*.pem => root.pem
20-
ls -la ./root.pem || cp ./*.pem root.pem
11+
source "$HOME/.cargo/env"

scripts/setup-nitro-cli.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
set -e
44

5-
USERNAME="$(whoami)"
65
KERNEL_VERSION="$(uname -r)"
76

87
# Install dependencies
@@ -11,7 +10,7 @@ sudo apt-get install -y build-essential git clang libclang-dev llvm-dev linux-mo
1110

1211
# Install Rust
1312
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
14-
source $HOME/.cargo/env
13+
source "$HOME/.cargo/env"
1514

1615
# Install Nitro Enclaves driver and CLI
1716
git clone https://github.com/aws/aws-nitro-enclaves-cli -b v1.4.4
@@ -29,9 +28,10 @@ pushd aws-nitro-enclaves-cli
2928
sudo make nitro-cli
3029
sudo make vsock-proxy
3130
sudo make NITRO_CLI_INSTALL_DIR=/ install
32-
source ./build/install/etc/profile.d/nitro-cli-env.sh
33-
echo source ./build/install/etc/profile.d/nitro-cli-env.sh >> ~/.bashrc
34-
./build/install/etc/profile.d/nitro-cli-config -i
31+
source /etc/profile.d/nitro-cli-env.sh
32+
grep -qF 'source /etc/profile.d/nitro-cli-env.sh' "$HOME/.bashrc" \
33+
|| (echo source /etc/profile.d/nitro-cli-env.sh >> "$HOME/.bashrc" && source "$HOME/.bashrc")
34+
nitro-cli-config -i
3535
popd
3636

3737
# Start and enable the Nitro Enclaves Allocator Service

0 commit comments

Comments
 (0)