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

---
4

5
# Install runectl
jia zhang's avatar
jia zhang 已提交
6 7 8
Refer to [this guide](https://github.com/alibaba/inclavare-containers/tree/master/runectl).

---
9

10 11
# Build liberpal-skeleton.so
```shell
12 13
cd "${path_to_inclavare_containers}/rune/libenclave/internal/runtime/pal/skeleton"
make
14
cp liberpal-skeletion.so /usr/lib
15 16
```

jia zhang's avatar
jia zhang 已提交
17 18 19
---

# Build skeleton container image
20
```shell
21
cd "${path_to_inclavare_containers}/rune/libenclave/internal/runtime/pal/skeleton"
22
cat >Dockerfile <<EOF
23
FROM centos:7.5.1804
24 25 26 27

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

28 29 30 31
COPY encl.bin .
COPY encl.elf .
COPY encl.ss .
COPY encl.token .
32
EOF
jia zhang's avatar
jia zhang 已提交
33
docker build . -t skeleton-enclave
34 35
```

jia zhang's avatar
jia zhang 已提交
36 37
---

38
# Build and install rune
39 40 41 42
`rune` is a CLI tool for spawning and running enclaves in containers according to the OCI specification.

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

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

# 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.
48

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

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

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

jia zhang's avatar
jia zhang 已提交
69
## Run skeleton container image with rune
70 71 72
```shell
docker run -it --rm --runtime=rune \
  -e ENCLAVE_TYPE=intelSgx \
73
  -e ENCLAVE_RUNTIME_PATH=/usr/lib/liberpal-skeleton.so \
74
  -e ENCLAVE_RUNTIME_ARGS="debug" \
jia zhang's avatar
jia zhang 已提交
75
  skeleton-enclave
76
```
77 78 79 80 81 82

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 已提交
83 84
---

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

88
## Create skeleton bundle
jia zhang's avatar
jia zhang 已提交
89
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.
90

jia zhang's avatar
jia zhang 已提交
91
```shell
92 93 94 95 96 97 98 99 100
# 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 已提交
101
docker export $(docker create skeleton-enclave) | sudo tar -C rootfs -xvf -
102 103 104 105
```

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 已提交
106
```shell
107 108 109 110 111 112
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 已提交
113
```json
114 115 116 117 118 119 120 121 122 123 124 125
  "annotations": {
      "enclave.type": "intelSgx",
      "enclave.runtime.path": "/usr/lib/liberpal-skeleton.so",
      "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 已提交
126
## Run skeleton
127 128
Assuming you have an OCI bundle from the previous step you can execute the container in this way.

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