Skip to content

Commit 77b2a24

Browse files
committed
docker: use a volume for sharing the aesmd socket.
When sharing aesmd socket between two Docker containers, use a dedicated volume instead of tmp directory on the host.
1 parent 985cd0a commit 77b2a24

9 files changed

+19
-40
lines changed

docker/build/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The Dockerfile specifies 3 image build targets:
3434
2. aesm: Takes the PSW installer from builder to install and run the AESM daemon.
3535
3. sample: Installs the SDK installer from builder, then builds and runs the SampleEnclave app
3636

37-
- [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, mounted in /var/run/aesmd in the container from the host /tmp/aesmd.
37+
- [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.
3838

3939
- [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.
4040

docker/build/build_and_run_aesm_docker.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@ set -e
3333
docker build --target aesm --build-arg https_proxy=$https_proxy \
3434
--build-arg http_proxy=$http_proxy -t sgx_aesm -f ./Dockerfile ../../
3535

36-
# Create a temporary directory on the host that is mounted
37-
# into both the AESM and sample containers at /var/run/aesmd
38-
# so that the AESM socket is visible to the sample container
39-
# in the expected location. It is critical that /tmp/aesmd is
40-
# world writable as the UIDs may shift in the container.
41-
mkdir -p -m 777 /tmp/aesmd
42-
chmod -R -f 777 /tmp/aesmd || sudo chmod -R -f 777 /tmp/aesmd || true
36+
docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=rw aesmd-socket
4337

4438
# If you use the Legacy Launch Control driver, replace /dev/sgx/enclave with /dev/isgx, and remove
4539
# --device=/dev/sgx/provision
4640

47-
docker run --env http_proxy --env https_proxy --device=/dev/sgx/enclave --device=/dev/sgx/provision -v /dev/log:/dev/log -v /tmp/aesmd:/var/run/aesmd -it sgx_aesm
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

docker/build/build_and_run_sample_docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ set -e
3333
docker build --target sample --build-arg https_proxy=$https_proxy \
3434
--build-arg http_proxy=$http_proxy -t sgx_sample -f ./Dockerfile ../../
3535

36-
# Another container should expose AESM and its socket
36+
# Another container should expose AESM and its socket in aesmd-socket volume.
3737
# 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 /tmp/aesmd:/var/run/aesmd -it sgx_sample
38+
docker run --env http_proxy --env https_proxy --device=/dev/sgx/enclave -v aesmd-socket:/var/run/aesmd -it sgx_sample

docker/build/build_compose_run.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,5 @@ docker build --target aesm --build-arg https_proxy=$https_proxy \
3636
docker build --target sample --build-arg https_proxy=$https_proxy \
3737
--build-arg http_proxy=$http_proxy -t sgx_sample -f ./Dockerfile ../../
3838

39-
# Create a temporary directory on the host that is mounted
40-
# into both the AESM and sample containers at /var/run/aesmd
41-
# so that the AESM socket is visible to the sample container
42-
# in the expected location. It is critical that /tmp/aesmd is
43-
# world writable as the UIDs may shift in the container.
44-
45-
mkdir -p -m 777 /tmp/aesmd
46-
chmod -R -f 777 /tmp/aesmd || sudo chmod -R -f 777 /tmp/aesmd || true
39+
docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=rw aesmd-socket
4740
docker-compose --verbose up

docker/build/docker-compose.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ services:
3939
- /dev/sgx/enclave
4040
- /dev/sgx/provision
4141
volumes:
42-
- /tmp/aesmd:/var/run/aesmd
42+
- aesmd-socket:/var/run/aesmd
4343
stdin_open: true
4444
tty: true
4545
environment:
@@ -53,10 +53,12 @@ services:
5353
devices:
5454
- /dev/sgx/enclave
5555
volumes:
56-
- /tmp/aesmd:/var/run/aesmd
56+
- aesmd-socket:/var/run/aesmd
5757
stdin_open: true
5858
tty: true
5959
environment:
6060
- http_proxy
6161
- https_proxy
6262

63+
volumes:
64+
aesmd-socket:

linux/installer/docker/build_and_run_aesm_docker.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,8 @@ set -e
3333
docker build --target aesm --build-arg https_proxy=$https_proxy \
3434
--build-arg http_proxy=$http_proxy -t sgx_aesm -f ./Dockerfile ./
3535

36-
# Create a temporary directory on the host that is mounted
37-
# into both the AESM and sample containers at /var/run/aesmd
38-
# so that the AESM socket is visible to the sample container
39-
# in the expected location. It is critical that /tmp/aesmd is
40-
# world writable as the UIDs may shift in the container.
41-
mkdir -p -m 777 /tmp/aesmd
42-
chmod -R -f 777 /tmp/aesmd || sudo chmod -R -f 777 /tmp/aesmd || true
36+
docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=rw aesmd-socket
4337

4438
# If you use the Legacy Launch Control driver, replace /dev/sgx/enclave with /dev/isgx, and remove
4539
# --device=/dev/sgx/provision
46-
docker run --env http_proxy --env https_proxy --device=/dev/sgx/enclave --device=/dev/sgx/provision -v /dev/log:/dev/log -v /tmp/aesmd:/var/run/aesmd -it sgx_aesm
40+
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

linux/installer/docker/build_and_run_sample_docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ set -e
3333
docker build --target sample --build-arg https_proxy=$https_proxy \
3434
--build-arg http_proxy=$http_proxy -t sgx_sample -f ./Dockerfile ./
3535

36-
# Another container should expose AESM and its socket
36+
# Another container should expose AESM and its socket in volume aesmd-socket
3737
# 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 /tmp/aesmd:/var/run/aesmd -it sgx_sample
38+
docker run --env http_proxy --env https_proxy --device=/dev/sgx/enclave -v aesmd-socket:/var/run/aesmd -it sgx_sample

linux/installer/docker/build_compose_run.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ docker build --target aesm --build-arg https_proxy=$https_proxy \
3636
docker build --target sample --build-arg https_proxy=$https_proxy \
3737
--build-arg http_proxy=$http_proxy -t sgx_sample -f ./Dockerfile ./
3838

39-
# Create a temporary directory on the host that is mounted
40-
# into both the AESM and sample containers at /var/run/aesmd
41-
# so that the AESM socket is visible to the sample container
42-
# in the expected location. It is critical that /tmp/aesmd is
43-
# world writable as the UIDs may shift in the container.
39+
docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=rw aesmd-socket
4440

45-
mkdir -p -m 777 /tmp/aesmd
46-
chmod -R -f 777 /tmp/aesmd || sudo chmod -R -f 777 /tmp/aesmd || true
4741
docker-compose --verbose up

linux/installer/docker/docker-compose.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ services:
3939
- /dev/sgx/enclave
4040
- /dev/sgx/provision
4141
volumes:
42-
- /tmp/aesmd:/var/run/aesmd
42+
- aesmd-socket:/var/run/aesmd
4343
stdin_open: true
4444
tty: true
4545
environment:
@@ -53,10 +53,12 @@ services:
5353
devices:
5454
- /dev/sgx/enclave
5555
volumes:
56-
- /tmp/aesmd:/var/run/aesmd
56+
- aesmd-socket:/var/run/aesmd
5757
stdin_open: true
5858
tty: true
5959
environment:
6060
- http_proxy
6161
- https_proxy
6262

63+
volumes:
64+
aesmd-socket:

0 commit comments

Comments
 (0)