Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AKS attestation example to use Gramine 1.3.1 #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions Examples/aks-attestation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,32 @@ Note: This example is Ubuntu 18.04-specific. This example was tested with Gramin
$ docker push <dockerhubusername>/aks-secret-prov-server-img:latest
```

3. Deploy `aks-secret-prov-server-img:latest` in the AKS confidential compute cluster using reference
deployment file: `aks-secret-prov-server-deployment.yaml`
3. Deploy `aks-secret-prov-server-img:latest` in the AKS confidential compute cluster using
reference deployment file: `aks-secret-prov-server-deployment.yaml`

### Creating client (SGX application) image

The client Docker image must run the client application inside the SGX enclave. For this, we use the
Gramine Shielded Containers (GSC) tool (https://github.com/gramineproject/gsc). GSC transforms the
native Docker client image into a new "graminized" Docker image.
The client Docker image must run the client application (`client.c` in this case) inside the SGX
enclave. For this, we use the Gramine Shielded Containers (GSC) tool (https://github.com/gramineproject/gsc).
GSC transforms the native Docker client image into a new "graminized" Docker image.

1. The `base-image-generation-script.sh` script will create the native Docker client image with the
name `aks-secret-prov-client-img:latest`.
1. The `base-image-generation-script.sh` script will first create the native Docker client image
with the name `aks-secret-prov-client-img:latest`.

2. Create the GSC client image (note that we tested this example with DCAP driver 1.11 specified in
the GSC configuration file):
2. The script then creates a GSC client image `gsc-aks-secret-prov-client-img:latest` (note that we
tested this example with DCAP driver 1.11 specified in `config.yaml.template`) signed with a
test enclave signing key.

```sh
$ cd gsc
$ ./gsc build aks-secret-prov-client-img:latest \
Examples/aks-attestation/aks-secret-prov-client.manifest
$ ./gsc sign-image aks-secret-prov-client-img:latest enclave-key.pem
```

5. Push resulting image to Docker Hub or your preferred registry:
3. The user is now expected to push `gsc-aks-secret-prov-client-img:latest` to Docker Hub or the
preferred registry:

```sh
$ docker tag gsc-aks-secret-prov-client-img:latest \
<dockerhubusername>/gsc-aks-secret-prov-client-img:latest
$ docker push <dockerhubusername>/gsc-aks-secret-prov-client-img:latest
```

6. Deploy `gsc-aks-secret-prov-client-img:latest` in AKS confidential compute cluster using
4. Deploy `gsc-aks-secret-prov-client-img:latest` in AKS confidential compute cluster using
reference deployment file: `aks-secret-prov-client-deployment.yaml`

## Deploying client and server images in AKS confidential compute cluster
Expand All @@ -101,6 +96,12 @@ libsgx-dcap-quote-verify library via the az-dcap-client library.

### Deployment

Create a ConfigMap for the ssl artifacts that will be later injected into the server pod.
```sh
$ kubectl create configmap ssl-certs --from-file=ssl/ca.crt --from-file=ssl/server.key \
--from-file=ssl/server.crt
```

```sh
$ kubectl apply -f aks-secret-prov-server-deployment.yaml
```
Expand Down Expand Up @@ -131,7 +132,7 @@ $ kubectl logs -l app=gsc-ra-tls-secret-prov-client --tail=50

Expected output:

`--- Received secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'`
`--- Received secret = 'A_SIMPLE_SECRET' ---`

Delete both client and server containers:

Expand Down
27 changes: 5 additions & 22 deletions Examples/aks-attestation/aks-secret-prov-client.dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
FROM ubuntu:18.04

RUN apt-get update \
&& env DEBIAN_FRONTEND=noninteractive apt-get install -y wget \
build-essential \
gnupg2 \
libcurl3-gnutls \
python3
&& env DEBIAN_FRONTEND=noninteractive apt-get install -y git build-essential

# Installing DCAP libraries
RUN echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu bionic main' \
> /etc/apt/sources.list.d/intel-sgx.list \
&& wget https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key \
&& apt-key add intel-sgx-deb.key
COPY client.c /client.c
RUN client.c -o min_client && cp min_client /usr/local/bin
COPY ssl/ca.crt /ca.crt

RUN apt-get update \
&& apt-get install -y libsgx-urts \
libsgx-dcap-ql \
libsgx-quote-ex

WORKDIR /ra-tls-secret-prov

COPY gramine/CI-Examples/ra-tls-secret-prov/ssl ./ssl

COPY gramine/CI-Examples/ra-tls-secret-prov/secret_prov_min_client /usr/local/bin

ENTRYPOINT ["secret_prov_min_client"]
ENTRYPOINT ["min_client"]
22 changes: 7 additions & 15 deletions Examples/aks-attestation/aks-secret-prov-client.manifest
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
# Secret Provisioning library (client-side) is preloaded
loader.env.LD_PRELOAD = "libsecret_prov_attest.so"
sgx.enclave_size = "1024M"
sgx.thread_num = 8

# Attestation related entries
sgx.remote_attestation = "dcap"
loader.env.LD_PRELOAD = "/gramine/meson_build_output/lib/x86_64-linux-gnu/libsecret_prov_attest.so"
loader.env.SECRET_PROVISION_SERVERS = { passthrough = true }
loader.env.SECRET_PROVISION_CONSTRUCTOR = "1"
loader.env.SECRET_PROVISION_CA_CHAIN_PATH = "ssl/ca.crt"
loader.env.SECRET_PROVISION_CA_CHAIN_PATH = "/ca.crt"

sgx.remote_attestation = true

sgx.allowed_files = [
"file:/etc/ethers",
"file:/etc/gai.conf",
"file:/etc/group",
"file:/etc/host.conf",
"file:/etc/hosts",
"file:/etc/nsswitch.conf",
"file:/etc/passwd",
"file:/etc/resolv.conf",
]
sys.enable_extra_runtime_domain_names_conf = true
12 changes: 12 additions & 0 deletions Examples/aks-attestation/aks-secret-prov-server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ spec:
resources:
limits:
kubernetes.azure.com/sgx_epc_mem_in_MiB: 10
volumeMounts:
- name: ssl
mountPath: /ra-tls-secret-prov/ssl/
env:
- name: RA_TLS_ALLOW_DEBUG_ENCLAVE_INSECURE
value: "1"
- name: RA_TLS_ALLOW_OUTDATED_TCB_INSECURE
value: "1"
volumes:
- name: ssl
configMap:
name: ssl-certs

# TODO: Requesting an SGX machine is not needed, but Intel DCAP libraries have a bug of trying to
# open the SGX driver (see https://github.com/intel/linux-sgx/issues/756)
Expand Down
30 changes: 21 additions & 9 deletions Examples/aks-attestation/aks-secret-prov-server.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ FROM ubuntu:18.04

RUN apt-get update \
&& env DEBIAN_FRONTEND=noninteractive apt-get install -y \
build-essential \
curl \
git \
gnupg2 \
wget

Expand All @@ -13,21 +15,31 @@ RUN apt-get update \
RUN wget https://packages.microsoft.com/ubuntu/18.04/prod/pool/main/a/az-dcap-client/az-dcap-client_1.10_amd64.deb \
&& dpkg -i az-dcap-client_1.10_amd64.deb

WORKDIR /ra-tls-secret-prov

COPY gramine/CI-Examples/ra-tls-secret-prov/ssl ./ssl
COPY gramine/CI-Examples/ra-tls-secret-prov/files ./files

COPY gramine/CI-Examples/ra-tls-secret-prov/secret_prov_server_dcap /usr/local/bin

RUN echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu bionic main' \
> /etc/apt/sources.list.d/intel-sgx.list \
&& wget https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key \
&& apt-key add intel-sgx-deb.key

RUN curl -fsSLo /usr/share/keyrings/gramine-keyring.gpg https://packages.gramineproject.io/gramine-keyring.gpg
RUN echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/gramine-keyring.gpg] https://packages.gramineproject.io/ stable main' | tee /etc/apt/sources.list.d/gramine.list
RUN echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/gramine-keyring.gpg] https://packages.gramineproject.io/ bionic main' | tee /etc/apt/sources.list.d/gramine.list
RUN apt-get update
RUN apt-get install -y gramine-dcap

ENTRYPOINT ["secret_prov_server_dcap"]
RUN git clone --depth 1 --branch v1.3.1 https://github.com/gramineproject/gramine.git

ARG server_dcap_pf="n"
RUN if [ $server_dcap_pf="y" ]; then \
sed -i "s|verify_measurements_callback,|NULL,|g" \
"gramine/CI-Examples/ra-tls-secret-prov/secret_prov_pf/server.c"; \
fi

RUN mkdir -p /ra-tls-secret-prov/secret_prov_minimal
RUN cd gramine/CI-Examples/ra-tls-secret-prov/ \
&& make clean && make dcap \
&& cp secret_prov_minimal/server_dcap /ra-tls-secret-prov/secret_prov_minimal/

RUN rm -rf gramine >/dev/null 2>&1

WORKDIR /ra-tls-secret-prov/secret_prov_minimal

ENTRYPOINT ["./server_dcap"]
22 changes: 11 additions & 11 deletions Examples/aks-attestation/base-image-generation-script.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Install Gramine, and build the ra-tls-secret-prov files and
# relevant libraries to be used in the server and client Dockerfiles.
/bin/sh install_gramine.sh

# Create Server image
cd gramine/CI-Examples/ra-tls-secret-prov
make clean && make dcap
cd ../../../
docker build -f aks-secret-prov-server.dockerfile -t aks-secret-prov-server-img .

# Create Client image
cd gramine/CI-Examples/ra-tls-secret-prov
make clean && make secret_prov_min_client
cd ../../../
docker build -f aks-secret-prov-client.dockerfile -t aks-secret-prov-client-img .

rm -rf gramine/
# Clone GSC repo
git clone --depth 1 https://github.com/gramineproject/gsc.git
cd gsc
cp ../config.yaml.template config.yaml

# Generate an unsigned GSC image
./gsc build aks-secret-prov-client-img ../aks-secret-prov-client.manifest

# Create a test signing key, and generate the signed image
openssl genrsa -3 -aes128 -passout pass:test@123 -out enclave-key.pem 3072
./gsc sign-image aks-secret-prov-client-img enclave-key.pem -p test@123
15 changes: 15 additions & 0 deletions Examples/aks-attestation/client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2020 Intel Labs */

#include <stdio.h>
#include <stdlib.h>

int main(void) {
char* secret = getenv("SECRET_PROVISION_SECRET_STRING");
if (secret)
printf("--- Received secret = '%s' ---\n", secret);
else
printf("--- Did not receive any secret! ---\n");

return 0;
}
28 changes: 28 additions & 0 deletions Examples/aks-attestation/config.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# DO NOT CHANGE! BELOW WILL BE REPLACED BY THE CURATION SCRIPT!
# Currently tested distros are
# - ubuntu:18.04, ubuntu:20.04, ubuntu:21.04
# - debian:10, debian:11

Distro: "ubuntu:18.04"

# If the image has a specific registry, define it here.
# Empty by default; example value: "registry.access.redhat.com/ubi8".
Registry: ""

# If you're using your own fork and branch of Gramine, specify the GitHub link and the branch name
# below; typically, you want to keep the default values though
Gramine:
Repository: "https://github.com/gramineproject/gramine.git"
Branch: "v1.3.1"

# Specify the Intel SGX driver installed on your target machine (more specifically, on the machine
# where the graminized Docker container will run); Default assumption is DCAP out-of-tree driver,
# but for DCAP in-kernel driver: use empty values like below
#
# - DCAP in-kernel driver: use empty values like below
# Repository: ""
# Branch: ""
#
SGXDriver:
Repository: "https://github.com/intel/SGXDataCenterAttestationPrimitives.git"
Branch: "DCAP_1.11 && cp -r driver/linux/* ."
15 changes: 0 additions & 15 deletions Examples/aks-attestation/install_gramine.sh

This file was deleted.

51 changes: 21 additions & 30 deletions Examples/aks-attestation/ssl/ca.crt
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
-----BEGIN CERTIFICATE-----
MIIFeDCCA2CgAwIBAgIBADANBgkqhkiG9w0BAQsFADBVMQswCQYDVQQGEwJOTDEL
MAkGA1UECAwCTkwxCzAJBgNVBAcMAk5MMREwDwYDVQQKDAhQb2xhclNTTDEZMBcG
A1UEAwwQUG9sYXJTU0wgVGVzdCBDQTAeFw0yMTExMDkwNTA4MDhaFw0zMTExMDcw
NTA4MDhaMFUxCzAJBgNVBAYTAk5MMQswCQYDVQQIDAJOTDELMAkGA1UEBwwCTkwx
ETAPBgNVBAoMCFBvbGFyU1NMMRkwFwYDVQQDDBBQb2xhclNTTCBUZXN0IENBMIIC
IjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAt4LPFNvOHrkgztHoZ9LR+69Q
uhDzaPmlEGng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