Skip to content

Commit e640eb6

Browse files
author
Dmitrii Kuvaiskii
committed
WIP Add support for Gramine-TDX
Currently only Gramine-VM. I'll update with Gramine-TDX in the next iteration. Need to think how to automatically start socat for virtio-vsock networking. Signed-off-by: Dmitrii Kuvaiskii <[email protected]>
1 parent 45eeba0 commit e640eb6

File tree

6 files changed

+62
-1
lines changed

6 files changed

+62
-1
lines changed

templates/Dockerfile.common.compile.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ RUN mkdir -p /gramine/driver/asm \
2929
RUN cd /gramine \
3030
&& meson setup build/ --prefix="/gramine/meson_build_output" \
3131
--buildtype={{buildtype}} \
32-
-Ddirect=enabled -Dsgx=enabled \
32+
-Ddirect=enabled -Dsgx=enabled -Dvm=enabled \
3333
{% if Distro.startswith('ubuntu') %}-Ddcap=enabled{% endif %} \
3434
{% if "linux-sgx-driver" in SGXDriver.Repository %} \
3535
-Dsgx_driver=oot -Dsgx_driver_include_path=/gramine/driver \

templates/apploader.common.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ then
1414
exec gramine-sgx /gramine/app_files/entrypoint \
1515
{% if insecure_args %}{{ binary_arguments | map('shlex_quote') | join(' ') }} \
1616
"${@}"{% endif %}
17+
elif [ "$GSC_PAL" == "VM" ]
18+
then
19+
exec gramine-vm /gramine/app_files/entrypoint \
20+
{% if insecure_args %}{{ binary_arguments | map('shlex_quote') | join(' ') }} \
21+
"${@}"{% endif %}
1722
else
1823
exec gramine-direct /gramine/app_files/entrypoint \
1924
{{ binary_arguments | map('shlex_quote') | join(' ') }} "${@}"

templates/debian/Dockerfile.build.template

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
# Combine all installation and removal steps in a single RUN command to reduce the final image size.
66
# This is because each Dockerfile command creates a new layer which necessarily adds size to the
77
# final image. This trick allows to decrease the image size by hundreds of MBs.
8+
#
9+
# For Gramine-TDX, need socat and virtiofsd. The former can be installed in Ubuntu 22.04 and later
10+
# (we need at least v1.7.4). The latter can't be installed in most Ubuntu versions, so install
11+
# manually by downloading the zip archive and copying.
812
RUN apt-get update \
913
&& env DEBIAN_FRONTEND=noninteractive apt-get install -y \
1014
binutils \
@@ -14,8 +18,13 @@ RUN apt-get update \
1418
python3 \
1519
python3-cryptography \
1620
python3-protobuf \
21+
python3-psutil \
1722
python3-pyelftools \
1823
python3-voluptuous \
24+
qemu-kvm \
25+
socat \
26+
unzip \
27+
wget \
1928
# Debian 12 and Ubuntu 23.04 adopted PEP 668, which dictates that `pip` can no longer install
2029
# packages managed by the distro's general-purpose package manager, hence we use `apt-get`
2130
{%- if (distro[0] == "debian" and distro[1] | int >= 12) or
@@ -34,6 +43,18 @@ RUN apt-get update \
3443
&& apt-get autoremove -y \
3544
&& rm -rf /var/lib/apt/lists/*
3645

46+
RUN ln -s /usr/bin/qemu-system-x86_64 /usr/local/bin/qemu
47+
48+
RUN mkdir -p /gramine/virtiofsd \
49+
&& mkdir -p /usr/local/bin \
50+
&& cd /gramine/virtiofsd \
51+
&& wget --timeout=10 -O virtiofsd.zip \
52+
https://gitlab.com/virtio-fs/virtiofsd/uploads/2cf9068046720699531407101f2bcb60/virtiofsd-v1.10.1.zip \
53+
&& sha256sum virtiofsd.zip | grep -q 8166b47d80ed16cc6df4bfd350063e98f70039a212d10cc5c1ea99251dbd2945 \
54+
&& unzip virtiofsd.zip \
55+
&& cp target/x86_64-unknown-linux-musl/release/virtiofsd /usr/local/bin/ \
56+
&& rm virtiofsd.zip
57+
3758
{% if buildtype != "release" %}
3859
RUN apt-get update \
3960
&& env DEBIAN_FRONTEND=noninteractive apt-get install -y \

test/README.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,32 @@ version of the Intel SGX driver if needed):
4444
docker run --device=/dev/sgx_enclave \
4545
-v /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket \
4646
gsc-ubuntu20.04-bash -c ls
47+
48+
Building for Gramine-TDX
49+
------------------------
50+
51+
Note that we need at least Ubuntu 22.04.
52+
53+
.. code-block:: sh
54+
55+
docker build --tag ubuntu22.04-hello-world --file test/ubuntu22.04-hello-world.dockerfile .
56+
57+
./gsc build --buildtype debug ubuntu22.04-hello-world test/ubuntu22.04-hello-world.manifest
58+
./gsc sign-image ubuntu22.04-hello-world enclave-key.pem
59+
60+
docker run --env GSC_PAL=VM --security-opt seccomp=unconfined \
61+
--shm-size 4G --env GRAMINE_CPU_NUM=1 \
62+
--device=/dev/vhost-vsock:/dev/vhost-vsock \
63+
--device=/dev/kvm:/dev/kvm --group-add `getent group kvm | cut -d: -f3` \
64+
gsc-ubuntu22.04-hello-world
65+
# or to peek into the image
66+
docker run -it --entrypoint /bin/bash gsc-ubuntu22.04-hello-world
67+
68+
Note that in ``docker run``, we must specify the following:
69+
70+
- ``--shm-size 4G`` -- our QEMU/KVM uses ``/dev/shm`` for virtio-fs shared
71+
memory. However, Docker containers start with 64MB by default. Thus, we need
72+
to explicitly specify the shared memory limit. ``4G`` is just an example; this
73+
limit depends on the app running inside Gramine-TDX.
74+
- ``--env GRAMINE_CPU_NUM=1`` -- this instructs QEMU to spawn a Gramine-TDX VM
75+
with 1 vCPU. Modify this to have more vCPUs.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM ubuntu:22.04
2+
3+
RUN apt-get update
4+
5+
CMD ["echo", "\"Hello World! Let's check escaped symbols: < & > \""]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# intentionally left empty so that GSC uses default manifest options

0 commit comments

Comments
 (0)