Skip to content

Commit 304cfbd

Browse files
authored
Merge pull request #16 from iExecBlockchainComputing/feature/gramine
Feature/gramine
2 parents ea3a4f4 + e76a7af commit 304cfbd

3 files changed

Lines changed: 128 additions & 3 deletions

File tree

Jenkinsfile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22

33
buildInfo = getBuildInfo()
44

5-
def nativeImage = buildSimpleDocker_v2(
5+
baseDir = 'cloud-computing'
6+
nativeImage = buildSimpleDocker_v3(
67
buildInfo: buildInfo,
7-
dockerfileDir: 'cloud-computing',
8+
dockerfileDir: baseDir,
9+
buildContext: baseDir,
810
dockerImageRepositoryName: 'python-hello-world',
9-
imageprivacy: 'public'
11+
visibility: 'docker.io'
1012
)
1113

14+
buildSimpleDocker_v3(
15+
buildInfo: buildInfo,
16+
dockerfileDir: baseDir + '/gramine',
17+
buildContext: baseDir,
18+
dockerImageRepositoryName: 'tee-gramine-python-hello-world',
19+
visibility: 'iex.ec'
20+
)
21+
22+
1223
sconeBuildUnlocked(
1324
nativeImage: nativeImage,
1425
imageName: 'python-hello-world',

cloud-computing/gramine/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# FIXME: use tagged version when released
2+
FROM docker-regis.iex.ec/iexec-graphene-base:0.7.0
3+
4+
RUN apt-get install -y python3 \
5+
&& pip3 install pyfiglet
6+
7+
ARG SOURCE_DIR=src
8+
ARG GRAMINE_DIR=gramine
9+
10+
# get the code of app to /workplace/app
11+
COPY $SOURCE_DIR/app.py /workplace/app
12+
13+
# set the main function for python and node app, no need for binnary app
14+
RUN sed -i "s#MAIN_FUNC=#MAIN_FUNC=/workplace/app/app.py#" /apploader.sh
15+
16+
WORKDIR /workplace/app
17+
18+
# Copy the manifest to use from within the base image
19+
# or create your own
20+
RUN mv /common-manifests/python.entrypoint.manifest /entrypoint.manifest \
21+
&& rm -r /common-manifests
22+
23+
# Finalize app (finalize manifest and sign app)
24+
RUN /finalize-app.sh

cloud-computing/gramine/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
## How to run demo with Gramine on localhost
2+
3+
1. Start a SPS container:
4+
```shell
5+
SPS_VERSION=<set SPS version here>
6+
docker run -d \
7+
-v /opt/multiple/sessions:/graphene/workplace/sessions \
8+
-v /opt/secret-prov/certs/:/graphene/workplace/certs \
9+
-p 8080:8080 -p 4433:4433 \
10+
-e SPS_USERNAME=admin -e SPS_PASSWORD=admin \
11+
--name iexec-sps \
12+
iexechub/iexec-sps:${SPS_VERSION}
13+
```
14+
15+
16+
2. Build your app (from `cloud-computing` directory) :
17+
```shell
18+
docker build -t tee-gramine-python-hello-world:latest -f gramine/Dockerfile .
19+
```
20+
Please note the `measurement` value.
21+
22+
23+
3. To add a session to the SPS, run the following after having filled both env var:
24+
```shell
25+
SESSION_ID=<define your custom session id>
26+
MEASUREMENT=<set previous retrieved measurement>
27+
28+
curl --location --request POST 'localhost:8080/api/session/' \
29+
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
30+
--header 'Content-Type: application/json' \
31+
--data-raw '{
32+
"session": "'${SESSION_ID}'",
33+
"enclaves": [
34+
{
35+
"name": "app",
36+
"mrenclave": "'${MEASUREMENT}'",
37+
"command": "/apploader.sh",
38+
"environment": {
39+
"IEXEC_IN": "/iexec_in",
40+
"IEXEC_OUT": "/iexec_out",
41+
"IEXEC_DATASET_FILENAME": "file.txt",
42+
"IEXEC_INPUT_FILES_NUMBER": "1",
43+
"IEXEC_INPUT_FILE_NAME_1": "file.txt",
44+
"IEXEC_TASK_ID": "TASK_ID",
45+
"IEXEC_APP_DEVELOPER_SECRET": "App developer secret",
46+
"IEXEC_REQUESTER_SECRET_1": "Requester secret 1",
47+
"IEXEC_REQUESTER_SECRET_2": "Requester secret 2",
48+
"IEXEC_REQUESTER_SECRET_3": "Requester secret 3"
49+
},
50+
"volumes": [
51+
]
52+
}
53+
]
54+
}'
55+
```
56+
57+
58+
4. Run the app:
59+
```shell
60+
docker run \
61+
--device=/dev/sgx/enclave \
62+
-v /iexec_in:/iexec_in -v /tmp/iexec_out:/iexec_out \
63+
-v /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket \
64+
-v $PWD/encryptedData:/workplace/encryptedData \
65+
-v /opt/secret-prov/certs/:/graphene/attestation/certs/ \
66+
--net=host \
67+
-e session=${SESSION_ID} -e sps=localhost:4433 \
68+
tee-gramine-python-hello-world:latest
69+
```
70+
71+
72+
### Troubleshooting:
73+
74+
#### "Get keys failed"
75+
When the app can't communicate with the SPS, you can encounter some numeric error codes, in the following format:
76+
```
77+
[error] connect to kms failed, kms_endpoint is iexec-sps:4433, cert_path is /graphene/attestation/certs/test-ca-sha256.crt
78+
[error] get keys failed, return -[ERROR_CODE]
79+
```
80+
81+
Depending on the error code, the issue is the following:
82+
83+
| Error code | Error | Solution |
84+
|:----------:|:-----------------:|:-------------------------------------------------------------------------------------------------------------------------:|
85+
| 111 | Can't reach SPS | Check SPS IP is correct in app configuration. |
86+
| 9984 | Certificate error | Check both app & SPS share a valid certificate. Regenerate it if needed, providing SPS IP as `Common Name` when prompted. |
87+
88+
89+
#### Dataset and input files are not correctly read
90+
Check they are correctly added as `sgx.allowed_files` in `entrypoint.manifest`.

0 commit comments

Comments
 (0)