Skip to content

Commit 7f685b5

Browse files
committed
sgx: add QuoteVerification demo and cleanup hostNetwork dependency
hostNetwork usage for SGX demo pods is not absolutely necessary so it's better to clean it up and make IAS "security" scanners happier. It was originally used to be able to use "localhost" PCCS but this change now adds an example how proper PCCS url can be configured using jq. Additionally, SGX DCAP Quote Verification is added. Signed-off-by: Mikko Ylinen <[email protected]>
1 parent ed86c4f commit 7f685b5

File tree

11 files changed

+72
-32
lines changed

11 files changed

+72
-32
lines changed

.trivyignore

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ AVD-DS-0002
99
# initcontainers require privileged access
1010
AVD-KSV-0017
1111

12-
# Sharing the host’s network namespace permits processes in the pod to communicate with
13-
# processes bound to the host’s loopback adapter.
14-
# sgx single-node demo deployment uses hostNetwork: true to be able to use the default setting for PCCS URL from containers
15-
AVD-KSV-0009
16-
1712
# Do not allow privilege escalation from node proxy
1813
# Check whether role permits privilege escalation from node proxy
1914
# gpu plugin in kubelet mode requires "nodes/proxy" resource access

cmd/sgx_plugin/README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ Successfully tagged intel/sgx-sdk-demo:devel
195195
#### Deploy the pods
196196

197197
The demo runs Intel aesmd (architectural enclaves service daemon) that is responsible
198-
for generating SGX quotes for workloads. It is deployed with `hostNetwork: true`
199-
to allow connections to localhost PCCS.
198+
for generating SGX quotes for workloads.
199+
200+
**Note**: The PCCS URL must be configured in `sgx_default_qcnl.conf`. The default `localhost` URL
201+
is not available in containers
200202

201203
```bash
202204
$ kubectl apply -k 'https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/sgx_aesmd?ref=<RELEASE_VERSION>'
@@ -239,5 +241,7 @@ $ kubectl logs ecdsa-quote-intelsgx-demo-job-vtq84
239241
Step4: Call sgx_qe_get_quote:succeed!cert_key_type = 0x5
240242
```
241243
244+
Similarly, full SGX DCAP Flow with Quote Generation and Trusted Quote Verification can be deployed using the `sgx_ecdsa_inproc_quote` overlay. Again, the PCCS URL must be set beforehand.
245+
242246
> **Note**: The deployment example above uses [kustomize](https://github.com/kubernetes-sigs/kustomize)
243247
> that is available in kubectl since Kubernetes v1.14 release.

demo/screencast-sgx.sh

+17-10
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ cleanup()
2727
out 'Cleanup demo artifacts' 20
2828
out 'delete node-feature-discovery deployment:' 20
2929
command 'kubectl delete -k https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/nfd/overlays/node-feature-rules?ref=main || true' 20
30-
command 'kubectl delete -k https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/nfd/overlays/sgx?ref=main || true' 20
30+
command 'kubectl delete -k https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/nfd?ref=main || true' 20
3131
out 'delete SGX Device Plugin deployment:' 20
3232
command 'kubectl delete sgxdeviceplugin sgxdeviceplugin-sample || true' 20
3333
out 'delete Intel Device Plugin Operator deployment:' 20
@@ -69,10 +69,10 @@ screen3()
6969
clear
7070
out "2. Deploy node-feature-discovery for Kubernetes"
7171
out "It's used to label SGX capable nodes and register SGX EPC as an extended resource"
72-
command "kubectl apply -k https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/nfd/overlays/sgx?ref=main"
72+
command "kubectl apply -k https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/nfd?ref=main"
7373
out "Check its pod is running"
7474
command "kubectl wait --for=condition=Ready pod/$(kubectl get --no-headers -l app=nfd-worker -o=jsonpath='{.items[0].metadata.name}' pods -n node-feature-discovery) -n node-feature-discovery"
75-
out "Create NodeFeatureRules for SGX specific labels"
75+
out "Create NodeFeatureRules for SGX specific labels and SGX EPC extended resource"
7676
command 'kubectl apply -k https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/nfd/overlays/node-feature-rules?ref=main || true' 20
7777
}
7878

@@ -91,8 +91,8 @@ screen5()
9191
{
9292
clear
9393
out "4. Verify node resources"
94-
command "kubectl get nodes -o json | jq .items[].status.allocatable | grep sgx"
95-
command "kubectl get nodes -o json | jq .items[].metadata.labels | grep sgx"
94+
command "kubectl get nodes -o jsonpath='{.items[].status.allocatable}' | jq | grep sgx"
95+
command "kubectl get nodes -o jsonpath='{.items[].metadata.labels}' | jq | grep kubernetes.io\/sgx"
9696
out "Both node labels and resources for SGX are in place"
9797
}
9898

@@ -104,7 +104,10 @@ screen6()
104104
command "sudo ctr -n k8s.io i import sgx-aesmd.tar"
105105
command "sudo ctr -n k8s.io i import sgx-demo.tar"
106106
out "Deploy Intel(R) AESMD"
107-
command "kubectl apply -k https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/sgx_aesmd?ref=main -n sgx-ecdsa-quote"
107+
pushd ../deployments/sgx_aesmd/base
108+
jq --arg pccs_url "$PCCS_URL" '.pccs_url = $pccs_url' sgx_default_qcnl.template > sgx_default_qcnl.conf
109+
command "kubectl apply -k . -n sgx-ecdsa-quote"
110+
popd
108111
out "Deploy Intel(R) SGX DCAP ECDSA Quote Generation"
109112
command "kubectl apply -k https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/sgx_enclave_apps/overlays/sgx_ecdsa_aesmd_quote?ref=main -n sgx-ecdsa-quote"
110113
command "kubectl logs $(kubectl get --no-headers -l job-name=ecdsa-quote-intelsgx-demo-job -o=jsonpath='{.items[0].metadata.name}' pods -n sgx-ecdsa-quote) -n sgx-ecdsa-quote"
@@ -117,11 +120,14 @@ screen6()
117120
screen7()
118121
{
119122
clear
120-
out "6. Run Intel(R) SGX DCAP ECDSA Quote Generation (in-proc)"
121-
out "Deploy Intel(R) SGX DCAP ECDSA Quote Generation"
122-
command "kubectl apply -k https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/sgx_enclave_apps/overlays/sgx_ecdsa_inproc_quote?ref=main -n sgx-ecdsa-quote"
123+
out "6. Run Intel(R) SGX DCAP ECDSA Quote Generation (in-proc) and Trusted Quote Verification"
124+
out "Deploy Intel(R) SGX DCAP ECDSA DCAP Flow"
125+
pushd ../deployments/sgx_enclave_apps/overlays/sgx_ecdsa_inproc_quote
126+
jq --arg pccs_url "$PCCS_URL" '.pccs_url = $pccs_url' sgx_default_qcnl.template > sgx_default_qcnl.conf
127+
command "kubectl apply -k . -n sgx-ecdsa-quote"
128+
popd
123129
command "kubectl logs $(kubectl get --no-headers -l job-name=inproc-ecdsa-quote-intelsgx-demo-job -o=jsonpath='{.items[0].metadata.name}' pods -n sgx-ecdsa-quote) -n sgx-ecdsa-quote"
124-
out "Intel(R) SGX DCAP QuoteGenerationSample successfully generated a quote using DCAP Quote Provider Library"
130+
out "Intel(R) SGX DCAP QuoteGenerationSample successfully generated and verified a quote using DCAP Quote Provider Library"
125131
out "Delete the deployment"
126132
command "kubectl delete -k https://github.com/intel/intel-device-plugins-for-kubernetes/deployments/sgx_enclave_apps/overlays/sgx_ecdsa_inproc_quote?ref=main -n sgx-ecdsa-quote"
127133
}
@@ -134,6 +140,7 @@ screen8()
134140
out "* SGX Kubernetes* Device Plugin deployment with an Operator"
135141
out "* Intel(R) SGX node resource and feature label registration to Kubernetes*"
136142
out "* Intel(R) SGX DCAP ECDSA Quote Generation (out-of-proc and in-proc)"
143+
out "* Intel(R) SGX DCAP ECDSA Trusted Quote Verification"
137144
}
138145

139146
if [ "$1" == 'play' ] ; then

demo/sgx-sdk-demo/Dockerfile

+17-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN apt-get update && \
2323
# SGX SDK is installed in /opt/intel directory.
2424
WORKDIR /opt/intel
2525

26-
ARG DCAP_VERSION=DCAP_1.17
26+
ARG DCAP_VERSION=DCAP_1.18
2727

2828
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-sgx.gpg] https://download.01.org/intel-sgx/sgx_repo/ubuntu jammy main" | \
2929
tee -a /etc/apt/sources.list.d/intel-sgx.list \
@@ -32,11 +32,12 @@ RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-sgx.gpg] https://d
3232
&& apt-get update \
3333
&& env DEBIAN_FRONTEND=noninteractive apt-get install -y \
3434
libsgx-dcap-ql-dev \
35+
libsgx-dcap-quote-verify-dev \
3536
libsgx-dcap-default-qpl-dev \
3637
libsgx-quote-ex-dev
3738

3839
# Install SGX SDK
39-
ARG SGX_SDK_URL=https://download.01.org/intel-sgx/sgx-linux/2.20/distro/ubuntu22.04-server/sgx_linux_x64_sdk_2.20.100.4.bin
40+
ARG SGX_SDK_URL=https://download.01.org/intel-sgx/sgx-linux/2.21/distro/ubuntu22.04-server/sgx_linux_x64_sdk_2.21.100.1.bin
4041
RUN wget ${SGX_SDK_URL} \
4142
&& export SGX_SDK_INSTALLER=$(basename $SGX_SDK_URL) \
4243
&& chmod +x $SGX_SDK_INSTALLER \
@@ -55,6 +56,12 @@ RUN cd SGXDataCenterAttestationPrimitives/SampleCode/QuoteGenerationSample \
5556
&& make \
5657
&& cd -
5758

59+
RUN cd SGXDataCenterAttestationPrimitives/SampleCode/QuoteVerificationSample \
60+
&& . /opt/intel/sgxsdk/environment \
61+
&& make HW_RELEASE=1 \
62+
&& sgx_sign sign -key ../QuoteGenerationSample/Enclave/Enclave_private_sample.pem -enclave enclave.so -out enclave.signed.so -config Enclave/Enclave.config.xml \
63+
&& cd -
64+
5865
FROM ubuntu:22.04
5966

6067
RUN apt-get update && \
@@ -72,9 +79,12 @@ RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-sgx.gpg] https://d
7279
libsgx-enclave-common \
7380
libsgx-urts \
7481
libsgx-quote-ex \
82+
libsgx-dcap-quote-verify \
83+
libsgx-ae-qve \
7584
libsgx-dcap-ql \
7685
libsgx-dcap-default-qpl \
7786
&& mkdir -p /opt/intel/sgx-sample-app/ \
87+
&& mkdir -p /opt/intel/sgx-quote-verification/ \
7888
&& mkdir -p /opt/intel/sgx-quote-generation/
7989

8090
COPY --from=builder /opt/intel/sgxsdk/SampleCode/SampleEnclave/app /opt/intel/sgx-sample-app/sgx-sample-app
@@ -83,4 +93,9 @@ COPY --from=builder /opt/intel/sgxsdk/SampleCode/SampleEnclave/enclave.signed.so
8393
COPY --from=builder /opt/intel/SGXDataCenterAttestationPrimitives/SampleCode/QuoteGenerationSample/app /opt/intel/sgx-quote-generation/sgx-quote-generation
8494
COPY --from=builder /opt/intel/SGXDataCenterAttestationPrimitives/SampleCode/QuoteGenerationSample/enclave.signed.so /opt/intel/sgx-quote-generation/enclave.signed.so
8595

96+
COPY --from=builder /opt/intel/SGXDataCenterAttestationPrimitives/SampleCode/QuoteVerificationSample/app /opt/intel/sgx-quote-verification/sgx-quote-verification
97+
COPY --from=builder /opt/intel/SGXDataCenterAttestationPrimitives/SampleCode/QuoteVerificationSample/enclave.signed.so /opt/intel/sgx-quote-verification/enclave.signed.so
98+
99+
COPY --chmod=555 run-dcap-flow /opt/intel
100+
86101
ENTRYPOINT /opt/intel/sgx-sample-app/sgx-sample-app

demo/sgx-sdk-demo/run-dcap-flow

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
pushd sgx-quote-generation
4+
5+
./sgx-quote-generation
6+
7+
popd
8+
9+
pushd sgx-quote-verification
10+
11+
./sgx-quote-verification -quote ../sgx-quote-generation/quote.dat

deployments/sgx_aesmd/base/intel-sgx-aesmd.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ spec:
1515
annotations:
1616
sgx.intel.com/quote-provider: "aesmd"
1717
spec:
18-
hostNetwork: true
1918
containers:
2019
- name: aesmd
2120
image: intel/sgx-aesmd-demo:devel
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"pccs_url": "https://localhost:8081/sgx/certification/v4/",
3+
"use_secure_cert": false,
4+
"pccs_api_version": "3.1"
5+
}

deployments/sgx_enclave_apps/overlays/sgx_ecdsa_inproc_quote/add_hostnetwork.yaml

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{"op": "replace", "path": "/spec/template/spec/containers/0/workingDir", "value": "/opt/intel/"},
3+
{"op": "replace", "path": "/spec/template/spec/containers/0/command", "value": ["/opt/intel/run-dcap-flow"]},
4+
{"op": "remove", "path": "/spec/template/spec/containers/0/securityContext/readOnlyRootFilesystem"}
5+
]

deployments/sgx_enclave_apps/overlays/sgx_ecdsa_inproc_quote/kustomization.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ configMapGenerator:
1010
- sgx_default_qcnl.conf
1111
name: sgx-attestation-conf
1212
patches:
13-
- path: add_hostnetwork.yaml
1413
- path: add_sgx_default_qcnl_conf.yaml
14+
- path: change_workingdir_and_command.json
15+
target:
16+
group: batch
17+
kind: Job
18+
name: intelsgx-demo-job
19+
version: v1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"pccs_url": "https://localhost:8081/sgx/certification/v4/",
3+
"use_secure_cert": false,
4+
"pccs_api_version": "3.1"
5+
}

0 commit comments

Comments
 (0)