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
H
haosanzi 已提交
5
- Install Intel SGX driver for Linux by following [Intel SGX Installation Guide](https://download.01.org/intel-sgx/sgx-linux/2.9.1/docs/Intel_SGX_Installation_Guide_Linux_2.9.1_Open_Source.pdf), required by Intel SGX SDK && PSW.
6
- Install [enable_rdfsbase kernel module](https://github.com/occlum/enable_rdfsbase#how-to-build), allowing to use `rdfsbase` -family instructions in Occlum.
7
- Ensure that you have one of the following required operating systems:
H
haosanzi 已提交
8
  - CenOS 8.1
9 10 11
  - Ubuntu 18.04-server

  Note: You may also choose to launch a container corresponding to above operating systems.
jia zhang's avatar
jia zhang 已提交
12
  ```shell
H
haosanzi 已提交
13
  docker run -it --privileged --device /dev/isgx centos:8.1.1911
jia zhang's avatar
jia zhang 已提交
14
  ```
15 16 17 18
  or
  ```shell
  docker run -it --privileged --device /dev/isgx ubuntu:18.04
  ```
H
haosanzi 已提交
19
  If so, you need to run **another docker daemon** inside your container. Please refer to [this guide](https://docs.docker.com/engine/install) to install docker daemon. In CentOS 8.1 container, type the following command to start dockerd.
jia zhang's avatar
jia zhang 已提交
20 21 22
  ```shell
  dockerd -b docker0 --storage-driver=vfs &
  ```
23 24 25

---

jia zhang's avatar
jia zhang 已提交
26 27 28 29
## Build Occlum application container image
### Download Occlum SDK container image
```shell
mkdir "$HOME/rune_workdir"
30
docker run -it --privileged --device /dev/isgx \
jia zhang's avatar
jia zhang 已提交
31
  -v "$HOME/rune_workdir":/root/rune_workdir \
H
haosanzi 已提交
32
  occlum/occlum:0.15.1-centos8.1
33 34 35
```

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

```shell
39 40 41 42 43
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 已提交
44
Assuming "hello world" demo program is built, execute the following commands in Occlum SDK container:
45

jia zhang's avatar
jia zhang 已提交
46
```shell
47 48 49
cp -a ${OCCLUM_INSTANCE_DIR} /root/rune_workdir
```

jia zhang's avatar
jia zhang 已提交
50 51
### Prepare Occlum application image
Now you can build your occlum application image in the $HOME/rune_workdir directory of your host system.
52 53 54

Type the following commands to create a `Dockerfile`:
``` Dockerfile
H
haosanzi 已提交
55
cd "$HOME/rune_workdir/${OCCLUM_INSTANCE_DIR}"
56
cat >Dockerfile <<EOF
H
haosanzi 已提交
57
FROM centos:8.1.1911
58

H
haosanzi 已提交
59
RUN mkdir -p /run/rune
60 61
WORKDIR /run/rune

H
haosanzi 已提交
62 63 64 65
COPY Occlum.json ./
COPY build ./build
COPY image ./image
COPY run ./run
66 67 68 69 70 71 72 73 74 75 76 77

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

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

---

H
haosanzi 已提交
78 79
## Install SGX SDK and SGX PSW
Please follow [Intel SGX Installation Guide](https://download.01.org/intel-sgx/sgx-linux/2.9.1/docs/Intel_SGX_Installation_Guide_Linux_2.9.1_Open_Source.pdf) to install SGX SDK and SGX PSW.
80

H
haosanzi 已提交
81
In additon, UAE service libraries are needed but may not installed together with SGX PSW if SGX PSW installer is used. Go to SGX RPM local repo and run:
82

jia zhang's avatar
jia zhang 已提交
83
```shell
H
haosanzi 已提交
84
rpm -i libsgx-uae-service-2.9.101.2-1.el8.x86_64.rpm
85 86
```

H
haosanzi 已提交
87
## Install rune and occlum-pal
88
Download the package from [here](https://github.com/alibaba/inclavare-containers/releases/).
H
haosanzi 已提交
89 90

- On CentOS 8.1:
91
```shell
92
yum install -y libseccomp
H
haosanzi 已提交
93 94
rpm -ivh rune-0.4.0-1.el8.x86_64.rpm
rpm -ivh occlum-pal-0.15.1-1.el8.x86_64.rpm
95 96
```
- On Ubuntu 18.04-server:
jia zhang's avatar
jia zhang 已提交
97
```shell
H
haosanzi 已提交
98
dpkg -i rune_0.4.0-1_amd64.deb
99
dpkg -i occlum-pal_0.15.1-1_amd64.deb
jia zhang's avatar
jia zhang 已提交
100 101
```

102 103
---

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

jia zhang's avatar
jia zhang 已提交
107
```JSON
108 109 110
{
	"runtimes": {
		"rune": {
111
			"path": "/usr/bin/rune",
112 113 114 115 116 117
			"runtimeArgs": []
		}
	}
}
```

jia zhang's avatar
jia zhang 已提交
118
then restart dockerd on your system.
119

jia zhang's avatar
jia zhang 已提交
120 121 122
You can check whether `rune` is correctly added to OCI runtime or not with
```shell
docker info | grep rune
123 124 125 126 127 128 129 130
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 已提交
131
```shell
132 133
docker run -it --rm --runtime=rune \
  -e ENCLAVE_TYPE=intelSgx \
H
haosanzi 已提交
134 135
  -e ENCLAVE_RUNTIME_PATH=/opt/occlum/build/lib/libocclum-pal.so.0.15.1 \
  -e ENCLAVE_RUNTIME_ARGS=./ \
136 137 138 139 140
  ${Occlum_application_image}
```

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