running_rune_with_occlum.md 4.3 KB
Newer Older
jia zhang's avatar
jia zhang 已提交
1 2
# Quick Start: running rune with Occlum
[rune](https://github.com/alibaba/inclavare-containers) is a new OCI runtime used to run trusted applications in containers with the hardware-assisted enclave technology.
3

jia zhang's avatar
jia zhang 已提交
4
## Requirements
5 6
- Install [Intel SGX driver for Linux](https://github.com/intel/linux-sgx-driver#build-and-install-the-intelr-sgx-driver), required by Intel SGX SDK && PSW.
- Install [enable_rdfsbase kernel module](https://github.com/occlum/enable_rdfsbase#how-to-build), allowing to use `rdfsbase` -family instructions in Occlum.
jia zhang's avatar
jia zhang 已提交
7 8 9
- Assume the host system is CentOS 7.5.
- You can also launch a CentOS 7.5 container as your host system with the following command:
  ```shell
10
  docker run -it --privileged --device /dev/isgx centos:7.5.1804
jia zhang's avatar
jia zhang 已提交
11 12 13 14 15
  ```
  If so, you need to run **another docker daemon** inside this CentOS 7.5 container. Please refer to [this guide](https://docs.docker.com/engine/install/centos) to install docker daemon, and type the following command to start dockerd.
  ```shell
  dockerd -b docker0 --storage-driver=vfs &
  ```
16 17 18

---

jia zhang's avatar
jia zhang 已提交
19 20 21 22
## Build Occlum application container image
### Download Occlum SDK container image
```shell
mkdir "$HOME/rune_workdir"
23
docker run -it --privileged --device /dev/isgx \
jia zhang's avatar
jia zhang 已提交
24
  -v "$HOME/rune_workdir":/root/rune_workdir \
25
  occlum/occlum:0.14.0-centos7.5
26 27 28
```

### Prepare the materials
jia zhang's avatar
jia zhang 已提交
29 30 31
Before Occlum build, execute the following command to set your Occlum instance name:

```shell
32 33 34 35 36
export OCCLUM_INSTANCE_DIR=occlum-app
```

[This guide](https://github.com/occlum/occlum#hello-occlum) can help you to create your first occlum build.

jia zhang's avatar
jia zhang 已提交
37
Assuming "hello world" demo program is built, execute the following commands in Occlum SDK container:
38

jia zhang's avatar
jia zhang 已提交
39
```shell
40 41 42
cp -a ${OCCLUM_INSTANCE_DIR} /root/rune_workdir
```

jia zhang's avatar
jia zhang 已提交
43 44
### Prepare Occlum application image
Now you can build your occlum application image in the $HOME/rune_workdir directory of your host system.
45 46 47

Type the following commands to create a `Dockerfile`:
``` Dockerfile
jia zhang's avatar
jia zhang 已提交
48
cd "$HOME/rune_workdir"
49 50 51 52 53 54 55 56
cat >Dockerfile <<EOF
FROM centos:7.5.1804

ENV OCCLUM_INSTANCE_DIR=occlum-app
RUN mkdir -p /run/rune/${OCCLUM_INSTANCE_DIR}
WORKDIR /run/rune

COPY ${OCCLUM_INSTANCE_DIR} ${OCCLUM_INSTANCE_DIR}
jia zhang's avatar
jia zhang 已提交
57
COPY ${OCCLUM_INSTANCE_DIR}/build/lib/libocclum-pal.so /usr/lib/liberpal-occlum.so
58 59 60 61 62 63 64 65 66 67 68 69

ENTRYPOINT ["/bin/hello_world"]
EOF
```

and then build it with the command:
```shell
docker build . -t ${Occlum_application_image}
```

---

jia zhang's avatar
jia zhang 已提交
70 71
## Install Inclavare Containers binary
Download the binary release from [here](https://github.com/alibaba/inclavare-containers/releases/).
72 73

### Install `sgx_linux_x64_sdk_2.9.101.2.bin`
jia zhang's avatar
jia zhang 已提交
74 75
Type the following commands to install `sgx_linux_x64_sdk_2.9.101.2.bin` on your host system.
```shell
76
yum install -y make
jia zhang's avatar
jia zhang 已提交
77
echo -e "no\n/opt/intel\n" | ./sgx_linux_x64_sdk_2.9.101.2.bin
78 79 80
```

### Install `sgx_linux_x64_psw_2.9.101.2.bin` 
jia zhang's avatar
jia zhang 已提交
81 82
Type the following commands to install `sgx_linux_x64_psw_2.9.101.2.bin` on your host system.
```shell
83 84
yum install -y https://cbs.centos.org/kojifiles/packages/protobuf/3.6.1/4.el7/x86_64/protobuf-3.6.1-4.el7.x86_64.rpm
./sgx_linux_x64_psw_2.9.101.2.bin
jia zhang's avatar
jia zhang 已提交
85 86 87
cd /opt/intel/sgxpsw/aesm
export LD_LIBRARY_PATH=$PWD
export AESM_PATH=$PWD
88 89 90
/opt/intel/sgxpsw/aesm/aesm_service
```

jia zhang's avatar
jia zhang 已提交
91 92 93 94 95 96
### Install rune and liberpal-occlum.so
```shell
cp ./rune /usr/local/sbin
cp ./liberpal-occlum.so /usr/lib
```

97 98
---

jia zhang's avatar
jia zhang 已提交
99 100
## Config OCI Runtimes
Add the `rune` OCI runtime configuration in dockerd config file, e.g, `/etc/docker/daemon.json`, on your system.
101

jia zhang's avatar
jia zhang 已提交
102
```JSON
103 104 105 106 107 108 109 110 111 112
{
	"runtimes": {
		"rune": {
			"path": "/usr/local/sbin/rune",
			"runtimeArgs": []
		}
	}
}
```

jia zhang's avatar
jia zhang 已提交
113
then restart dockerd on your system.
114

jia zhang's avatar
jia zhang 已提交
115 116 117
You can check whether `rune` is correctly added to OCI runtime or not with
```shell
docker info | grep rune
118 119 120 121 122 123 124 125
Runtimes: rune runc
```

---

## Run Occlum application image using rune
You need to specify a set of parameters to `docker run` in order to use `rune`, e.g,

jia zhang's avatar
jia zhang 已提交
126 127 128
```shell
export OCCLUM_INSTANCE_DIR=occlum-app
yum install -y libseccomp
129 130 131 132 133 134 135 136 137
docker run -it --rm --runtime=rune \
  -e ENCLAVE_TYPE=intelSgx \
  -e ENCLAVE_RUNTIME_PATH=/usr/lib/liberpal-occlum.so \
  -e ENCLAVE_RUNTIME_ARGS=${OCCLUM_INSTANCE_DIR} \
  ${Occlum_application_image}
```

where:
- @ENCLAVE_TYPE: specify the type of enclave hardware to use, such as `intelSgx`.
jia zhang's avatar
jia zhang 已提交
138 139
- @ENCLAVE_PATH: specify the path to enclave runtime to launch.
- @ENCLAVE_ARGS: specify the specific arguments to enclave runtime, separated by the comma.