Search…
Use confidential assets
Prerequisites
Please make sure you have already checked the Quickstart, Your first application and Build trusted applications tutorials before learning how to manage confidential datasets.
Trusted Execution Environments offer a huge advantage from a security perspective. They guarantee that the behavior of execution does not change even when launched on an untrusted remote machine. The data inside this type of environment is also protected, which allows its monetization while preventing leakage.
With iExec, it is possible to authorize only applications you trust to use your datasets and get paid for it. Data is encrypted using standard encryption mechanisms and the plain version never leaves your machine. The encrypted version is made available for usage and the encryption key is pushed into the SMS. After you deploy the dataset on iExec it is you, and only you, who decides which application is allowed to get the secret to decrypt it.
Datasets are only decrypted inside authorized enclaves and never leave them. The same thing applies to secrets.
Your secrets are securely transferred with the SDK from your machine to the SMS over a TLS channel. Internally, your secrets are encrypted with standard AES encryption before being written to disk. Next releases will feature an SMS running entirely inside a trusted enclave.
Let's see how to do all of that!

Encrypt the dataset

Before starting, let's make sure we are inside the folder ~/iexec-projects - created previously, during the quick start tutorial.
cd ~/iexec-projects
Init the dataset configuration.
iexec dataset init --encrypted
This command will create the folders datasets/encrypted, datasets/original and .secrets/datasets. A new section "dataset" will be added to the iexec.json file as well.
.
├── datasets
│ ├── encrypted
│ └── original
└── .secrets
│ └── datasets
...
We will create a dummy file that has "Hello, world!" as content inside datasets/original. Alternatively, you can put your own dataset file.
echo "Hello, confidential world!" > datasets/original/my-first-dataset.txt
datasets
├── encrypted
└── original
└── my-first-dataset.txt
Now run the following command to encrypt the file:
iexec dataset encrypt
iexec dataset encrypt will output a checksum, keep this value for a later use.
datasets
├── encrypted
│ └── my-first-dataset.txt.enc
└── original
└── my-first-dataset.txt
As you can see, the command generated the file datasets/encrypted/my-first-dataset.txt.enc. That file is the encrypted version of your dataset, you should push it somewhere accessible because the worker will download it during the execution process. You will enter this file's URI in the iexec.jsonfile (multiaddr attribute) when you will deploy your dataset. Make sure that the URI is a DIRECT download link (not a link to a web page for example).
You can use Github for example to publish the file but you should add /raw/ to the URI like this: https://github.com/<username>/<repo>/raw/master/my-first-dataset.zip
The file .secrets/datasets/my-first-dataset.txt.key is the encryption key, make sure to back it up securely. The file .secrets/datasets/dataset.key is just an "alias" in the sense that it is the key of the last encrypted dataset.
.secrets
└── datasets
├── dataset.key
└── my-first-dataset.txt.key

Deploy the dataset

Fill in the fields of the iexec.json file. Choose a name for your dataset, put the encrypted file's URI in multiaddr(the URI you got after publishing the file), and add the checksum (you can get it by running sha256sum datasets/encrypted/my-first-dataset.txt.enc)
$ cat iexec.json
{
"description": "My iExec ressource description...",
...
"dataset": {
"owner": "0x-your-wallet-address",
"name": "Encrypted hello world dataset",
"multiaddr": "/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ",
"checksum": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
}
To deploy your dataset run:
iexec dataset deploy --chain bellecour
You will get a hexadecimal address for your deployed dataset. Use that address to push the encryption key to the SMS so it is available for authorized applications.
For simplicity, we will use the dataset with a TEE-debug app on a debug workerpool. The debug workerpool is connected to a debug Secret Management Service so we will send the dataset encryption key to this SMS (this is fine for debugging but do not use to store production secrets).
These sed commands will do the trick:
# set a custom bellecour SMS in chain.json
sed -i 's|"bellecour": {},|"bellecour": { "sms": "https://v7.sms.debug-tee-services.bellecour.iex.ec" },|g' chain.json
# push the dataset secret to the SMS
iexec dataset push-secret --chain bellecour
# check the secret is available on the SMS
iexec dataset check-secret --chain bellecour
# restore the default configuration in chain.json
sed -i 's|"bellecour": { "sms": "https://v7.sms.debug-tee-services.bellecour.iex.ec" },|"bellecour": {},|g' chain.json
We saw in this section how to encrypt a dataset and deploy it on iExec. In addition, we learned how to push the encryption secret to the SMS. Now we need to build the application that is going to consume this dataset.

Prepare your application

Let's create a directory tree for this app in ~/iexec-projects/.
cd ~/iexec-projects
mkdir tee-dataset-app && cd tee-dataset-app
iexec init --skip-wallet
mkdir src
touch Dockerfile
touch sconify.sh
In the folder src/ create the file app.js or app.py then copy this code inside:
The application reads the content of the dataset and writes it into the result's folder (in an artistic way using Figlet):
Javascript
Python
src/app.js
const fsPromises = require('fs').promises;
const figlet = require('figlet');
(async () => {
try {
const iexecOut = process.env.IEXEC_OUT;
const iexecIn = process.env.IEXEC_IN;
const datasetFileName = process.env.IEXEC_DATASET_FILENAME;
// Use some confidential assets
let text = '';
try {
const confidentialFile = await fsPromises.readFile(`${iexecIn}/${datasetFileName}`);
text = figlet.textSync(confidentialFile.toString());
} catch (e) {
console.log('confidential file does not exist');
}
// Append some results
await fsPromises.writeFile(`${iexecOut}/result.txt`, text);
console.log(text);
// Declare everything is computed
const computedJsonObj = {
'deterministic-output-path': `${iexecOut}/result.txt`,
};
await fsPromises.writeFile(
`${iexecOut}/computed.json`,
JSON.stringify(computedJsonObj),
);
} catch (e) {
console.log(e);
process.exit(1);
}
})();
src/app.py
import json
import os
from pyfiglet import Figlet
iexec_out = os.environ['IEXEC_OUT']
iexec_in = os.environ['IEXEC_IN']
dataset_filename = os.environ['IEXEC_DATASET_FILENAME']
text = ''
# Check the confidential file exists and open it
try:
dataset_file = open(iexec_in + '/' + dataset_filename, 'r')
dataset = dataset_file.read()
text = Figlet().renderText(dataset)
except OSError:
print('confidential file does not exists')
exit(1)
print(text)
# Append some results in /iexec_out/
with open(iexec_out + '/result.txt', 'w+') as fout:
fout.write(text)
# Declare everything is computed
with open(iexec_out + '/computed.json', 'w+') as f:
json.dump({"deterministic-output-path": iexec_out + '/result.txt'}, f)

Build the TEE docker image

The Dockerfile and the build scripts are the same as the ones we saw previously for a trusted application:
Javascript
Python
Dockerfile
# Starting from a base image supported by SCONE
FROM node:14-alpine3.11
# install your dependencies
RUN mkdir /app && cd /app && npm install [email protected]
COPY ./src /app
ENTRYPOINT [ "node", "/app/app.js"]
Dockerfile
FROM python:3.7.3-alpine3.10
### install python dependencies if you have some
RUN pip3 install pyfiglet
COPY ./src /app
ENTRYPOINT ["python3", "/app/app.py"]
Javascript
Python
sconify.sh
#!/bin/bash
# declare the app entrypoint
ENTRYPOINT="node /app/app.js"
# declare an image name
IMG_NAME=tee-dataset-app
IMG_FROM=${IMG_NAME}:temp-non-tee
IMG_TO=${IMG_NAME}:tee-debug
# build the regular non-TEE image
docker build . -t ${IMG_FROM}
# pull the SCONE curated image corresponding to our base image
docker pull registry.scontain.com:5050/sconecuratedimages/node:14.4.0-alpine3.11
# run the sconifier to build the TEE image based on the non-TEE image
docker run -it --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
registry.scontain.com:5050/scone-production/iexec-sconify-image:5.3.15 \
sconify_iexec \
--name=${IMG_NAME} \
--from=${IMG_FROM} \
--to=${IMG_TO} \
--binary-fs \
--fs-dir=/app \
--host-path=/etc/hosts \
--host-path=/etc/resolv.conf \
--binary=/usr/local/bin/node \
--heap=1G \
--dlopen=2 \
--no-color \
--verbose \
--command=${ENTRYPOINT} \
&& echo -e "\n------------------\n" \
&& echo "successfully built TEE docker image => ${IMG_TO}" \
&& echo "application mrenclave.fingerprint is $(docker run -it --rm -e SCONE_HASH=1 ${IMG_TO})"
#!/bin/bash
# declare the app entrypoint
ENTRYPOINT="python3 /app/app.py"
# declare an image name
IMG_NAME=tee-dataset-app
IMG_FROM=${IMG_NAME}:temp-non-tee
IMG_TO=${IMG_NAME}:tee-debug
# build the regular non-TEE image
docker build . -t ${IMG_FROM}
# run the sconifier to build the TEE image based on the non-TEE image
docker run -it \
-v /var/run/docker.sock:/var/run/docker.sock \
registry.scontain.com:5050/scone-production/iexec-sconify-image:5.3.15 \
sconify_iexec \
--name=${IMG_NAME} \
--from=${IMG_FROM} \
--to=${IMG_TO} \
--binary-fs \
--fs-dir=/app \
--host-path=/etc/hosts \
--host-path=/etc/resolv.conf \
--binary=/usr/local/bin/python3.7 \
--heap=1G \
--dlopen=2 \
--no-color \
--verbose \
--command=${ENTRYPOINT} \
&& echo -e "\n------------------\n" \
&& echo "successfully built TEE docker image => ${IMG_TO}" \
&& echo "application mrenclave.fingerprint is $(docker run -it --rm -e SCONE_HASH=1 ${IMG_TO})"
Run the sconify.sh script to build the TEE-debug app.
The sconify.sh script prints the generated docker image name, you must retag this image and push it on dockerhub.

Test your app on iExec

At this stage, your application is ready to be tested on iExec. The process is similar to testing any type of application on the platform, with these minor exceptions:

Deploy the TEE app on iExec

TEE applications require some additional information to be filled in during deployment.
# prepare the TEE application template
iexec app init --tee
Edit iexec.json and fill in the standard keys and the mrenclave object:
{
...
"app": {
"owner": "0xF048eF3d7E3B33A465E0599E641BB29421f7Df92", // your address
"name": "tee-dataset-app", // application name
"type": "DOCKER",
"multiaddr": "docker.io/username/tee-dataset-app:1.0.0", // app image
"checksum": "0x15bed530c76f1f3b05b2db8d44c417128b8934899bc85804a655a01b441bfa78", // image digest
"mrenclave": {
"provider": "SCONE", // TEE provider (keep default value)
"version": "v5", // Scone version (keep default value)
"entrypoint": "node /app/app.js" OR "python3 /app/app.py", // your app image entrypoint
"heapSize": 1073741824, // heap size in bytes (1GB)
"fingerprint": "eca3ace86f1e8a5c47123c8fd271319e9eb25356803d36666dc620f30365c0c1" // fingerprint of the enclave code (mrenclave), see how to retrieve it below
}
},
...
}
Run your TEE image with SCONE_HASH=1 to get the enclave fingerprint (mrenclave):
docker run -it --rm -e SCONE_HASH=1 tee-dataset-app:tee-debug
Deploy the app with the standard command:
iexec app deploy --chain bellecour

Run the TEE app

Specify the tag --tag tee and the dataset to use --dataset <datasetAddress> in iexec app run command to run a tee app with a dataset.
One last thing, in order to run a TEE-debug app you will also need to select a debug workerpool, use the debug workerpool v7-debug.main.pools.iexec.eth.
You are now ready to run the app
iexec app run <appAddress> --tag tee --dataset <datasetAddress> --workerpool v7-debug.main.pools.iexec.eth --watch --chain bellecour

Next step?

Thanks to the explained confidential computing workflow, it is possible to use an encrypted dataset with a trusted application. We can go another step further and protect the result too. See in the next chapter how to make your execution result encrypted so that you are the only one who can read it.
Copy link
On this page
Encrypt the dataset
Deploy the dataset
Prepare your application
Build the TEE docker image
Test your app on iExec
Deploy the TEE app on iExec
Run the TEE app
Next step?