Skip to content

Commit be0be19

Browse files
authored
ci: calculate SGX mr_enclave for notary server in gramine docker (#701)
* calculate SGX mr_enclave for notary server in gramine docker * remove old tee github workflow * attest build result for dev branch builds and releases
1 parent 63bd6ab commit be0be19

File tree

4 files changed

+193
-42
lines changed

4 files changed

+193
-42
lines changed

.github/workflows/ci.yml

+124-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ on:
88
- "[v]?[0-9]+.[0-9]+.[0-9]+*"
99
pull_request:
1010

11+
permissions:
12+
id-token: write
13+
contents: read
14+
attestations: write
15+
1116
env:
1217
CARGO_TERM_COLOR: always
1318
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
@@ -17,7 +22,7 @@ env:
1722
# - https://github.com/privacy-scaling-explorations/mpz/issues/178
1823
# 32 seems to be big enough for the foreseeable future
1924
RAYON_NUM_THREADS: 32
20-
25+
GIT_COMMIT_HASH: ${{ github.event.pull_request.head.sha || github.sha }}
2126
jobs:
2227
fmt:
2328
name: Check formatting
@@ -38,6 +43,7 @@ jobs:
3843

3944
- name: Check formatting
4045
run: cargo +nightly fmt --check --all
46+
4147
build-and-test:
4248
name: Build and test
4349
runs-on: ubuntu-latest
@@ -62,6 +68,7 @@ jobs:
6268

6369
- name: Test
6470
run: cargo test
71+
6572
wasm:
6673
name: Build and Test wasm
6774
runs-on: ubuntu-latest
@@ -136,6 +143,7 @@ jobs:
136143

137144
- name: Run integration tests
138145
run: cargo test --profile tests-integration --workspace --exclude tlsn-tls-client --exclude tlsn-tls-core -- --include-ignored
146+
139147
coverage:
140148
runs-on: ubuntu-latest
141149
env:
@@ -155,4 +163,118 @@ jobs:
155163
with:
156164
token: ${{ secrets.CODECOV_TOKEN }}
157165
files: lcov.info
158-
fail_ci_if_error: true
166+
fail_ci_if_error: true
167+
168+
build-sgx:
169+
runs-on: ubuntu-latest
170+
needs: build-and-test
171+
container:
172+
image: rust:latest
173+
174+
steps:
175+
- name: Checkout repository
176+
uses: actions/checkout@v4
177+
178+
- name: Install Clang
179+
run: |
180+
apt update
181+
apt install -y clang
182+
183+
- name: Use caching
184+
uses: Swatinem/[email protected]
185+
186+
- name: Build Rust Binary
187+
run: |
188+
cargo build --bin notary-server --release --features tee_quote
189+
cp --verbose target/release/notary-server $GITHUB_WORKSPACE
190+
191+
- name: Upload Binary for use in the Gramine Job
192+
uses: actions/upload-artifact@v4
193+
with:
194+
name: notary-server
195+
path: notary-server
196+
if-no-files-found: error
197+
198+
gramine-sgx:
199+
runs-on: ubuntu-latest
200+
needs: build-sgx
201+
environment: tee
202+
container:
203+
image: gramineproject/gramine:latest
204+
205+
steps:
206+
- name: Checkout repository
207+
uses: actions/checkout@v4
208+
209+
- name: Restore SGX signing key from secrets
210+
run: |
211+
mkdir -p "${HOME}/.config/gramine/"
212+
echo "${{ secrets.SGX_SIGNING_KEY }}" > "${HOME}/.config/gramine/enclave-key.pem"
213+
# verify key
214+
openssl rsa -in "${HOME}/.config/gramine/enclave-key.pem" -check -noout
215+
216+
- name: Download notary-server binary from build job
217+
uses: actions/download-artifact@v4
218+
with:
219+
name: notary-server
220+
path: crates/notary/server/tee
221+
222+
- name: Install jq
223+
run: |
224+
apt update
225+
apt install -y jq
226+
227+
- name: Use Gramine to calculate measurements
228+
run: |
229+
cd crates/notary/server/tee
230+
231+
chmod +x notary-server
232+
233+
gramine-manifest \
234+
-Dlog_level=debug \
235+
-Darch_libdir=/lib/x86_64-linux-gnu \
236+
-Dself_exe=notary-server \
237+
notary-server.manifest.template \
238+
notary-server.manifest
239+
240+
gramine-sgx-sign \
241+
--manifest notary-server.manifest \
242+
--output notary-server.manifest.sgx
243+
244+
gramine-sgx-sigstruct-view --verbose --output-format=json notary-server.sig | tee >> notary-server-sigstruct.json
245+
246+
cat notary-server-sigstruct.json
247+
248+
mr_enclave=$(jq -r '.mr_enclave' notary-server-sigstruct.json)
249+
mr_signer=$(jq -r '.mr_signer' notary-server-sigstruct.json)
250+
251+
echo "mrenclave=$mr_enclave" >>"$GITHUB_OUTPUT"
252+
echo "#### sgx mrenclave" | tee >>$GITHUB_STEP_SUMMARY
253+
echo "\`\`\`mr_enclave: ${mr_enclave}\`\`\`" | tee >>$GITHUB_STEP_SUMMARY
254+
echo "\`\`\`mr_signer: ${mr_signer}\`\`\`" | tee >>$GITHUB_STEP_SUMMARY
255+
256+
- name: Upload notary-server and signatures
257+
id: upload-notary-server-sgx
258+
uses: actions/upload-artifact@v4
259+
with:
260+
name: notary-server-sgx.zip
261+
path: |
262+
crates/notary/server/tee/notary-server
263+
crates/notary/server/tee/notary-server-sigstruct.json
264+
crates/notary/server/tee/notary-server.sig
265+
crates/notary/server/tee/notary-server.manifest
266+
crates/notary/server/tee/notary-server.manifest.sgx
267+
crates/notary/server/tee/config
268+
crates/notary/server/tee/notary-server-sgx.md
269+
if-no-files-found: error
270+
271+
- name: Attest Build Provenance
272+
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/dev'
273+
uses: actions/attest-build-provenance@v2
274+
with:
275+
subject-name: notary-server-sgx.zip
276+
subject-digest: sha256:${{ steps.upload-notary-server-sgx.outputs.artifact-digest }}
277+
278+
- uses: geekyeggo/delete-artifact@v5 # Delete notary-server from the build job, It is part of the zipfile with the signature
279+
with:
280+
name: notary-server

.github/workflows/tee-ci.yml

-39
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# TLSNotary Notary Server for Intel SGX
2+
3+
This package contains the **SGX-enabled version of the TLSNotary Notary Server**, built with **Gramine** to run securely on Intel SGX hardware. Follow the instructions below to install dependencies, verify the integrity of the enclave, and launch the server.
4+
5+
## Install Intel SGX Drivers & Runtime Dependencies
6+
7+
Ensure your system has the required Intel SGX components installed.
8+
9+
```sh
10+
wget https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key
11+
cat intel-sgx-deb.key | sudo tee /etc/apt/keyrings/intel-sgx-keyring.asc > /dev/null
12+
13+
# Add the repository to your sources:
14+
echo 'deb [signed-by=/etc/apt/keyrings/intel-sgx-keyring.asc arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu noble main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list
15+
16+
sudo apt-get update
17+
sudo apt-get install libsgx-epid libsgx-quote-ex libsgx-dcap-ql -y
18+
```
19+
20+
For more details, refer to the official **[Intel SGX Installation Guide](https://download.01.org/intel-sgx/latest/dcap-latest/linux/docs/Intel_SGX_SW_Installation_Guide_for_Linux.pdf).**
21+
22+
## Verify the Enclave Signature (`MR_ENCLAVE`, `MR_SIGNER`)
23+
24+
Before running the Notary Server, verify that the provided **enclave signature (`.sig`)** matches the expected **`MR_ENCLAVE` and `MR_SIGNER`** values.
25+
26+
Run the following command inside a **Gramine Docker container** to inspect the enclave's signature:
27+
28+
```sh
29+
docker run --rm -v "$(pwd):/work" -w /work gramineproject/gramine:latest \
30+
"gramine-sgx-sigstruct-view --verbose --output-format=json notary-server.sig"
31+
```
32+
33+
The output should be the same as `notary-server-sigstruct.json`
34+
35+
## Run the Notary Server in SGX
36+
37+
Once verification is complete, you can start the Notary Server inside a **Gramine-protected SGX enclave**.
38+
39+
```sh
40+
docker run --detach \
41+
--restart=unless-stopped \
42+
--device=/dev/sgx_enclave \
43+
--device=/dev/sgx_provision \
44+
--volume=/var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket \
45+
--publish=7047:7047 \
46+
--volume="$(pwd):/work" \
47+
--workdir=/work \
48+
gramineproject/gramine:latest \
49+
"gramine-sgx notary-server"
50+
```
51+
52+
Notes:
53+
- `--device /dev/sgx_enclave --device /dev/sgx_provision` → Exposes SGX devices.
54+
- `--volume=/var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket` → Enables access to **Intel's AESM daemon** (required for remote attestation).
55+
- `-p 7047:7047` → Exposes the notary server on port **7047**.
56+
57+
## Attestation & Verification
58+
59+
The Notary Server runs inside an **Intel SGX enclave**, which supports **remote attestation**. When connecting to it, clients should request an **SGX quote** to verify:
60+
61+
- **MR_ENCLAVE** (ensures the correct enclave binary is running).
62+
- **MR_SIGNER** (ensures the enclave was signed by the expected key).
63+
- **Quote Freshness** (prevents replay attacks).
64+
65+
To retrieve the SGX attestation quote, navigate to `<your notary server>:7047/info`:
66+
```
67+
curl localhost:7047/info | jq
68+
```

crates/notary/server/tee/notary-server.manifest.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ sys.disallow_subprocesses = true
4242
#### tlsn rev
4343
sgx.isvprodid = 7
4444
#### F
45-
sgx.isvsvn = 46
45+
sgx.isvsvn = 1

0 commit comments

Comments
 (0)