Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notary Server SGX Attestation Template #492

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

maceip
Copy link
Collaborator

@maceip maceip commented Jun 5, 2024

sgx attestation

this pr adds two files to the notary-server:
  1. a gramine manifest template

    • this manifest details needed files, mounts, and other hardware required by the enclave; it sets the entrypoint to be executed when the enclave boots, and other gramine specific security / policy settings
  2. a Makefile

    • a convenience file to preprocess the manifest template, and runs our binary in SGX, or if there is no SGX hardware, uses gramine-direct for testing / verification.

this PR sets the stage for SGX specific concepts and scaffolding before we deploy on SGX hardware

The SGX Report

The SGX report contains a few values, one of which is MR_ENCLAVE.

This PR also adds a push-hook that generates a new SGX report for that commit, and modifies the project's README.md with the updated SGX Report:

auto-report

How To Create an SGX Report without SGX:

steps to test this out (gramine is a pain to build on macos, use a *nix:

  1. install gramine; for ubuntu it's (copypasta this whole block):

    • sudo curl -fsSLo /usr/share/keyrings/gramine-keyring.gpg https://packages.gramineproject.io/gramine-keyring.gpg
      echo "deb [arch=amd64 signed-by=/usr/share/keyrings/gramine-keyring.gpg] https://packages.gramineproject.io/ $(lsb_release -sc) main" \
      | sudo tee /etc/apt/sources.list.d/gramine.list
      sudo curl -fsSLo /usr/share/keyrings/intel-sgx-deb.asc https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key
      echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-sgx-deb.asc] https://download.01.org/intel-sgx/sgx_repo/ubuntu $(lsb_release -sc) main" \
      | sudo tee /etc/apt/sources.list.d/intel-sgx.list
      
      sudo apt-get update
      sudo apt-get install gramine
      
  2. ensure you have the tlsn deps

  3. make

  4. gramine-sgx-gen-private-key

  5. gramine-sgx-sign -v --manifest notary-server.manifest --output notary-server.sgx

  6. gramine-sgx-sigstruct-view notary-server.sig

if all went well you should see something like the following:

Attributes:
    mr_signer: 9a03bd7cd0172e7d04dc886d2f01405b9fb28a02fd08b9e388a387176c5a1edb
    mr_enclave: e9ee7d2d63f95d5cd426e57d20b1e7120a2657af2f45a50879a8e51e0bf5ac07
    isv_prod_id: 0
    isv_svn: 0
    debug_enclave: False
  • the mr_enclave value is the thing we care about: it won't change unless you change the notary server & it's deps.
  1. if you want to test notary-server, spawned inside libOS on a machine without SGX, you can invoke it like so:
  2. make start-gramine-server
  • or if you do have SGX, you would run it like so: SGX=1 make start-gramine-server
*.sig, *.manifest$, and *.sgx need to get added to .gitignore

@sinui0
Copy link
Member

sinui0 commented Jun 5, 2024

Let's open a tee branch and merge related work into there until we're ready to release

@maceip
Copy link
Collaborator Author

maceip commented Jun 6, 2024

Let's open a tee branch and merge related work into there until we're ready to release

sgtm; i tried but i get a:

remote: Permission to tlsnotary/tlsn.git denied to maceip.

…ement

feat: push hook action to generate a gramine sig for notary-server, add output to readme
Copy link
Member

@heeckhau heeckhau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. See comments

.gitignore Outdated Show resolved Hide resolved
Comment on lines 15 to 16
with:
ref: ${{ github.ref }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this is the default

Suggested change
with:
ref: ${{ github.ref }}

.github/workflows/sgx-report.yml Outdated Show resolved Hide resolved
.github/workflows/sgx-report.yml Outdated Show resolved Hide resolved
.github/workflows/sgx-report.yml Outdated Show resolved Hide resolved
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: rustc cargo gramine cmake clang gramine
version: 1.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this version here?

.github/workflows/sgx-report.yml Outdated Show resolved Hide resolved
.github/workflows/sgx-report.yml Outdated Show resolved Hide resolved
.github/workflows/sgx-report.yml Outdated Show resolved Hide resolved
run: |
echo "GITHUB_ENV: $GITHUB_ENV"
echo "SGX_REPORT: $SGX_REPORT"
- name: update README
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid changing the readme and regex magic, If write the report to a file, add and commit it.
The README file can link to this file.
Similar to what projects to with checksum files.
What do you think?

I'll postpone reviewing the README file until we make a decision here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now it creates and uploads a signed-by github artifact

README.md Outdated Show resolved Hide resolved
notary-server/Makefile Outdated Show resolved Hide resolved
Copy link
Member

@yuroitaki yuroitaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! got a few minor comments :)

@maceip
Copy link
Collaborator Author

maceip commented Jun 29, 2024

will address comments above;

  • attestation artifacts attested by github:

Screenshot_20240628-223454

on:
create:
branches:
- 'release/*'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for releases, we don't use release/* naming; but just tags, like https://github.com/tlsnotary/tlsn/blob/main/.github/workflows/ci.yml#L7-L8


jobs:
create-gramine-attestation:
uses: maceip/tlsn/.github/workflows/gramine-report.yml@sgx-attest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shouldn't be maceip's here right?

@@ -134,3 +134,8 @@ Axum is chosen as the framework to serve HTTP and WebSocket requests from the pr

#### WebSocket
Axum's internal implementation of WebSocket uses [tokio_tungstenite](https://docs.rs/tokio-tungstenite/latest/tokio_tungstenite/), which provides a WebSocket struct that doesn't implement [AsyncRead](https://docs.rs/futures/latest/futures/io/trait.AsyncRead.html) and [AsyncWrite](https://docs.rs/futures/latest/futures/io/trait.AsyncWrite.html). Both these traits are required by the TLSN core libraries for the prover and the notary. To overcome this, a [slight modification](./src/service/axum_websocket.rs) of Axum's implementation of WebSocket is used, where [async_tungstenite](https://docs.rs/async-tungstenite/latest/async_tungstenite/) is used instead so that [ws_stream_tungstenite](https://docs.rs/ws_stream_tungstenite/latest/ws_stream_tungstenite/index.html) can be used to wrap on top of the WebSocket struct to get AsyncRead and AsyncWrite implemented.

## Reproduciple Builds & Attestation
- We are using [Gramine](https://github.com/gramineproject) to generate SGX reports for notary-server;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- We are using [Gramine](https://github.com/gramineproject) to generate SGX reports for notary-server;
- We are using [Gramine](https://github.com/gramineproject) to generate SGX reports for notary-server.

@@ -134,3 +134,8 @@ Axum is chosen as the framework to serve HTTP and WebSocket requests from the pr

#### WebSocket
Axum's internal implementation of WebSocket uses [tokio_tungstenite](https://docs.rs/tokio-tungstenite/latest/tokio_tungstenite/), which provides a WebSocket struct that doesn't implement [AsyncRead](https://docs.rs/futures/latest/futures/io/trait.AsyncRead.html) and [AsyncWrite](https://docs.rs/futures/latest/futures/io/trait.AsyncWrite.html). Both these traits are required by the TLSN core libraries for the prover and the notary. To overcome this, a [slight modification](./src/service/axum_websocket.rs) of Axum's implementation of WebSocket is used, where [async_tungstenite](https://docs.rs/async-tungstenite/latest/async_tungstenite/) is used instead so that [ws_stream_tungstenite](https://docs.rs/ws_stream_tungstenite/latest/ws_stream_tungstenite/index.html) can be used to wrap on top of the WebSocket struct to get AsyncRead and AsyncWrite implemented.

## Reproduciple Builds & Attestation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Reproduciple Builds & Attestation
## Reproducible Builds & Attestation

## Reproduciple Builds & Attestation
- We are using [Gramine](https://github.com/gramineproject) to generate SGX reports for notary-server;
- Each release of tlsn will include a build artifact attested by github, which includes the gramine signature.
- if you build and run the notary-server with gramine, you should get the same mr_enclave hash as in our release artifact.
Copy link
Member

@yuroitaki yuroitaki Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- if you build and run the notary-server with gramine, you should get the same mr_enclave hash as in our release artifact.
- If you build and run the notary-server with gramine, you should get the same `mr_enclave` hash as in our release artifact.

execute_install_scripts: true
- name: Set PATH
run: echo "export PATH=\$PATH:/usr/local/bin:/usr/bin" >> $GITHUB_ENV
- name: generate manifest and sig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we not need to cd into notary/server first?

name: generate a gramine signature, which can be verified later

on:
workflow_call:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason why we making this modular to be called from another workflow, instead of everything in one workflow file?


ARCH_LIBDIR ?= /lib/$(shell $(CC) -dumpmachine)

SELF_EXE = target/release/notary-server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the target/release/notary-server file is actually located in the parent folder: notary/target/release, instead of notary/server/target/release — will this affect anything?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the latest repo reorg has shifted the target folder to the top level of the repo

Copy link
Member

@yuroitaki yuroitaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stufff! BTW SO SORRY EVERYONE haha i didn't realise each of my previous comments was an independent review that might end up spamming everyone's inbox :(


# Note that we're compiling in release mode regardless of the DEBUG setting passed
# to Make, as compiling in debug mode results in an order of magnitude's difference in
# performance that makes testing by running a benchmark with ab painful. The primary goal
Copy link
Member

@yuroitaki yuroitaki Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: does ab here mean ab testing?

$(GRAMINE) notary-server
.PHONY: clean
clean:
$(RM) -rf *.token *.sig *.manifest.sgx *.manifest result-* OUTPUT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: does this command run in notary/server directory? or somewhere else?

{ uri = "file:fixture/notary/notary.key" },
{ uri = "file:fixture/notary/notary.pub" },
{ uri = "file:fixture/auth/whitelist.csv" },
{ uri = "file:fixture/tls/notary.crt" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't tls/notary.key also need to be included since it's the TLS key?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tls/notary.key not needed anymore as hosted notary server doesnt use it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same goes for whitelist.csv and notary.crt; though for config.yaml, notary.key and notary.pub — we need to make sure they are the same files used by the hosted notary server

{ uri = "file:fixture/notary/notary.key" },
{ uri = "file:fixture/notary/notary.pub" },
{ uri = "file:fixture/auth/whitelist.csv" },
{ uri = "file:fixture/tls/notary.crt" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tls/notary.key not needed anymore as hosted notary server doesnt use it

{ uri = "file:fixture/notary/notary.key" },
{ uri = "file:fixture/notary/notary.pub" },
{ uri = "file:fixture/auth/whitelist.csv" },
{ uri = "file:fixture/tls/notary.crt" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same goes for whitelist.csv and notary.crt; though for config.yaml, notary.key and notary.pub — we need to make sure they are the same files used by the hosted notary server

edmm_enable = true

allowed_files = [
"file:fixture/tls",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont need this anymore probably? since hosted notary server don't use it


ARCH_LIBDIR ?= /lib/$(shell $(CC) -dumpmachine)

SELF_EXE = target/release/notary-server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the latest repo reorg has shifted the target folder to the top level of the repo

mounts = [
{ path = "/lib", uri = "file:{{ gramine.runtimedir() }}" },
{ path = "{{ arch_libdir }}", uri = "file:{{ arch_libdir }}" },
{ path = "/fixture", uri = "file:fixture" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont need this anymore probably? since hosted notary server don't use it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants