Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

Gramine Integartion with Avalon #775

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions docker/compose/avalon-fib-gsgx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@ services:
graphene-python-workload:
image: gsc-avalon-fibonacci-workload-dev
devices:
- "/dev/gsgx:/dev/gsgx"
- "/dev/isgx:/dev/isgx"
volumes:
- /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket
- "/dev/sgx_enclave:/dev/sgx_enclave"
3 changes: 2 additions & 1 deletion docs/graphene-workload-tutorial/create_workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
os.path.join("src","my_workload.py.template"),
os.path.join("tests","test_work_orders.json.template"),
"workload.json.template",
"Makefile.template"
"Makefile.template",
"setup.py.template"
}

IN_DIR = "workload"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@ services:
graphene-python-workload:
image: gsc-avalon-{{ my_workload }}-workload-dev
devices:
- "/dev/gsgx:/dev/gsgx"
- "/dev/isgx:/dev/isgx"
volumes:
- /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket
- "/dev/sgx_enclave:/dev/sgx_enclave"
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@ services:
process-work-order:
image: gsc-avalon-{{ my_workload }}-workload-dev
devices:
- "/dev/gsgx:/dev/gsgx"
- "/dev/isgx:/dev/isgx"
volumes:
- /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket
- "/dev/sgx_enclave:/dev/sgx_enclave"
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,13 @@ if [ "$GSC_IMAGE_EXISTS" = "yes" ]; then
fi

# Manifest files
MANIFEST_FILE_DIR="${TCF_HOME}/tc/graphene/python_worker/graphene_sgx/manifest"
MANIFEST_FILES="python.manifest
sh.manifest
gcc.manifest
collect2.manifest
ld.manifest"
# Generate list of manifest files
LIST_MANIFEST_FILES=""
for f in $MANIFEST_FILES
do
FILE_NAME=${MANIFEST_FILE_DIR}/$f
if [ ! -f $FILE_NAME ]; then
echo "ERROR:Manifest file $FILE_NAME doesn't exist"
exit
fi
LIST_MANIFEST_FILES+=${MANIFEST_FILE_DIR}/$f
LIST_MANIFEST_FILES+=" "
done
echo $LIST_MANIFEST_FILES

MANIFEST_FILE="${TCF_HOME}tc/graphene/python_worker/graphene_sgx/manifest/avalon.manifest"
echo $MANIFEST_FILE
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to print manifest filename? You could remove if added for debugging.

Copy link
Author

Choose a reason for hiding this comment

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

Added for debugging purpose, removed now


# Build image
echo "Build unsigned GSC image"
./gsc build --insecure-args $IMAGE_NAME $LIST_MANIFEST_FILES
sudo ./gsc build --insecure-args $IMAGE_NAME $MANIFEST_FILE
Copy link
Contributor

Choose a reason for hiding this comment

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

Why sudo needed here? gsc binary should run with user permission itself.

Copy link
Author

Choose a reason for hiding this comment

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

yes, sudo is not required. gsc runs with user permission, tested with gramine production release.

Removed sudo, in all the gsc build scripts


# Generate signing key if it doesn't exists
SIGN_KEY_FILE=enclave-key.pem
Expand All @@ -70,4 +54,7 @@ fi

# Sign image to generate final GSC image
echo "Generate Signed GSC image"
./gsc sign-image $IMAGE_NAME $SIGN_KEY_FILE
sudo ./gsc sign-image $IMAGE_NAME $SIGN_KEY_FILE

# Retrieve SGX-related information from graphenized image using gsc info-image
# sudo ./gsc info-image $IMAGE_NAME
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove commented lines.

Copy link
Author

Choose a reason for hiding this comment

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

Removed

34 changes: 34 additions & 0 deletions docs/graphene-workload-tutorial/workload/setup.py.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python

# Copyright 2020 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

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

change copyright to 2021

Copy link
Author

Choose a reason for hiding this comment

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

Updated the copyright to 2021

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

# This should only be run with python3
if sys.version_info[0] < 3:
print('ERROR: must run with python3')
sys.exit(1)

from setuptools import setup, find_packages

setup(name='avalon_python_{{ my_workload }}_workload',
version=0.6,
description='Avalon python workload for Graphene',
author='Hyperledger Avalon',
url='https://github.com/hyperledger/avalon',
packages=find_packages(),
data_files=[],
entry_points={}
)
2 changes: 1 addition & 1 deletion enclave_manager/Dockerfile-graphene
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ COPY ./enclave_manager/Makefile-graphene /project/avalon/enclave_manager/
COPY ./enclave_manager/avalon_enclave_manager/*.py /project/avalon/enclave_manager/avalon_enclave_manager/
COPY ./enclave_manager/avalon_enclave_manager/${ENCLAVE_TYPE} /project/avalon/enclave_manager/avalon_enclave_manager/${ENCLAVE_TYPE}
COPY ./enclave_manager/avalon_enclave_manager/wpe_common /project/avalon/enclave_manager/avalon_enclave_manager/wpe_common
COPY ./wpe_mr_enclave.txt /project/avalon/
# COPY ./wpe_mr_enclave.txt /project/avalon/
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the line

Copy link
Author

Choose a reason for hiding this comment

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

Removed



WORKDIR /project/avalon/enclave_manager
Expand Down
1 change: 0 additions & 1 deletion examples/graphene_apps/python_workloads/fibonacci/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ build :
install:
@echo INSTALLING WHEEL FILE =================
pip3 install $(WHEEL_FILE)

clean:
if pip3 uninstall --yes $(WHEEL_FILE); then echo UNINSTALLED $(WHEEL_FILE) WHEEL FILE ; fi
rm -rf build deps dist *.egg-info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ https://creativecommons.org/licenses/by/4.0/

- To run fibonacci workload as a docker container in Graphene-SGX environment and to use a test application to send work order requests, execute the following command from [fibonacci](https://github.com/hyperledger/avalon/tree/master/examples/graphene_apps/python_workloads/fibonacci) directory.

`docker-compose -f docker-compose.yaml -f compose/graphene-sgx.yaml up`
`docker-compose -f docker-compose.yaml -f compose/graphene-wpe-sgx.yaml up`

Above command will run test work orders listed in file [*test_fib_work_orders.json*](http://github.com/hyperledger/avalon/tree/master/examples/graphene_apps/python_workloads/fibonacci/tests/test_fib_work_orders.json).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

# Avalon python worker docker image name.
IMAGE_NAME=avalon-fibonacci-workload-dev
echo "Building GSC image $IMAGE_NAME started"
# Graphenized docker image name for python worker.
GSC_IMAGE_NAME=gsc-$IMAGE_NAME

Expand All @@ -38,29 +39,13 @@ if [ "$GSC_IMAGE_EXISTS" = "yes" ]; then
fi

# Manifest files
MANIFEST_FILE_DIR="${TCF_HOME}/tc/graphene/python_worker/graphene_sgx/manifest"
MANIFEST_FILES="python.manifest
sh.manifest
gcc.manifest
collect2.manifest
ld.manifest"
# Generate list of manifest files
LIST_MANIFEST_FILES=""
for f in $MANIFEST_FILES
do
FILE_NAME=${MANIFEST_FILE_DIR}/$f
if [ ! -f $FILE_NAME ]; then
echo "ERROR:Manifest file $FILE_NAME doesn't exist"
exit
fi
LIST_MANIFEST_FILES+=${MANIFEST_FILE_DIR}/$f
LIST_MANIFEST_FILES+=" "
done
echo $LIST_MANIFEST_FILES

MANIFEST_FILE="./avalon.manifest" #"${TCF_HOME}tc/graphene/python_worker/graphene_sgx/manifest/python.manifest"
Copy link
Contributor

Choose a reason for hiding this comment

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

its better to address file with absolute path than relative path, it leads to bugs if run from different paths

Copy link
Author

Choose a reason for hiding this comment

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

Addressed the file with absolute path.

echo $MANIFEST_FILE

# Build image
echo "Build unsigned GSC image"
./gsc build --insecure-args $IMAGE_NAME $LIST_MANIFEST_FILES
sudo ./gsc build --insecure-args $IMAGE_NAME $MANIFEST_FILE
Copy link
Contributor

Choose a reason for hiding this comment

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

remove sudo here and everywhere


# Generate signing key if it doesn't exists
SIGN_KEY_FILE=enclave-key.pem
Expand All @@ -70,13 +55,7 @@ fi

# Sign image to generate final GSC image
echo "Generate Signed GSC image"
./gsc sign-image $IMAGE_NAME $SIGN_KEY_FILE

# Extract enclave info from GSC image
./gsc info-image $GSC_IMAGE_NAME > gsc-info.toml

# Extract mrenclave corresponding to python and persist to file
python3 $TCF_HOME/scripts/mr_enclave.py
sudo ./gsc sign-image $IMAGE_NAME $SIGN_KEY_FILE

# Move MRENCLAVE file to TCF_HOME
mv wpe_mr_enclave.txt $TCF_HOME
# Retrieve SGX-related information from graphenized image using gsc info-image
# sudo ./gsc info-image $IMAGE_NAME
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def execute(self, in_data_array):
logger.error(out_msg)
result = False
return result, out_msg_bytes

# -------------------------------------------------------------------------

def _fibonacci(self, n):
Expand Down
5 changes: 1 addition & 4 deletions tc/graphene/python_worker/compose/graphene-sgx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@ services:
process-work-order:
image: gsc-avalon-python-worker-dev
devices:
- "/dev/gsgx:/dev/gsgx"
- "/dev/isgx:/dev/isgx"
volumes:
- /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket
- "dev/sgx_enclave:/dev/sgx_enclave"
26 changes: 26 additions & 0 deletions tc/graphene/python_worker/graphene_sgx/manifest/avalon.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sgx.enclave_size = "256M" # Minimum enclave size, can be increased based on the requirements
sgx.thread_num = 8
sgx.allow_file_creation = 1
sgx.file_check_policy = "allow_all_but_log"


# the below files may differ from Docker container to Docker container, so they are marked as
# allowed (this may be insecure if untrusted host maliciously modified these files!)
# sgx.allowed_files.etchostname = "file:/etc/hostname"
# sgx.allowed_files.etchosts = "file:/etc/hosts"
# sgx.allowed_files.etcresolv = "file:/etc/resolv.conf"

# Below are the required files to be allowed for "Gramine Integration with Avalon"
sgx.allowed_files = [
"file:/usr/local/lib/python3.9/",
"file:/home/python_worker/bash", # for getdents test
"file:/etc/hostname",
"file:/etc/hosts",
"file:/etc/resolv.conf",
"file:/root/.python_history-00001.tmp",
"file:/tmp"
]

# To enable eventfd() for using libzmq system calls, which is disable in Graphene by default.
sys.insecure__allow_eventfd = true