Skip to content

Commit 2d57d8d

Browse files
RodgerZhuHsy-Intelbillionairiam
authored
Enable PSI with Anolis (#161)
* Add support for Ubuntu 20.04 and gramine v1.2 * Update dockerfiles in common folder * Update image * Enable psi in anolisos (#135) * enable psi in anolisos * fixup! enable psi in anolisos * fixup! enable psi in anolisos Co-authored-by: Hsy-Intel <siyuan.hui@intel.com> Co-authored-by: Liang Ma <liang3.ma@intel.com>
1 parent c5b6e7b commit 2d57d8d

File tree

16 files changed

+313
-108
lines changed

16 files changed

+313
-108
lines changed

cczoo/common/docker/gramine/build_docker_image.sh

100755100644
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#!/bin/bash
1717
set -e
1818

19-
if [ -n "$1" ] ; then
19+
if [ "$1" == "anolisos" ] ; then
2020
base_image=$1
2121
else
2222
base_image=ubuntu:20.04
23+
2324
fi
2425

2526
if [ -n "$2" ] ; then
@@ -34,14 +35,25 @@ proxy_server="" # your http proxy server
3435

3536
cd `dirname $0`
3637

38+
if [ ${base_image} == "anolisos" ] ; then
39+
DOCKER_BUILDKIT=0 docker build \
40+
--build-arg no_proxy=${no_proxy} \
41+
--build-arg http_proxy=${proxy_server} \
42+
--build-arg https_proxy=${proxy_server} \
43+
--build-arg base_image=${base_image} \
44+
--build-arg BASE_IMAGE=${base_image} \
45+
-f gramine-sgx-dev:v1.2-anolisos.dockerfile \
46+
-t gramine-sgx-dev:v1.2-anolisos \
47+
.
48+
else
3749
DOCKER_BUILDKIT=0 docker build \
3850
--build-arg no_proxy=${no_proxy} \
3951
--build-arg http_proxy=${proxy_server} \
4052
--build-arg https_proxy=${proxy_server} \
4153
--build-arg base_image=${base_image} \
4254
--build-arg BASE_IMAGE=${base_image} \
4355
-f gramine-sgx-dev.dockerfile \
44-
-t ${image_tag} \
56+
-t gramine-sgx-dev:v1.2-ubuntu20.04-latest \
4557
.
46-
58+
fi
4759
cd -

cczoo/common/docker/gramine/gramine-sgx-dev.dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ ENV ISGX_DRIVER_PATH=${GRAMINEDIR}/driver
7777
ENV WERROR=1
7878
ENV SGX=1
7979

80+
8081
RUN apt-get update && apt-get install -y bison gawk nasm python3-click python3-jinja2 ninja-build pkg-config \
8182
libcurl4-openssl-dev libprotobuf-c-dev python3-protobuf protobuf-c-compiler \
8283
libgmp-dev libmpfr-dev libmpc-dev libisl-dev
8384

8485
RUN pip3 install --upgrade pip \
86+
8587
&& pip3 install 'meson>=0.56' 'toml>=0.10' cryptography
8688

8789
#todo: use github gramine
@@ -137,6 +139,10 @@ RUN gramine-sgx-gen-private-key
137139

138140
COPY configs /
139141

142+
RUN gramine-sgx-gen-private-key
143+
144+
COPY configs /
145+
140146
# Use it to ignore packages authenticate in apt-get
141147
# ENV apt_arg="-o Acquire::AllowInsecureRepositories=true \
142148
# -o Acquire::AllowDowngradeToInsecureRepositories=true"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
2+
# Copyright (c) 2022 Intel Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# https://github.com/oscarlab/graphene/blob/master/Tools/gsc/images/graphene_aks.latest.dockerfile
17+
FROM openanolis/anolisos:8.4-x86_64 AS Anolisos
18+
19+
ENV INSTALL_PREFIX=/usr/local
20+
ENV LD_LIBRARY_PATH=${INSTALL_PREFIX}/lib:${INSTALL_PREFIX}/lib64:${LD_LIBRARY_PATH}
21+
ENV PATH=${INSTALL_PREFIX}/bin:${LD_LIBRARY_PATH}:${PATH}
22+
# Add steps here to set up dependencies
23+
RUN yum -y install \
24+
openssl-devel \
25+
libcurl-devel \
26+
protobuf-devel \
27+
yum-utils.noarch \
28+
python3 \
29+
wget
30+
31+
# Intel SGX
32+
RUN mkdir /opt/intel && cd /opt/intel \
33+
&& wget https://mirrors.openanolis.cn/inclavare-containers/bin/anolis8.4/sgx-2.15.1/sgx_rpm_local_repo.tar.gz \
34+
&& sha256sum sgx_rpm_local_repo.tar.gz \
35+
&& tar xvf sgx_rpm_local_repo.tar.gz \
36+
&& yum-config-manager --add-repo file:///opt/intel/sgx_rpm_local_repo \
37+
&& yum -y --nogpgcheck install libsgx-urts libsgx-launch libsgx-epid libsgx-quote-ex libsgx-dcap-ql libsgx-uae-service libsgx-dcap-quote-verify-devel
38+
&& yum -y groupinstall 'Development Tools'
39+
40+
# COPY patches/libsgx_dcap_quoteverify.so /usr/lib64/
41+
RUN yum -y install --nogpgcheck sgx-dcap-pccs libsgx-dcap-default-qpl
42+
43+
# Gramine
44+
ENV GRAMINEDIR=/gramine
45+
ENV SGX_DCAP_VERSION=DCAP_1.11
46+
ENV GRAMINE_VERSION=v1.2
47+
ENV ISGX_DRIVER_PATH=${GRAMINEDIR}/driver
48+
ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig/
49+
ENV LC_ALL=C.UTF-8 LANG=C.UTF-8
50+
ENV WERROR=1
51+
ENV SGX=1
52+
ENV GRAMINE_PKGLIBDIR=/usr/local/lib64/gramine
53+
ENV ARCH_LIBDIR=/lib64
54+
55+
RUN yum -y install gawk bison python3-click python3-jinja2 golang ninja-build
56+
RUN yum -y install openssl-devel protobuf-c-devel python3-protobuf protobuf-c-compiler
57+
RUN yum -y install gmp-devel mpfr-devel libmpc-devel isl-devel nasm python3-devel mailcap
58+
#install gramine
59+
RUN ln -s /usr/bin/python3 /usr/bin/python \
60+
&& python3 -m pip install --upgrade pip \
61+
&& python3 -m pip install toml meson wheel cryptography paramiko \
62+
&& git clone https://github.com/gramineproject/gramine.git ${GRAMINEDIR} \
63+
&& cd ${GRAMINEDIR} \
64+
&& git checkout ${GRAMINE_VERSION}
65+
66+
RUN git clone https://github.com/intel/SGXDataCenterAttestationPrimitives.git ${ISGX_DRIVER_PATH} \
67+
&& cd ${ISGX_DRIVER_PATH} \
68+
&& git checkout ${SGX_DCAP_VERSION}
69+
70+
ENV LD_LIBRARY_PATH=${INSTALL_PREFIX}/lib:${INSTALL_PREFIX}/lib64:${LD_LIBRARY_PATH}
71+
RUN cd ${GRAMINEDIR} \
72+
&& LD_LIBRARY_PATH="" meson setup build/ --buildtype=debug -Dprefix=${INSTALL_PREFIX} -Ddirect=enabled -Dsgx=enabled -Ddcap=enabled -Dsgx_driver=dcap1.10 -Dsgx_driver_include_path=${ISGX_DRIVER_PATH}/driver/linux/include \
73+
&& LD_LIBRARY_PATH="" ninja -C build/ \
74+
&& LD_LIBRARY_PATH="" ninja -C build/ install
75+
RUN gramine-sgx-gen-private-key
76+
77+
FROM Anolisos AS Psi_tensorflow
78+
# Install mbedtls
79+
RUN cd ${GRAMINEDIR}/build/subprojects/mbedtls-mbedtls* \
80+
&& cp -r *_gramine.a ${INSTALL_PREFIX}/lib \
81+
&& cd ${GRAMINEDIR}/subprojects/mbedtls-mbedtls*/mbedtls-mbedtls* \
82+
&& cp -r include/mbedtls ${INSTALL_PREFIX}/include
83+
84+
# Install cJSON
85+
RUN cd ${GRAMINEDIR}/subprojects/cJSON*/ \
86+
&& make static \
87+
&& cp -r *.a ${INSTALL_PREFIX}/lib \
88+
&& mkdir -p ${INSTALL_PREFIX}/include/cjson \
89+
&& cp -r *.h ${INSTALL_PREFIX}/include/cjson
90+
91+
RUN echo "enabled=0" > /etc/default/apport
92+
RUN echo "exit 0" > /usr/sbin/policy-rc.d
93+
94+
# Clean tmp files
95+
RUN yum -y clean all && rm -rf /var/cache
96+
97+
COPY configs /
98+
99+
# Workspace
100+
ENV WORK_SPACE_PATH=${GRAMINEDIR}
101+
WORKDIR ${WORK_SPACE_PATH}

cczoo/psi/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ images for developing the gRPC RA-TLS application.
5555

5656
### Prerequisites
5757

58-
- Ubuntu 18.04. This solution should work on other Linux distributions as well,
59-
but for simplicity we provide the steps for Ubuntu 18.04 only.
58+
- Ubuntu 20.04. This solution should work on other Linux distributions as well,
59+
but for simplicity we provide the steps for Ubuntu 20.04 only.
6060

6161
- Docker Engine. Docker Engine is an open source containerization technology for
6262
building and containerizing your applications.
@@ -85,7 +85,7 @@ After Intel SGX DCAP is setup, verify the Intel Architectural Enclave Service Ma
8585
- Gramine
8686
```bash
8787
cd cczoo/common/docker/gramine
88-
./build_docker_image.sh
88+
./build_docker_image.sh [ubuntu/anolisos]
8989
```
9090

9191
### Setup develop environment of gRPC RA-TLS based on Intel SGX
@@ -94,7 +94,7 @@ After Intel SGX DCAP is setup, verify the Intel Architectural Enclave Service Ma
9494
```bash
9595
cd -
9696
cd cczoo/psi/gramine
97-
./build_docker_image.sh
97+
./build_docker_image.sh [ubuntu/anolisos]
9898
```
9999

100100
## Run PSI examples
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a./grpc.manifest.template b./grpc.manifest.template
2+
index c29ed9d..fc8a3fb 100644
3+
--- a./grpc.manifest.template
4+
+++ b./grpc.manifest.template
5+
@@ -58,7 +58,7 @@ sgx.trusted_files = [
6+
"file:{{ gramine.runtimedir() }}/",
7+
"file:{{ arch_libdir }}/",
8+
"file:/usr{{ arch_libdir }}/",
9+
- "file:/etc/ssl/certs/ca-certificates.crt",
10+
+ "file:/etc/ssl/certs/ca-bundle.crt",
11+
]
12+
13+
sgx.allowed_files = [

cczoo/psi/gramine/CI-Examples/psi/cpp/grpc.manifest.template

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# limitations under the License.
1515

1616
libos.entrypoint = "{{ entrypoint }}"
17-
libos.check_invalid_pointers = false
17+
# libos.check_invalid_pointers = false
1818

19-
loader.preload = "file:{{ gramine.libos }}"
19+
loader.entrypoint = "file:{{ gramine.libos }}"
2020
loader.log_level = "{{ log_level }}"
2121
# loader.log_file = ""
2222

@@ -32,42 +32,29 @@ loader.env.GRPC_VERBOSITY = "ERROR"
3232
sys.enable_sigterm_injection = true
3333
sys.stack.size = "16M"
3434

35-
fs.mount.lib.type = "chroot"
36-
fs.mount.lib.path = "/lib"
37-
fs.mount.lib.uri = "file:{{ gramine.runtimedir() }}"
38-
39-
fs.mount.lib2.type = "chroot"
40-
fs.mount.lib2.path = "{{ arch_libdir }}"
41-
fs.mount.lib2.uri = "file:{{ arch_libdir }}"
42-
43-
fs.mount.lib3.type = "chroot"
44-
fs.mount.lib3.path = "/usr{{ arch_libdir }}"
45-
fs.mount.lib3.uri = "file:/usr{{ arch_libdir }}"
46-
47-
fs.mount.etc.type = "chroot"
48-
fs.mount.etc.path = "/etc"
49-
fs.mount.etc.uri = "file:/etc"
50-
51-
# Note that Gramine also creates an internal
52-
# thread for handling inter-process communication (IPC), and potentially another
53-
# thread for asynchronous events. Therefore, the actual number of threads that
54-
# the application can create is (sgx.thread_num - 2).
35+
fs.mounts = [
36+
{ path = "/lib", uri = "file:{{ gramine.runtimedir() }}" },
37+
{ path = "{{ arch_libdir }}", uri = "file:{{ arch_libdir }}" },
38+
{ path = "/etc", uri = "file:/etc" },
39+
{ path = "/usr", uri = "file:/usr" },
40+
{ type = "tmpfs", path = "/var/tmp" },
41+
]
5542

5643
sgx.debug = false
5744
sgx.remote_attestation = true
45+
sgx.enable_stats = false
5846
sgx.nonpie_binary = true
59-
6047
sgx.enclave_size = "2G"
6148
sgx.thread_num = 16
6249

63-
sgx.require_avx = true
50+
# sgx.require_avx = true
6451
# sgx.require_avx512 = true
6552
# sgx.require_amx = true
6653

67-
sgx.enable_stats = false
6854

6955
sgx.trusted_files = [
7056
"file:{{ entrypoint }}",
57+
"file:{{ gramine.libos }}",
7158
"file:{{ gramine.runtimedir() }}/",
7259
"file:{{ arch_libdir }}/",
7360
"file:/usr{{ arch_libdir }}/",

cczoo/psi/gramine/CI-Examples/psi/python/Makefile

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515

1616
################################# CONSTANTS ###################################
1717

18-
GRAMINEDIR ?= ../../../..
19-
SGX_SIGNER_KEY ?= $(GRAMINEDIR)/Pal/src/host/Linux-SGX/signer/enclave-key.pem
20-
21-
include $(GRAMINEDIR)/Scripts/Makefile.configs
18+
ARCH_LIBDIR ?= /lib/$(shell $(CC) -dumpmachine)
19+
# ENTRYPOINT ?= $(realpath $(shell sh -c "command -v python3"))
2220

2321
ifeq ($(DEBUG),1)
24-
GRAPHENE_LOG_LEVEL = debug
22+
GRAMINE_LOG_LEVEL = debug
2523
else
26-
GRAPHENE_LOG_LEVEL = error
24+
GRAMINE_LOG_LEVEL = error
2725
endif
2826

2927
.PHONY: all
@@ -32,22 +30,23 @@ ifeq ($(SGX),1)
3230
all: python.manifest.sgx python.sig python.token
3331
endif
3432

35-
################################ gRPC MANIFEST ###############################
33+
################################ MANIFEST ###############################
3634

3735
python.manifest: python.manifest.template
3836
gramine-manifest \
37+
-Dlog_level=$(GRAMINE_LOG_LEVEL) \
3938
-Dentrypoint=$(realpath $(shell sh -c "command -v python3")) \
4039
-Darch_libdir=$(ARCH_LIBDIR) \
41-
-Dlog_level=$(GRAPHENE_LOG_LEVEL) \
4240
$< >$@
4341

44-
python.manifest.sgx: python.manifest
42+
python.manifest.sgx python.sig: sgx_sign
43+
@:
44+
45+
.INTERMEDIATE: sgx_sign
46+
sgx_sign: python.manifest
4547
gramine-sgx-sign \
46-
--key $(SGX_SIGNER_KEY) \
4748
--manifest $< \
48-
--output $@
49-
50-
python.sig: python.manifest.sgx
49+
--output $<.sgx
5150

5251
python.token: python.sig
5352
gramine-sgx-get-token --output $@ --sig $<
@@ -60,4 +59,4 @@ clean:
6059
$(RM) -r scripts/__pycache__
6160

6261
.PHONY: distclean
63-
distclean: clean
62+
distclean: clean
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
diff --git a./python.manifest.template b./python.manifest.template
2+
index 057cffe..480dd78 100644
3+
--- a./python.manifest.template
4+
+++ b./python.manifest.template
5+
@@ -37,9 +37,10 @@ fs.mounts = [
6+
{ path = "/usr", uri = "file:/usr" },
7+
{ type = "tmpfs", path = "/var/tmp" },
8+
{ path = "{{ python.stdlib }}", uri = "file:{{ python.stdlib }}" },
9+
- { path = "{{ python.distlib }}", uri = "file:{{ python.distlib }}" },
10+
+ # { path = "{{ python.distlib }}", uri = "file:{{ python.distlib }}" },
11+
# { path = "/usr/local/lib/python3.6/dist-packages/", uri = "file:/usr/local/lib/python3.6/dist-packages/" }, # for ubuntu:18.04
12+
- { path = "/usr/local/lib/python3.8/dist-packages/", uri = "file:/usr/local/lib/python3.8/dist-packages/" }, # for ubuntu:20.04
13+
+ # { path = "/usr/local/lib/python3.8/dist-packages/", uri = "file:/usr/local/lib/python3.8/dist-packages/" }, # for ubuntu:20.04
14+
+ { path = "/usr/local/lib/python3.6/site-packages/", uri = "file:/usr/local/lib/python3.6/site-packages/" }, # for anolisos
15+
]
16+
17+
sgx.debug = false
18+
@@ -60,10 +61,12 @@ sgx.trusted_files = [
19+
"file:{{ arch_libdir }}/",
20+
"file:/usr/{{ arch_libdir }}/",
21+
"file:{{ python.stdlib }}/",
22+
- "file:{{ python.distlib }}/",
23+
+ # "file:{{ python.distlib }}/",
24+
# "file:/usr/local/lib/python3.6/dist-packages/", # for ubuntu:18.04
25+
- "file:/usr/local/lib/python3.8/dist-packages/", # for ubuntu:20.04
26+
- "file:/etc/ssl/certs/ca-certificates.crt",
27+
+ # "file:/usr/local/lib/python3.8/dist-packages/", # for ubuntu:20.04
28+
+ "file:/usr/local/lib/python3.6/site-packages/",
29+
+ "file:/usr/local/lib64/python3.6/site-packages/",
30+
+ "file:/etc/ssl/certs/ca-bundle.crt",
31+
"file:server.py",
32+
"file:data_provider1.py",
33+
"file:data_provider2.py",

0 commit comments

Comments
 (0)