feat: use nixsgx nix function to create containers

It refactors the way the SGX containers are built.
This removes all `Dockerfile` and gramine manifest files.
It also enables a single recipe for azure and non-azure variants.

Additionally the `teepot-crate.nix` is now the inherited recipe to
build the rust `teepot` crate.

Signed-off-by: Harald Hoyer <harald@matterlabs.dev>
This commit is contained in:
Harald Hoyer 2024-06-03 16:46:21 +02:00
parent 93e3e73d56
commit d0c5950c0e
Signed by: harald
GPG key ID: F519A1143B3FBE32
30 changed files with 337 additions and 897 deletions

View file

@ -1,19 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ lib
, inputs
, makeRustPlatform
, nixsgx
, pkg-config
, rust-bin
, pkgs
, callPackage
, ...
}@args:
let
teepotCrate = import ../teepot/teepot.nix args;
in
teepotCrate.craneLib.cargoClippy (
{ teepotCrate }: teepotCrate.craneLib.cargoClippy (
teepotCrate.commonArgs // {
pname = "teepot";
inherit (teepotCrate) cargoArtifacts NIX_OUTPATH_USED_AS_RANDOM_SEED;

View file

@ -1,19 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ lib
, inputs
, makeRustPlatform
, nixsgx
, pkg-config
, rust-bin
, pkgs
, callPackage
, ...
}@args:
let
teepotCrate = import ../teepot/teepot.nix args;
in
teepotCrate.craneLib.cargoDeny (
{ teepotCrate }: teepotCrate.craneLib.cargoDeny (
teepotCrate.commonArgs // {
pname = "teepot";
}

View file

@ -1,19 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ lib
, inputs
, makeRustPlatform
, nixsgx
, pkg-config
, rust-bin
, pkgs
, callPackage
, ...
}@args:
let
teepotCrate = import ../teepot/teepot.nix args;
in
teepotCrate.craneLib.cargoFmt (
{ teepotCrate }: teepotCrate.craneLib.cargoFmt (
teepotCrate.commonArgs // {
pname = "teepot";
}

View file

@ -1,23 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
FROM teepot-self-attestation-test-sgx-azure:base
WORKDIR /app
COPY packages/container-vault-sgx-azure/test-enclave-key.pem /tmp/
RUN set -eux; \
gramine-manifest -Darch_libdir=/lib/x86_64-linux-gnu \
-Dentrypoint=$(readlink /bin/tee-self-attestation-test) \
-Dexecdir=/bin \
-Dlog_level=error \
tee-self-attestation-test.manifest.toml tee-self-attestation-test.manifest; \
gramine-sgx-sign --manifest tee-self-attestation-test.manifest --output tee-self-attestation-test.manifest.sgx --key /tmp/test-enclave-key.pem; \
rm /tmp/test-enclave-key.pem
EXPOSE 8443
ENTRYPOINT ["/bin/sh", "-c"]
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt
CMD [ "[[ -r /var/run/aesmd/aesm.socket ]] || restart-aesmd >&2; exec gramine-sgx tee-self-attestation-test" ]

View file

@ -1,50 +1,35 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ pkgs
, nixsgx
, curl
{ lib
, pkgs
, inputs
, teepot
, bash
, coreutils
, openssl
, nixsgx
, container-name ? "teepot-self-attestation-test-sgx-azure"
, tag ? "latest"
, isAzure ? true
}:
let manifest = ./tee-self-attestation-test.manifest.toml;
in pkgs.dockerTools.buildLayeredImage {
name = "teepot-self-attestation-test-sgx-azure";
tag = "base";
pkgs.callPackage inputs.nixsgx-flake.lib.mkSGXContainer {
name = container-name;
inherit tag;
config.Entrypoint = [ "/bin/sh" "-c" ];
packages = [ teepot.teepot.tee_self_attestation_test ];
entrypoint = "${teepot.teepot.tee_self_attestation_test}/bin/tee-self-attestation-test";
contents = pkgs.buildEnv {
name = "image-root";
inherit isAzure;
paths = with pkgs.dockerTools; with nixsgx;[
bash
coreutils
openssl.out
azure-dcap-client
curl.out
teepot.teepot.tee_self_attestation_test
gramine
restart-aesmd
sgx-dcap.quote_verify
sgx-psw
usrBinEnv
binSh
caCertificates
fakeNss
];
pathsToLink = [ "/bin" "/lib" "/etc" "/share" "/app" ];
postBuild = ''
mkdir -p $out/{app,etc}
cp ${manifest} $out/app/tee-self-attestation-test.manifest.toml
mkdir -p $out/var/run
mkdir -p $out/${nixsgx.sgx-psw.out}/aesm/
touch $out/etc/sgx_default_qcnl.conf
mkdir -p $out/opt/vault/.cache $out/opt/vault/tls
ln -s ${curl.out}/lib/libcurl.so $out/${nixsgx.sgx-psw.out}/aesm/
ln -s ${nixsgx.azure-dcap-client.out}/lib/libdcap_quoteprov.so $out/${nixsgx.sgx-psw.out}/aesm/libdcap_quoteprov.so.1
printf "precedence ::ffff:0:0/96 100\n" > $out/etc/gai.conf
'';
manifest = {
loader = {
log_level = "error";
env = {
RUST_BACKTRACE = "1";
RUST_LOG = "warning";
};
};
sgx = {
edmm_enable = false;
enclave_size = "2G";
max_threads = 64;
};
};
}

View file

@ -1,56 +0,0 @@
libos.entrypoint = "{{ entrypoint }}"
[loader]
argv = ["{{ entrypoint }}"]
entrypoint = "file:{{ gramine.libos }}"
log_level = "{{ log_level }}"
[loader.env]
### DEBUG ###
RUST_BACKTRACE = "1"
RUST_LOG = "warning"
### Fixed values ###
LD_LIBRARY_PATH = "{{ gramine.runtimedir() }}:/lib"
SSL_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt"
PATH = "/bin"
HOME = "/app"
MALLOC_ARENA_MAX = "1"
AZDCAP_DEBUG_LOG_LEVEL = "ignore"
AZDCAP_COLLATERAL_VERSION = "v4"
[fs]
root.uri = "file:/"
start_dir = "/app"
mounts = [
{ type = "tmpfs", path = "/var/tmp" },
{ type = "tmpfs", path = "/tmp" },
{ type = "tmpfs", path = "/app/.dcap-qcnl" },
{ type = "tmpfs", path = "/app/.az-dcap-client" },
]
[sgx]
trusted_files = [
"file:/app/",
"file:/bin/",
"file:/etc/gai.conf",
"file:/etc/ssl/certs/ca-bundle.crt",
"file:/lib/",
"file:/nix/",
"file:{{ gramine.libos }}",
"file:{{ gramine.runtimedir() }}/",
]
remote_attestation = "dcap"
max_threads = 64
edmm_enable = false
## max enclave size
enclave_size = "2G"
[sys]
enable_extra_runtime_domain_names_conf = true
enable_sigterm_injection = true
# possible tweak option, if problems with mio
# currently mio is compiled with `mio_unsupported_force_waker_pipe`
# insecure__allow_eventfd = true

View file

@ -1,25 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
FROM teepot-self-attestation-test-sgx-dcap:base
WORKDIR /app
COPY packages/container-vault-sgx-azure/test-enclave-key.pem /tmp/
COPY assets/sgx_default_qcnl.conf.json /etc/sgx_default_qcnl.conf
RUN set -eux; \
touch -r /nix/store /etc/sgx_default_qcnl.conf; \
gramine-manifest -Darch_libdir=/lib/x86_64-linux-gnu \
-Dentrypoint=$(readlink /bin/tee-self-attestation-test) \
-Dexecdir=/bin \
-Dlog_level=error \
tee-self-attestation-test.manifest.toml tee-self-attestation-test.manifest; \
gramine-sgx-sign --manifest tee-self-attestation-test.manifest --output tee-self-attestation-test.manifest.sgx --key /tmp/test-enclave-key.pem; \
rm /tmp/test-enclave-key.pem
EXPOSE 8443
ENTRYPOINT ["/bin/sh", "-c"]
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt
CMD [ "[[ -r /var/run/aesmd/aesm.socket ]] || restart-aesmd >&2; exec gramine-sgx tee-self-attestation-test" ]

View file

@ -1,48 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ pkgs
, nixsgx
, curl
, teepot
, bash
, coreutils
, openssl
}:
let manifest = ./tee-self-attestation-test.manifest.toml;
in pkgs.dockerTools.buildLayeredImage {
name = "teepot-self-attestation-test-sgx-dcap";
tag = "base";
config.Entrypoint = [ "/bin/sh" "-c" ];
contents = pkgs.buildEnv {
name = "image-root";
paths = with pkgs.dockerTools; with nixsgx;[
bash
coreutils
openssl.out
curl.out
teepot.teepot.tee_self_attestation_test
gramine
restart-aesmd
sgx-dcap.quote_verify
sgx-dcap.default_qpl
sgx-psw
usrBinEnv
binSh
caCertificates
fakeNss
];
pathsToLink = [ "/bin" "/lib" "/etc" "/share" "/app" ];
postBuild = ''
mkdir -p $out/{app,etc}
mkdir -p $out/app/{.dcap-qcnl,.az-dcap-client}
mkdir -p $out/var/run
mkdir -p $out/${nixsgx.sgx-psw.out}/aesm/
ln -s ${curl.out}/lib/libcurl.so $out/${nixsgx.sgx-psw.out}/aesm/
cp ${manifest} $out/app/tee-self-attestation-test.manifest.toml
printf "precedence ::ffff:0:0/96 100\n" > $out/etc/gai.conf
'';
};
{ teepot }:
teepot.container-self-attestation-test-sgx-azure.override {
container-name = "teepot-self-attestation-test-sgx-dcap";
isAzure = false;
}

View file

@ -1,57 +0,0 @@
libos.entrypoint = "{{ entrypoint }}"
[loader]
argv = ["{{ entrypoint }}"]
entrypoint = "file:{{ gramine.libos }}"
log_level = "{{ log_level }}"
[loader.env]
### DEBUG ###
RUST_BACKTRACE = "1"
RUST_LOG = "warning"
### Fixed values ###
LD_LIBRARY_PATH = "{{ gramine.runtimedir() }}:/lib"
SSL_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt"
PATH = "/bin"
HOME = "/app"
MALLOC_ARENA_MAX = "1"
AZDCAP_DEBUG_LOG_LEVEL = "ignore"
AZDCAP_COLLATERAL_VERSION = "v4"
[fs]
root.uri = "file:/"
start_dir = "/app"
mounts = [
{ type = "tmpfs", path = "/var/tmp" },
{ type = "tmpfs", path = "/tmp" },
{ type = "tmpfs", path = "/app/.dcap-qcnl" },
{ type = "tmpfs", path = "/app/.az-dcap-client" },
]
[sgx]
trusted_files = [
"file:/app/",
"file:/bin/",
"file:/etc/gai.conf",
"file:/etc/sgx_default_qcnl.conf",
"file:/etc/ssl/certs/ca-bundle.crt",
"file:/lib/",
"file:/nix/",
"file:{{ gramine.libos }}",
"file:{{ gramine.runtimedir() }}/",
]
remote_attestation = "dcap"
max_threads = 64
edmm_enable = false
## max enclave size
enclave_size = "2G"
[sys]
enable_extra_runtime_domain_names_conf = true
enable_sigterm_injection = true
# possible tweak option, if problems with mio
# currently mio is compiled with `mio_unsupported_force_waker_pipe`
# insecure__allow_eventfd = true

View file

@ -1,25 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
FROM teepot-vault-admin-sgx-azure:base
WORKDIR /app
COPY packages/container-vault-sgx-azure/test-enclave-key.pem /tmp/
RUN set -eux; \
gramine-manifest -Darch_libdir=/lib/x86_64-linux-gnu \
-Dentrypoint=$(readlink /bin/tee-vault-admin) \
-Dexecdir=/bin \
-Dlog_level=warning \
tee-vault-admin.manifest.toml tee-vault-admin.manifest; \
gramine-sgx-sign --manifest tee-vault-admin.manifest --output tee-vault-admin.manifest.sgx --key /tmp/test-enclave-key.pem; \
rm /tmp/test-enclave-key.pem
VOLUME /opt/vault/tls
EXPOSE 8443
ENTRYPOINT ["/bin/sh", "-c"]
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt
CMD [ "echo tee-vault-admin in SGX mode starting; [[ -r /var/run/aesmd/aesm.socket ]] || restart-aesmd ; exec gramine-sgx tee-vault-admin" ]

View file

@ -1,49 +1,53 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ pkgs
, nixsgx
, curl
{ lib
, pkgs
, inputs
, teepot
, bash
, coreutils
, openssl
, nixsgx
, container-name ? "teepot-vault-admin-sgx-azure"
, tag ? "latest"
, isAzure ? true
}:
let manifest = ./tee-vault-admin.manifest.toml;
in pkgs.dockerTools.buildLayeredImage {
name = "teepot-vault-admin-sgx-azure";
tag = "base";
pkgs.callPackage inputs.nixsgx-flake.lib.mkSGXContainer {
name = container-name;
inherit tag;
config.Entrypoint = [ "/bin/sh" "-c" ];
packages = [ teepot.teepot.tee_vault_admin ];
entrypoint = "${teepot.teepot.tee_vault_admin}/bin/tee-vault-admin";
contents = pkgs.buildEnv {
name = "image-root";
isAzure = true;
paths = with pkgs.dockerTools; with nixsgx;[
bash
coreutils
openssl.out
azure-dcap-client
curl.out
teepot.teepot.tee_vault_admin
gramine
restart-aesmd
sgx-dcap.quote_verify
sgx-psw
usrBinEnv
binSh
caCertificates
fakeNss
];
pathsToLink = [ "/bin" "/lib" "/etc" "/app" ];
postBuild = ''
mkdir -p $out/{app,etc}
cp ${manifest} $out/app/tee-vault-admin.manifest.toml
mkdir -p $out/var/run
mkdir -p $out/${nixsgx.sgx-psw.out}/aesm/
touch $out/etc/sgx_default_qcnl.conf
ln -s ${curl.out}/lib/libcurl.so $out/${nixsgx.sgx-psw.out}/aesm/
ln -s ${nixsgx.azure-dcap-client.out}/lib/libdcap_quoteprov.so $out/${nixsgx.sgx-psw.out}/aesm/libdcap_quoteprov.so.1
printf "precedence ::ffff:0:0/96 100\n" > $out/etc/gai.conf
'';
manifest = {
loader = {
log_level = "error";
env = {
### Admin Config ###
PORT.passthrough = true;
### VAULT attestation ###
VAULT_ADDR.passthrough = true;
VAULT_SGX_MRENCLAVE.passthrough = true;
VAULT_SGX_MRSIGNER.passthrough = true;
VAULT_SGX_ALLOWED_TCB_LEVELS.passthrough = true;
### DEBUG ###
RUST_BACKTRACE = "1";
RUST_LOG = "info,tee_vault_admin=trace,teepot=trace,vault_tee_client=trace,tee_client=trace,awc=debug";
### Enclave security ###
ALLOWED_TCB_LEVELS = "SwHardeningNeeded";
};
};
sgx = {
edmm_enable = false;
enclave_size = "2G";
max_threads = 64;
};
# possible tweak option, if problems with mio
# currently mio is compiled with `mio_unsupported_force_waker_pipe`
# sys.insecure__allow_eventfd = true
};
}

View file

@ -1,71 +0,0 @@
libos.entrypoint = "{{ entrypoint }}"
[loader]
argv = ["{{ entrypoint }}"]
entrypoint = "file:{{ gramine.libos }}"
[loader.env]
### Admin Config ###
PORT = { passthrough = true }
### VAULT attestation ###
VAULT_ADDR = { passthrough = true }
VAULT_SGX_MRENCLAVE = { passthrough = true }
VAULT_SGX_MRSIGNER = { passthrough = true }
VAULT_SGX_ALLOWED_TCB_LEVELS = { passthrough = true }
### DEBUG ###
RUST_BACKTRACE = "1"
RUST_LOG = "info,tee_vault_admin=trace,teepot=trace,vault_tee_client=trace,tee_client=trace,awc=debug"
### Enclave security ###
ALLOWED_TCB_LEVELS = "SwHardeningNeeded"
### Fixed values ###
LD_LIBRARY_PATH = "/lib"
SSL_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt"
PATH = "/bin"
HOME = "/app"
MALLOC_ARENA_MAX = "1"
AZDCAP_DEBUG_LOG_LEVEL = "ignore"
AZDCAP_COLLATERAL_VERSION = "v4"
[fs]
root.uri = "file:/"
start_dir = "/app"
mounts = [
{ path = "/lib", uri = "file:{{ gramine.runtimedir() }}" },
{ path = "{{ gramine.runtimedir() }}/libdcap_quoteprov.so", uri = "file:/lib/libdcap_quoteprov.so" },
{ type = "tmpfs", path = "/var/tmp" },
{ type = "tmpfs", path = "/tmp" },
{ type = "tmpfs", path = "/app/.dcap-qcnl" },
{ type = "tmpfs", path = "/app/.az-dcap-client" },
]
[sgx]
trusted_files = [
"file:/app/",
"file:/bin/",
"file:/etc/gai.conf",
"file:/etc/sgx_default_qcnl.conf",
"file:/etc/ssl/certs/ca-bundle.crt",
"file:/lib/",
"file:/lib/libdcap_quoteprov.so",
"file:/nix/",
"file:{{ gramine.libos }}",
"file:{{ gramine.runtimedir() }}/",
]
remote_attestation = "dcap"
max_threads = 64
edmm_enable = false
## max enclave size
enclave_size = "2G"
[sys]
enable_extra_runtime_domain_names_conf = true
enable_sigterm_injection = true
# possible tweak option, if problems with mio
# currently mio is compiled with `mio_unsupported_force_waker_pipe`
# insecure__allow_eventfd = true

View file

@ -1,25 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
FROM teepot-vault-sgx-azure:base
WORKDIR /opt/vault
COPY packages/container-vault-sgx-azure/test-enclave-key.pem /tmp/
RUN set -eux; \
gramine-manifest \
-Dtee_ratls_preexec=$(readlink /bin/tee-ratls-preexec) \
-Dvault_exec=$(readlink /bin/vault) \
-Darch_libdir=/lib/x86_64-linux-gnu \
-Dexecdir=/bin \
-Dlog_level=warning \
vault.manifest.toml vault.manifest; \
gramine-sgx-sign --manifest vault.manifest --output vault.manifest.sgx --key /tmp/test-enclave-key.pem; \
rm /tmp/test-enclave-key.pem
VOLUME /opt/vault/tls
VOLUME /opt/vault/data
ENTRYPOINT ["/bin/sh", "-c"]
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt
CMD [ "echo vault in SGX mode starting; [[ -r /var/run/aesmd/aesm.socket ]] || restart-aesmd ; exec gramine-sgx vault" ]

View file

@ -1,54 +1,92 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ pkgs
, vat
, nixsgx
, curl
{ lib
, pkgs
, inputs
, teepot
, bash
, coreutils
, openssl
, nixsgx
, vat
, vault
, container-name ? "teepot-vault-sgx-azure"
, tag ? "latest"
, isAzure ? true
}:
let manifest = ./vault.manifest.toml;
in pkgs.dockerTools.buildLayeredImage {
name = "teepot-vault-sgx-azure";
tag = "base";
let
entrypoint = "${teepot.teepot.tee_ratls_preexec}/bin/tee-ratls-preexec";
appDir = "/opt/vault";
in
pkgs.callPackage inputs.nixsgx-flake.lib.mkSGXContainer {
name = container-name;
inherit tag;
inherit appDir;
config.Entrypoint = [ "/bin/sh" "-c" ];
packages = [
teepot.teepot.tee_ratls_preexec
vault
vat.vault-auth-tee
teepot.container-vault-start-config
];
inherit entrypoint;
contents = pkgs.buildEnv {
name = "image-root";
isAzure = true;
paths = with pkgs.dockerTools; with nixsgx;[
bash
coreutils
teepot.teepot.tee_ratls_preexec
vault
azure-dcap-client
openssl.out
curl.out
vat.vault-auth-tee
gramine
restart-aesmd
sgx-dcap.quote_verify
sgx-psw
usrBinEnv
binSh
caCertificates
fakeNss
teepot.container-vault-start-config
extraPostBuild = ''
mkdir -p $out/${appDir}/{data,.cache,tls,plugins}
ln -s ${vat.vault-auth-tee}/bin/vault-auth-tee $out/opt/vault/plugins
'';
manifest = {
loader = {
argv = [
entrypoint
"--"
"${vault}/bin/vault"
"server"
"-config=/opt/vault/config.hcl"
"-log-level=trace"
];
log_level = "error";
env = {
VAULT_CLUSTER_ADDR.passthrough = true;
VAULT_API_ADDR.passthrough = true;
VAULT_RAFT_NODE_ID.passthrough = true;
DNS_NAMES = "vault-1,vault-2,vault-3";
# otherwise vault will lock a lot of unused EPC memory
VAULT_RAFT_INITIAL_MMAP_SIZE = "0";
# possible tweak option, if problems with raft
# VAULT_RAFT_DISABLE_MAP_POPULATE = "true"
};
};
fs.mounts = [
{ type = "tmpfs"; path = "/opt/vault/tls"; }
{ type = "encrypted"; path = "/opt/vault/.cache"; uri = "file:/opt/vault/.cache"; key_name = "_sgx_mrsigner"; }
{ type = "encrypted"; path = "/opt/vault/data"; uri = "file:/opt/vault/data"; key_name = "_sgx_mrsigner"; }
];
pathsToLink = [ "/bin" "/lib" "/etc" "/opt/vault" ];
postBuild = ''
mkdir -p $out/var/run
mkdir -p $out/${nixsgx.sgx-psw.out}/aesm/
mkdir -p $out/opt/vault/data $out/opt/vault/.cache $out/opt/vault/tls
ln -s ${curl.out}/lib/libcurl.so $out/${nixsgx.sgx-psw.out}/aesm/
ln -s ${nixsgx.azure-dcap-client.out}/lib/libdcap_quoteprov.so $out/${nixsgx.sgx-psw.out}/aesm/libdcap_quoteprov.so.1
mkdir -p $out/opt/vault/plugins
ln -s ${vat.vault-auth-tee}/bin/vault-auth-tee $out/opt/vault/plugins
cp ${manifest} $out/opt/vault/vault.manifest.toml
'';
sgx = {
debug = false;
edmm_enable = false;
enclave_size = "8G";
max_threads = 64;
nonpie_binary = true;
trusted_files = [
"file:/opt/vault/plugins/"
"file:/opt/vault/config.hcl"
"file:/opt/vault/cacert.pem"
"file:/opt/vault/cakey.pem"
];
};
sys.stack.size = "1M";
# vault needs flock
sys.experimental__enable_flock = true;
};
}

View file

@ -1,39 +0,0 @@
-----BEGIN RSA PRIVATE KEY-----
MIIG5AIBAAKCAYEAwDrEJDyGnIGv/xWF4/MQtVEshpft/xGECSdjuHOU87nwCWon
hirmOyggPPU772tobmaqRhAMHn0NwvRyFCQcSwTIjd0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lUA3ymD4ay8Zysy3FflNqOSO6XkwKq
0GApQ6pIiDTst+LpnfgvQBDAnJXK3Hik2wDgXThXEofUoMDcGNsQ+NbdackR7/yL
8ep5ZLAhczGi4XE471ut48CHtxKq0eGde/lHx0Origk9PPbsNoH2XA==
-----END RSA PRIVATE KEY-----

View file

@ -1,77 +0,0 @@
libos.entrypoint = "{{ tee_ratls_preexec }}"
[loader]
entrypoint = "file:{{ gramine.libos }}"
argv = [
"{{ tee_ratls_preexec }}",
"--",
"{{ vault_exec }}",
"server",
"-config=/opt/vault/config.hcl",
"-log-level=trace",
]
# set a log level for gramine
log_level = "{{ log_level }}"
[loader.env]
LD_LIBRARY_PATH = "/lib"
SSL_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt"
PATH = "{{ execdir }}"
HOME = "/opt/vault"
VAULT_CLUSTER_ADDR.passthrough = true
VAULT_API_ADDR.passthrough = true
VAULT_RAFT_NODE_ID.passthrough = true
DNS_NAMES = "vault-1,vault-2,vault-3"
# otherwise vault will lock a lot of unused EPC memory
VAULT_RAFT_INITIAL_MMAP_SIZE = "0"
# possible tweak option, if problems with raft
# VAULT_RAFT_DISABLE_MAP_POPULATE = "true"
[fs]
root.uri = "file:/"
start_dir = "/opt/vault"
mounts = [
{ path = "/lib", uri = "file:{{ gramine.runtimedir() }}" },
{ path = "{{ gramine.runtimedir() }}/libdcap_quoteprov.so", uri = "file:/lib/libdcap_quoteprov.so" },
{ type = "tmpfs", path = "/var/tmp" },
{ type = "tmpfs", path = "/tmp" },
{ type = "tmpfs", path = "/opt/vault/tls" },
{ type = "tmpfs", path = "/opt/vault/.dcap-qcnl" },
{ type = "tmpfs", path = "/opt/vault/.az-dcap-client" },
{ type = "encrypted", path = "/opt/vault/.cache", uri = "file:/opt/vault/.cache", key_name = "_sgx_mrsigner" },
{ type = "encrypted", path = "/opt/vault/data", uri = "file:/opt/vault/data", key_name = "_sgx_mrsigner" },
]
[sgx]
debug = false
edmm_enable = false
enclave_size = "8G"
max_threads = 64
nonpie_binary = true
remote_attestation = "dcap"
trusted_files = [
"file:/bin/",
"file:/etc/gai.conf",
"file:/etc/ssl/certs/ca-bundle.crt",
"file:/lib/",
"file:/nix/",
"file:/opt/vault/plugins/",
"file:/opt/vault/config.hcl",
"file:/opt/vault/cacert.pem",
"file:/opt/vault/cakey.pem",
"file:{{ gramine.libos }}",
"file:{{ gramine.runtimedir() }}/",
]
[sys]
stack.size = "1M"
enable_extra_runtime_domain_names_conf = true
enable_sigterm_injection = true
# vault needs flock
experimental__enable_flock = true

View file

@ -19,8 +19,5 @@ stdenv.mkDerivation {
postInstall = ''
mkdir -p $out/opt/vault
cp -r $src/* $out/opt/vault
mkdir -p $out/etc
printf "precedence ::ffff:0:0/96 100\n" > $out/etc/gai.conf
'';
}

View file

@ -1,25 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
FROM teepot-vault-unseal-sgx-azure:base
WORKDIR /app
COPY packages/container-vault-sgx-azure/test-enclave-key.pem /tmp/
RUN set -eux; \
gramine-manifest -Darch_libdir=/lib/x86_64-linux-gnu \
-Dentrypoint=$(readlink /bin/tee-vault-unseal) \
-Dvault_auth_tee_sha=1505ffe3ef0994de63206ccce1dec6715d55e72955960cb7314e4571811c4422 \
-Dvault_auth_tee_version=0.1.0+dev \
-Dexecdir=/bin \
-Dlog_level=warning \
tee-vault-unseal.manifest.toml tee-vault-unseal.manifest; \
gramine-sgx-sign --manifest tee-vault-unseal.manifest --output tee-vault-unseal.manifest.sgx --key /tmp/test-enclave-key.pem; \
rm /tmp/test-enclave-key.pem
EXPOSE 8443
ENTRYPOINT ["/bin/sh", "-c"]
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt
CMD [ "echo tee-vault-unseal in SGX mode starting; [[ -r /var/run/aesmd/aesm.socket ]] || restart-aesmd ; exec gramine-sgx tee-vault-unseal" ]

View file

@ -1,52 +1,59 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ pkgs
, vat
, nixsgx
, curl
{ lib
, pkgs
, inputs
, teepot
, bash
, coreutils
, openssl
, nixsgx
, vat
, container-name ? "teepot-vault-unseal-sgx-azure"
, tag ? "latest"
, isAzure ? true
}:
let manifest = ./tee-vault-unseal.manifest.toml;
in pkgs.dockerTools.buildLayeredImage {
name = "teepot-vault-unseal-sgx-azure";
tag = "base";
pkgs.callPackage inputs.nixsgx-flake.lib.mkSGXContainer {
name = container-name;
inherit tag;
config.Entrypoint = [ "/bin/sh" "-c" ];
packages = [
vat.vault-auth-tee.sha
teepot.teepot.tee_vault_unseal
];
entrypoint = "${teepot.teepot.tee_vault_unseal}/bin/tee-vault-unseal";
contents = pkgs.buildEnv {
name = "image-root";
isAzure = true;
paths = with pkgs.dockerTools; with nixsgx;[
bash
coreutils
openssl.out
azure-dcap-client
curl.out
vat.vault-auth-tee.sha
teepot.teepot.tee_vault_unseal
gramine
restart-aesmd
sgx-dcap.quote_verify
sgx-psw
usrBinEnv
binSh
caCertificates
fakeNss
];
pathsToLink = [ "/bin" "/lib" "/etc" "/share" "/app" ];
postBuild = ''
mkdir -p $out/{app,etc}
cp ${manifest} $out/app/tee-vault-unseal.manifest.toml
mkdir -p $out/var/run
mkdir -p $out/${nixsgx.sgx-psw.out}/aesm/
touch $out/etc/sgx_default_qcnl.conf
mkdir -p $out/opt/vault/.cache $out/opt/vault/tls
ln -s ${curl.out}/lib/libcurl.so $out/${nixsgx.sgx-psw.out}/aesm/
ln -s ${nixsgx.azure-dcap-client.out}/lib/libdcap_quoteprov.so $out/${nixsgx.sgx-psw.out}/aesm/libdcap_quoteprov.so.1
printf "precedence ::ffff:0:0/96 100\n" > $out/etc/gai.conf
'';
manifest = {
loader = {
log_level = "error";
env = {
### Admin Config ###
PORT.passthrough = true;
### VAULT attestation ###
VAULT_ADDR.passthrough = true;
VAULT_SGX_MRENCLAVE.passthrough = true;
VAULT_SGX_MRSIGNER.passthrough = true;
VAULT_SGX_ALLOWED_TCB_LEVELS.passthrough = true;
### DEBUG ###
RUST_BACKTRACE = "1";
RUST_LOG = "info,tee_vault_unseal=trace,teepot=trace,vault_tee_client=trace,tee_client=trace,awc=debug";
### Enclave security ###
ALLOWED_TCB_LEVELS = "SwHardeningNeeded";
VAULT_AUTH_TEE_SHA256 = "${vat.vault-auth-tee.sha}/share/vault-auth-tee.sha256";
};
};
sgx = {
edmm_enable = false;
enclave_size = "2G";
max_threads = 64;
};
# possible tweak option, if problems with mio
# currently mio is compiled with `mio_unsupported_force_waker_pipe`
# sys.insecure__allow_eventfd = true
};
}

View file

@ -1,74 +0,0 @@
libos.entrypoint = "{{ entrypoint }}"
[loader]
argv = ["{{ entrypoint }}"]
entrypoint = "file:{{ gramine.libos }}"
[loader.env]
### Admin Config ###
PORT = { passthrough = true }
### VAULT attestation ###
VAULT_ADDR = { passthrough = true }
VAULT_SGX_MRENCLAVE = { passthrough = true }
VAULT_SGX_MRSIGNER = { passthrough = true }
VAULT_SGX_ALLOWED_TCB_LEVELS = { passthrough = true }
### DEBUG ###
RUST_BACKTRACE = "1"
RUST_LOG = "info,tee_vault_unseal=trace,teepot=trace,vault_tee_client=trace,tee_client=trace,awc=debug"
### Enclave security ###
ALLOWED_TCB_LEVELS = "SwHardeningNeeded"
### Fixed values ###
LD_LIBRARY_PATH = "/lib"
SSL_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt"
PATH = "/bin"
HOME = "/app"
MALLOC_ARENA_MAX = "1"
AZDCAP_DEBUG_LOG_LEVEL = "ignore"
AZDCAP_COLLATERAL_VERSION = "v4"
VAULT_AUTH_TEE_SHA256 = "{{ vault_auth_tee_sha }}"
VAULT_AUTH_TEE_VERSION = "{{ vault_auth_tee_version }}"
[fs]
root.uri = "file:/"
start_dir = "/app"
mounts = [
{ path = "/lib", uri = "file:{{ gramine.runtimedir() }}" },
{ path = "{{ gramine.runtimedir() }}/libdcap_quoteprov.so", uri = "file:/lib/libdcap_quoteprov.so" },
{ type = "tmpfs", path = "/var/tmp" },
{ type = "tmpfs", path = "/tmp" },
{ type = "tmpfs", path = "/app/.dcap-qcnl" },
{ type = "tmpfs", path = "/app/.az-dcap-client" },
]
[sgx]
trusted_files = [
"file:/app/",
"file:/bin/",
"file:/etc/gai.conf",
"file:/etc/sgx_default_qcnl.conf",
"file:/etc/ssl/certs/ca-bundle.crt",
"file:/lib/",
"file:/lib/libdcap_quoteprov.so",
"file:/nix/",
"file:{{ gramine.libos }}",
"file:{{ gramine.runtimedir() }}/",
]
remote_attestation = "dcap"
max_threads = 64
edmm_enable = false
## max enclave size
enclave_size = "2G"
[sys]
enable_extra_runtime_domain_names_conf = true
enable_sigterm_injection = true
# possible tweak option, if problems with mio
# currently mio is compiled with `mio_unsupported_force_waker_pipe`
# insecure__allow_eventfd = true

View file

@ -1,36 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ dockerTools
, buildEnv
, teepot
, openssl
, curl
, nixsgx
}:
dockerTools.buildLayeredImage {
name = "verify-attestation-sgx-azure";
tag = "latest";
config.Cmd = [ "${teepot.teepot.verify_attestation}/bin/verify-attestation" ];
config.Env = [
"LD_LIBRARY_PATH=/lib"
"AZDCAP_DEBUG_LOG_LEVEL=ignore"
"AZDCAP_COLLATERAL_VERSION=v4"
];
contents = buildEnv {
name = "image-root";
paths = with dockerTools; with nixsgx;[
openssl.out
curl.out
azure-dcap-client
sgx-dcap.quote_verify
teepot.teepot.verify_attestation
usrBinEnv
binSh
caCertificates
fakeNss
];
pathsToLink = [ "/bin" "/lib" "/etc" "/share" ];
};
}

View file

@ -8,7 +8,7 @@
, nixsgx
}:
dockerTools.buildLayeredImage {
name = "verify-attestation-sgx-dcap";
name = "verify-attestation-sgx";
tag = "latest";
config.Cmd = [ "${teepot.teepot.verify_attestation}/bin/verify-attestation" ];

View file

@ -1,18 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ lib
, inputs
, makeRustPlatform
, nixsgx
, pkg-config
, rust-bin
, pkgs
, ...
}@args:
let
teepotCrate = import ./teepot.nix args;
in
teepotCrate.craneLib.buildPackage (
{ teepotCrate }: teepotCrate.craneLib.buildPackage (
teepotCrate.commonArgs // {
pname = "teepot";
inherit (teepotCrate) cargoArtifacts

View file

@ -1,61 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ lib
, inputs
, makeRustPlatform
, nixsgx
, pkg-config
, rust-bin
, pkgs
, ...
}:
let
rustVersion = rust-bin.fromRustupToolchainFile ../../rust-toolchain.toml;
rustPlatform = makeRustPlatform {
cargo = rustVersion;
rustc = rustVersion;
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustVersion;
commonArgs = {
nativeBuildInputs = [
pkg-config
rustPlatform.bindgenHook
];
buildInputs = [
nixsgx.sgx-sdk
nixsgx.sgx-dcap
nixsgx.sgx-dcap.quote_verify
];
strictDeps = true;
src = with lib.fileset; toSource {
root = ../../.;
fileset = unions [
../../Cargo.lock
../../Cargo.toml
../../bin
../../crates
../../rust-toolchain.toml
../../deny.toml
../../taplo.toml
];
};
RUSTFLAGS = "--cfg mio_unsupported_force_waker_pipe";
checkType = "debug";
};
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
pname = "teepot-workspace";
inherit NIX_OUTPATH_USED_AS_RANDOM_SEED;
});
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
in
{
inherit rustPlatform
rustVersion
commonArgs
craneLib
cargoArtifacts;
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
}