-
Notifications
You must be signed in to change notification settings - Fork 20
/
Dockerfile.nitro
257 lines (219 loc) · 7.27 KB
/
Dockerfile.nitro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# This dockerfile is taken from https://github.com/aws/aws-nitro-enclaves-acm/blob/main/env/enclave/Dockerfile
# Modified to help build tmkms-nitro-enclave eif
# Copyright 2020-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# Modifications Copyright (c) 2021-present Crypto.com (licensed under the Apache License, Version 2.0)
# SPDX-License-Identifier: Apache-2.0
# This Docker file sets up the development environment for the eVault components
# that live inside the enclave.
# Note: this is not the container image used to generate the final enclave image,
# but a somewhat dependency-heavy dev-time environment. The enclave image
# source container will start from scratch, cherry-picking only its
# required run-time dependencies from here.
FROM alpine:3.12 as build_env
ARG RUST_TOOLCHAIN
# Force Rust dynamic linking against the Alpine-default musl libc.
ENV RUSTFLAGS="-C target-feature=-crt-static"
# Install system dependencies / packages.
RUN apk add \
p11-kit-server \
ca-certificates \
cmake \
g++ \
gcc \
git \
go \
perl \
curl \
make \
linux-headers \
shadow \
sudo
RUN ln -s /usr/lib /usr/lib64
RUN mkdir -p /build
WORKDIR /build
# Build AWS libcrypto
ENV AWS_LC_VER="v1.0.2"
RUN git clone "https://github.com/awslabs/aws-lc.git" \
&& cd aws-lc \
&& git reset --hard $AWS_LC_VER \
&& cmake \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build/ --parallel $(nproc) --target crypto \
&& mv build/crypto/libcrypto.so /usr/lib/ \
&& cp -rf include/openssl /usr/include/ \
&& ldconfig /usr/lib
# AWS-S2N
ENV AWS_S2N_VER="v1.3.11"
RUN git clone https://github.com/aws/s2n-tls.git \
&& cd s2n-tls \
&& git reset --hard $AWS_S2N_VER \
&& cmake \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build/ --parallel $(nproc) --target install
# AWS-C-COMMON
ENV AWS_C_COMMON_VER="v0.6.20"
RUN git clone https://github.com/awslabs/aws-c-common.git \
&& cd aws-c-common \
&& git reset --hard $AWS_C_COMMON_VER \
&& cmake \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build/ --parallel $(nproc) --target install
# AWS-C-SDKUTILS
ENV AWS_C_SDKUTILS_VER="v0.1.2"
RUN git clone https://github.com/awslabs/aws-c-sdkutils \
&& cd aws-c-sdkutils \
&& git reset --hard $AWS_C_SDKUTILS_VER \
&& cmake \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build/ --parallel $(nproc) --target install
# AWS-C-CAL
ENV AWS_C_CAL_VER="v0.5.17"
RUN git clone https://github.com/awslabs/aws-c-cal.git \
&& cd aws-c-cal \
&& git reset --hard $AWS_C_CAL_VER \
&& cmake \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build --parallel $(nproc) --target install
# AWS-C-IO
ENV AWS_C_IO_VER="v0.10.21"
RUN git clone https://github.com/awslabs/aws-c-io.git \
&& cd aws-c-io \
&& git reset --hard $AWS_C_IO_VER \
&& cmake \
-DUSE_VSOCK=1 \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build/ --parallel $(nproc) --target install
# AWS-C-COMPRESSION
ENV AWS_C_COMPRESSION_VER="v0.2.14"
RUN git clone http://github.com/awslabs/aws-c-compression.git \
&& cd aws-c-compression \
&& git reset --hard $AWS_C_COMPRESSION_VER \
&& cmake \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build --parallel $(nproc) --target install
# AWS-C-HTTP
ENV AWS_C_HTTP_VER="v0.6.13"
RUN git clone https://github.com/awslabs/aws-c-http.git \
&& cd aws-c-http \
&& git reset --hard $AWS_C_HTTP_VER \
&& cmake \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build --parallel $(nproc) --target install
# AWS-C-AUTH
ENV AWS_C_AUTH_VER="v0.6.11"
RUN git clone https://github.com/awslabs/aws-c-auth.git \
&& cd aws-c-auth \
&& git reset --hard $AWS_C_AUTH_VER \
&& cmake \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build --parallel $(nproc) --target install
# JSON-C library
ENV JSON_C_VER="json-c-0.16-20220414"
RUN git clone https://github.com/json-c/json-c.git \
&& cd json-c \
&& git reset --hard $JSON_C_VER \
&& cmake \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build --parallel $(nproc) --target install
# Install Rust
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUST_TOOLCHAIN
# NSM LIB
ENV AWS_NE_NSM_API_VER="v0.2.1"
RUN git clone "https://github.com/aws/aws-nitro-enclaves-nsm-api" \
&& cd aws-nitro-enclaves-nsm-api \
&& git reset --hard $AWS_NE_NSM_API_VER \
&& PATH="$PATH:/root/.cargo/bin" cargo build --release -p nsm-lib \
&& mv target/release/libnsm.so /usr/lib/ \
&& mv target/release/nsm.h /usr/include/
# AWS Nitro Enclaves SDK
ENV AWS_NE_SDK_VER="v0.2.1"
RUN git clone "https://github.com/aws/aws-nitro-enclaves-sdk-c" \
&& cd aws-nitro-enclaves-sdk-c \
&& git reset --hard $AWS_NE_SDK_VER \
&& cmake \
-DCMAKE_PREFIX_PATH=/usr \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_SHARED_LIBS=1 \
-DBUILD_TESTING=0 \
-B build \
&& cmake --build build --target install --parallel $(nproc)
ENV PATH="/root/.cargo/bin:$PATH"
FROM build_env as builder
WORKDIR /tmkms-light
USER root
COPY . .
RUN cargo build \
--target=x86_64-unknown-linux-musl \
--package tmkms-nitro-enclave \
--release \
&& cp target/x86_64-unknown-linux-musl/release/tmkms-nitro-enclave /usr/bin/tmkms-nitro-enclave
WORKDIR /rootfs
# Collect eVault lib deps
RUN BINS="\
/usr/bin/tmkms-nitro-enclave \
" && \
for bin in $BINS; do \
{ echo "$bin"; ldd "$bin" | grep -Eo "/.*lib.*/[^ ]+"; } | \
while read path; do \
mkdir -p ".$(dirname $path)"; \
cp -fL "$path" ".$path"; \
strip --strip-unneeded ".$path"; \
done \
done
RUN mkdir -p /rootfs/etc/ssl/certs \
&& cp -f /etc/ssl/certs/ca-certificates.crt /rootfs/etc/ssl/certs/
RUN mkdir -p /rootfs/bin/
RUN find /rootfs
FROM alpine:3.13
ARG USER=default
ENV HOME /home/$USER
# install sudo as root
RUN apk add --update sudo
# add new user
RUN adduser -D $USER \
&& echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER \
&& chmod 0440 /etc/sudoers.d/$USER
USER $USER
WORKDIR $HOME
COPY --from=builder /rootfs /
CMD ["/usr/bin/tmkms-nitro-enclave"]