Skip to content

Commit dd65737

Browse files
committed
Dockerfile: add debian package build
Updated README Also revert aesm docker to run as root inside This was to ensure access to /dev/sgx_provision Signed-off-by: Haitao Huang <4699115+haitaohuang@users.noreply.github.com>
1 parent 0af6a83 commit dd65737

File tree

5 files changed

+140
-10
lines changed

5 files changed

+140
-10
lines changed

docker/build/Dockerfile

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ RUN apt-get update && apt-get install -y \
4747
ocamlbuild \
4848
protobuf-compiler \
4949
python \
50+
reprepro \
5051
wget
5152

5253
# We assume this docker file is invoked with root at the top of linux-sgx repo, see shell scripts for example.
@@ -61,6 +62,7 @@ RUN sh -c 'echo yes | /linux-sgx/linux/installer/bin/sgx_linux_x64_sdk_*.bin'
6162
WORKDIR /linux-sgx
6263
RUN make psw_install_pkg
6364

65+
RUN make deb_local_repo
6466

6567
FROM ubuntu:18.04 as aesm
6668
RUN apt-get update && apt-get install -y \
@@ -73,11 +75,29 @@ RUN apt-get update && apt-get install -y \
7375
WORKDIR /installer
7476
COPY --from=builder /linux-sgx/linux/installer/bin/*.bin ./
7577
RUN ./sgx_linux_x64_psw*.bin --no-start-aesm
76-
USER aesmd
7778
WORKDIR /opt/intel/sgxpsw/aesm/
7879
ENV LD_LIBRARY_PATH=.
7980
CMD ./aesm_service --no-daemon
8081

82+
FROM ubuntu:18.04 as aesm_deb
83+
RUN apt-get update && apt-get install -y \
84+
libcurl4 \
85+
libprotobuf10 \
86+
libssl1.1 \
87+
make \
88+
module-init-tools
89+
90+
WORKDIR /deb_local_repo
91+
92+
COPY --from=builder /linux-sgx/linux/installer/deb/sgx_debian_local_repo/ ./
93+
RUN echo "deb [trusted=yes arch=amd64] file:///deb_local_repo bionic main">>/etc/apt/sources.list
94+
RUN apt-get update
95+
RUN apt-get install -y libsgx-aesm-launch-plugin libsgx-aesm-quote-ex-plugin
96+
97+
WORKDIR /opt/intel/sgx-aesm-service/aesm/
98+
ENV LD_LIBRARY_PATH=.
99+
CMD ./aesm_service --no-daemon
100+
81101

82102
FROM ubuntu:18.04 as sample
83103
RUN apt-get update && apt-get install -y \
@@ -101,3 +121,32 @@ USER sgxuser
101121

102122
CMD ./app
103123

124+
125+
FROM ubuntu:18.04 as sample_deb
126+
RUN apt-get update && apt-get install -y \
127+
g++ \
128+
libcurl4-openssl-dev \
129+
libprotobuf-dev \
130+
libssl-dev \
131+
make \
132+
module-init-tools
133+
134+
WORKDIR /deb_local_repo
135+
136+
COPY --from=builder /linux-sgx/linux/installer/deb/sgx_debian_local_repo/ ./
137+
RUN echo "deb [trusted=yes arch=amd64] file:///deb_local_repo bionic main">>/etc/apt/sources.list
138+
RUN apt-get update
139+
RUN apt-get install -y libsgx-urts
140+
141+
WORKDIR /opt/intel
142+
COPY --from=builder /linux-sgx/linux/installer/bin/*.bin ./
143+
RUN sh -c 'echo yes | ./sgx_linux_x64_sdk_*.bin'
144+
145+
WORKDIR /opt/intel/sgxsdk/SampleCode/SampleEnclave
146+
RUN SGX_DEBUG=0 SGX_MODE=HW SGX_PRERELEASE=1 make
147+
148+
RUN adduser -q --disabled-password --gecos "" --no-create-home sgxuser
149+
USER sgxuser
150+
151+
CMD ./app
152+

docker/build/README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,27 @@ $ ./build_and_run_sample_docker.sh
3333

3434
## Dockerfile
3535

36-
The Dockerfile specifies 3 image build targets:
37-
1. builder: Builds PSW and SDK bin installers from source. This requires downloading the prebuilt AEs and optimized libs from 01.org.
38-
2. aesm: Takes the PSW installer from builder to install and run the AESM daemon.
39-
3. sample: Installs the SDK installer from builder, then builds and runs the SampleEnclave app
36+
The Dockerfile specifies 5 image build targets:
37+
1. builder: Builds PSW and SDK bin and debian installers from source.
38+
2. aesm: Takes the PSW bin installer from builder to install and run the AESM daemon.
39+
3. sample: Installs the SDK installer and the PSW bin installer from builder. Then builds and runs the SampleEnclave app
40+
4. aesm_deb: Takes the PSW debian installer from builder to install and run the AESM daemon.
41+
5. sample_deb: Takes the SDK installer and the PSW debian installer from builder to install. Then builds and runs the SampleEnclave app.
4042

4143
- [build_and_run_aesm_docker.sh](./build_and_run_aesm_docker.sh): Shows how to build and run the AESM image in Docker. This will start the AESM service listening to a named socket, located in /var/run/aesmd in the container and mounted in Docker volume aesmd-socket.
42-
44+
- [build_and_run_aesm_deb_docker.sh](./build_and_run_aesm_deb_docker.sh): Same as above, but with the debian packages for PSW and DCAP.
4345
- [build_and_run_sample_docker.sh](./build_and_run_sample_docker.sh): Shows how to build and run the SampleEnclave app inside a Docker container with a locally built SGX sample image.
46+
- [build_and_run_sample_deb_docker.sh](./build_and_run_sample_deb_docker.sh): Same as above, but with the debian packages for PSW.
4447

4548
## Legacy Launch Control driver and kernel for SGX
4649

4750
All SGX applications need access to the SGX device nodes exposed by the kernel space driver. Depending on the driver or kernel you are using, the SGX device nodes may have different names and locations. Therefore, you need to ensure those nodes are mapped and mounted inside the containers properly.
4851

4952

50-
[SGX kernel patches](https://github.com/jsakkine-intel/linux-sgx/commits/master) are still in process of upstreaming.
51-
The [Flexible Launch Control driver](https://github.com/intel/SGXDataCenterAttestationPrimitives/tree/master/driver) is developed to imitate the kernel patches as closely as possible.
53+
[SGX kernel patches](https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/log/?h=x86/sgx) are upstream now and included in main line kernel release 5.11 or later.
54+
The [Flexible Launch Control driver](https://github.com/intel/SGXDataCenterAttestationPrimitives/tree/master/driver) is developed to imitate the kernel patches as closely as possible. It can be used for distros with kernels older than 5.11.
5255

53-
The sample scripts and Compose files are compatible with the Flexible Launch Control driver or a custom built kernel with SGX support. If you need to use the Legacy Launch Control driver then you need to make following modifications:
56+
The sample scripts and Compose files are compatible with the Flexible Launch Control driver or a custom built kernel with SGX support. To use the Legacy Launch Control driver, make following modifications:
5457
1. Replace "/dev/sgx/enclave" device with "/dev/isgx" and **remove** "/dev/sgx/provision" device for AESM in docker-compose.yml and build_and_run_aesm_docker.sh
5558
2. Replace "/dev/sgx/enclave" with "/dev/isgx" for the sample container in docker-compose.yml and build_and_run_sample_docker.sh
5659

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (C) 2022 Intel Corporation. All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions
7+
# are met:
8+
#
9+
# * Redistributions of source code must retain the above copyright
10+
# notice, this list of conditions and the following disclaimer.
11+
# * Redistributions in binary form must reproduce the above copyright
12+
# notice, this list of conditions and the following disclaimer in
13+
# the documentation and/or other materials provided with the
14+
# distribution.
15+
# * Neither the name of Intel Corporation nor the names of its
16+
# contributors may be used to endorse or promote products derived
17+
# from this software without specific prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
#
31+
32+
set -e
33+
docker build --target aesm_deb --build-arg https_proxy=$https_proxy \
34+
--build-arg http_proxy=$http_proxy -t sgx_aesm_deb -f ./Dockerfile ../../
35+
36+
docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=rw aesmd-socket
37+
38+
# If you use the Legacy Launch Control driver, replace /dev/sgx/enclave with /dev/isgx, and remove
39+
# --device=/dev/sgx/provision
40+
41+
docker run --env http_proxy --env https_proxy --device=/dev/sgx/enclave --device=/dev/sgx/provision -v /dev/log:/dev/log -v aesmd-socket:/var/run/aesmd -it sgx_aesm_deb
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (C) 2022 Intel Corporation. All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions
7+
# are met:
8+
#
9+
# * Redistributions of source code must retain the above copyright
10+
# notice, this list of conditions and the following disclaimer.
11+
# * Redistributions in binary form must reproduce the above copyright
12+
# notice, this list of conditions and the following disclaimer in
13+
# the documentation and/or other materials provided with the
14+
# distribution.
15+
# * Neither the name of Intel Corporation nor the names of its
16+
# contributors may be used to endorse or promote products derived
17+
# from this software without specific prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
#
31+
32+
set -e
33+
docker build --target sample_deb --build-arg https_proxy=$https_proxy \
34+
--build-arg http_proxy=$http_proxy -t sgx_sample_deb -f ./Dockerfile ../../
35+
36+
# Another container should expose AESM and its socket in aesmd-socket volume.
37+
# Replace /dev/sgx/enclave with /dev/isgx if you use the Legacy Launch Control driver
38+
docker run --env http_proxy --env https_proxy --device=/dev/sgx/enclave -v aesmd-socket:/var/run/aesmd -it sgx_sample_deb

linux/installer/docker/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ RUN apt-get install -y \
7777
# More aesm plugins, e.g libsgx-aesm-quote-ex-plugin, are needed if application requires attestation. See installation guide.
7878
RUN apt-get install -y libsgx-aesm-launch-plugin
7979

80-
USER aesmd
8180
WORKDIR /opt/intel/sgx-aesm-service/aesm
8281
ENV LD_LIBRARY_PATH=.
8382
CMD ./aesm_service --no-daemon

0 commit comments

Comments
 (0)