README.md 4.3 KB
Newer Older
jia zhang's avatar
jia zhang 已提交
1 2
The files in this directory are used to implement a skeleton enclave runtime in order to help to write your own enclave runtime.

3 4
Note that this code base is inspired by [v28 SGX in-tree driver](https://patchwork.kernel.org/patch/11418925/).

jia zhang's avatar
jia zhang 已提交
5
---
6

7 8
# Run skeleton with Docker
## Install sgx-tools
9
Refer to [this guide](https://github.com/alibaba/inclavare-containers/tree/master/sgx-tools/README.md).
jia zhang's avatar
jia zhang 已提交
10

11
Note that this step is only required when using SGX out-of-tree driver.
12

13
## Build liberpal-skeleton
14
```shell
15 16
cd "${path_to_inclavare_containers}/rune/libenclave/internal/runtime/pal/skeleton"
make
17
cp liberpal-skeleton-v*.so /usr/lib
18
```
19
Debug enclave is generated by default. Please use `make PRODUCT_ENCLAVE=1` command to generate production enclave.
20

21
## Build skeleton container image
22
```shell
23
cd "${path_to_inclavare_containers}/rune/libenclave/internal/runtime/pal/skeleton"
24
cat >Dockerfile <<EOF
H
haosanzi 已提交
25
FROM centos:8.1.1911
26 27 28 29

RUN mkdir -p /run/rune
WORKDIR /run/rune

30 31 32
COPY encl.bin .
COPY encl.elf .
COPY encl.ss .
33
# if any
34
COPY encl.token .
35
EOF
jia zhang's avatar
jia zhang 已提交
36
docker build . -t skeleton-enclave
37 38
```

39 40
[Skeleton container image](https://hub.docker.com/r/inclavarecontainers/skeleton-enclave/tags) is available for the demonstration purpose.

41
## Build and install rune
42 43
Please refer to [this guide](https://github.com/alibaba/inclavare-containers#rune) to build `rune` from scratch.

jia zhang's avatar
jia zhang 已提交
44 45 46 47 48
---

# Run skeleton container image
## Configure OCI runtime
Add the `rune` OCI runtime configuration in dockerd config file, e.g, `/etc/docker/daemon.json`, in your system.
49

jia zhang's avatar
jia zhang 已提交
50
```json
51 52 53 54 55 56 57 58 59 60
{
	"runtimes": {
		"rune": {
			"path": "/usr/local/sbin/rune",
			"runtimeArgs": []
		}
	}
}
```

jia zhang's avatar
jia zhang 已提交
61
then restart dockerd on your system.
62 63
> e.g. `sudo systemctl restart docker` for CentOS, or `sudo service docker restart` for Ubuntu

jia zhang's avatar
jia zhang 已提交
64 65 66
You can check whether `rune` is correctly picked as supported OCI runtime or not with
```shell
docker info | grep rune
67 68 69
Runtimes: rune runc
```

jia zhang's avatar
jia zhang 已提交
70
## Run skeleton container image with rune
71 72
Note that replace `${SKELETON_PAL_VERSION}` with the actual version number. Currently skeleton supports PAL API v1 and v2.

73 74 75
```shell
docker run -it --rm --runtime=rune \
  -e ENCLAVE_TYPE=intelSgx \
76
  -e ENCLAVE_RUNTIME_PATH=/usr/lib/liberpal-skeleton-v${SKELETON_PAL_VERSION}.so \
77
  -e ENCLAVE_RUNTIME_ARGS="debug" \
jia zhang's avatar
jia zhang 已提交
78
  skeleton-enclave
79
```
80 81 82 83 84 85

where:
- @ENCLAVE_TYPE: specify the type of enclave hardware to use, such as `intelSgx`.
- @ENCLAVE_PATH: specify the path to enclave runtime to launch.
- @ENCLAVE_ARGS: specify the specific arguments to enclave runtime, seperated by the comma.

jia zhang's avatar
jia zhang 已提交
86 87
---

88
# Run skeleton OCI bundle
jia zhang's avatar
jia zhang 已提交
89 90
Note: The following method to launch skeleton with `rune` is usually provided for developmemt purpose.

91
## Create skeleton bundle
jia zhang's avatar
jia zhang 已提交
92
In order to use `rune` you must have your container image in the format of an OCI bundle. If you have Docker installed you can use its `export` method to acquire a root filesystem from an existing skeleton Docker container image.
93

jia zhang's avatar
jia zhang 已提交
94
```shell
95 96 97 98 99 100 101 102 103
# create the top most bundle directory
cd "$HOME/rune_workdir"
mkdir rune-container
cd rune-container

# create the rootfs directory
mkdir rootfs

# export skeleton image via Docker into the rootfs directory
jia zhang's avatar
jia zhang 已提交
104
docker export $(docker create skeleton-enclave) | sudo tar -C rootfs -xvf -
105 106 107 108
```

After a root filesystem is populated you just generate a spec in the format of a config.json file inside your bundle. `rune` provides a spec command which is similar to `runc` to generate a template file that you are then able to edit.

jia zhang's avatar
jia zhang 已提交
109
```shell
110 111 112 113 114 115
rune spec
```

To find features and documentation for fields in the spec please refer to the [specs](https://github.com/opencontainers/runtime-spec) repository.

In order to run the skeleton bundle with `rune`, you need to configure enclave runtime as following:
jia zhang's avatar
jia zhang 已提交
116
```json
117 118
  "annotations": {
      "enclave.type": "intelSgx",
119
      "enclave.runtime.path": "/usr/lib/liberpal-skeleton-v${SKELETON_PAL_VERSION}.so",
120 121 122 123 124 125 126 127 128
      "enclave.runtime.args": "debug"
  }
```

where:
- @enclave.type: specify the type of enclave hardware to use, such as intelSgx.
- @enclave.runtime.path: specify the path to enclave runtime to launch.
- @enclave.runtime.args: specify the specific arguments to enclave runtime, seperated by the comma.

jia zhang's avatar
jia zhang 已提交
129
## Run skeleton
130 131
Assuming you have an OCI bundle from the previous step you can execute the container in this way.

jia zhang's avatar
jia zhang 已提交
132
```shell
133
cd "$HOME/rune_workdir/rune-container"
jia zhang's avatar
jia zhang 已提交
134
sudo rune run skeleton-enclave-container
135
```