Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.

Commit 1d2ff07

Browse files
authored
docs: add verfiy RTMR with replayed event log related content (#186)
Signed-off-by: Longyin Hu <[email protected]>
1 parent 1aa8f27 commit 1d2ff07

File tree

3 files changed

+73
-14
lines changed

3 files changed

+73
-14
lines changed

cnap/core/eventlog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Confidential Cloud-Native Primitives (CCNP), and is defined according to several tcg supported event
55
log formats defined in TCG_PCClient Spec, Canonical Eventlog Spec, etc.
66
7-
CCNP: https://github.com/intel/confidential-cloud-native-primitives
7+
CCNP: https://github.com/cc-api/confidential-cloud-native-primitives
88
TCG_PCClient Spec:
99
https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientSpecPlat_TPM_2p0_1p04_pub.pdf
1010
Canonical Eventlog Spec:

docs/How_to_Protect_AI_Models_in_Cloud_Native_Environments.md

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ To ensure the cloud native environments and AI models are secure protected in us
1010

1111
## 1. Architecture Design
1212

13-
This design can be divided into three steps logically.
13+
This design can be divided into four steps logically.
1414
- A plain AI model is preprocessed before uploading or use in cloud native environment. AI model should be encrypted offline, and the encryption key will be stored in a key database server.
15+
- Fetch and verify event logs. Event logs are the record of measurements made to PCRs (PCR: Platform Configuration Register) by the Platform Firmware, with some informational events not extended to PCRs. The informational events are used to convey valuable information to an evaluator of the log. Each measurement made, as well as the information events, are recorded in the event logs as individual entries with specified fields. Event logs can assist the attestation/verification process. For more detail, please refer to [TCG_PCClient Spec](https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientSpecPlat_TPM_2p0_1p04_pub.pdf).
1516
- Attestation of the cloud native environment. Attestation is a confidential computing keystone. With attestation, AI models owner can fully assert the trustworthiness of the hardware and software environment AI is running in, regardless of the security posture of the underlying infrastructure provider.
1617
- AI Model fetching and decryption. Before CNAP can start its AI pipeline streaming inference, a proper AI model has to be downloaded then decrypted.
1718

@@ -26,15 +27,34 @@ To protect the model and its encryption key, the following preprocessing steps a
2627
- Upload the encrypted model to Model Server.
2728
- Register key to Key Broker Service (KBS), and KBS will communicate with Key Management Service (KMS) to store the key in its database.
2829

29-
### 1.2 Attestation by using Confidential Cloud-Native Primitives (CCNP)
30+
### 1.2 Fetch and Verify Event Logs by using Confidential Cloud-Native Primitives (CCNP)
3031

31-
[CCNP](https://github.com/intel/confidential-cloud-native-primitives) is to enable Intel Trust Domain Extensions (TDX) or other TEE technologies and simplify the usage of TEE in cloud native environment. It comprises two main components: the services and the SDK, which includes event log, measurement, quote generation and other APIs.
32+
[CCNP](https://github.com/cc-api/confidential-cloud-native-primitives) is to enable Intel Trust Domain Extensions (TDX) or other TEE technologies and simplify the usage of TEE in cloud native environment. It comprises two main components: the services and the SDK, which includes event logs, measurement, quote generation and other APIs.
3233

3334
- Service is designed to hide the complexity of different TEE platforms and provides common interfaces and scalability for cloud native environment.
3435

3536
- SDK is to simplify the use of the service interface for development, it communicates to the service and parses the return results from the services.
3637

37-
The service supports attestation, measurement fetching and event log collecting of various platforms including Intel TDX, Trusted Platform Modules (TPM) and AMD Secure Encrypted Virtualization-Secure Nested Paging (SEV-SNP) (will be supported soon).
38+
The service supports attestation, measurement fetching and event logs collecting of various platforms including Intel TDX, Trusted Platform Modules (TPM) and AMD Secure Encrypted Virtualization-Secure Nested Paging (SEV-SNP) (will be supported soon).
39+
40+
CCNP is a good choice to fetch these evidences including measurements and event logs, which hides the complexity of the underlying platforms and increase the usability of the APIs. Here's the sample code using CCNP:
41+
42+
```Python
43+
from ccnp import Eventlog
44+
event_logs = Eventlog.get_platform_eventlog()
45+
```
46+
47+
To verify that the event logs have not been tampered with, we can compare the measurement replayed from event logs with the IMR (Integrated Measurement Register) values fetched using CCNP.
48+
Here's the sample code using CCNP to fetch IMR values (use Intel TDX RTMR as example):
49+
50+
```Python
51+
from ccnp import Measurement, MeasurementType
52+
imr_measurement = Measurement.get_platform_measurement(MeasurementType.TYPE_TDX_RTMR, None, 1)
53+
```
54+
55+
CCNP API detail documentation can be found [here](https://intel.github.io/confidential-cloud-native-primitives/).
56+
57+
### 1.3 Attestation by using Confidential Cloud-Native Primitives (CCNP)
3858

3959
To get the key to decrypt the model, we need provide the quote of TEE for attestation, CCNP is a good choice to get the quote and it hides the complexity and is easy to use, sample code from CCNP:
4060

@@ -43,13 +63,12 @@ from ccnp import Quote
4363
quote=Quote.get_quote()
4464
```
4565

46-
CCNP API detail documentation can be found [here](https://intel.github.io/confidential-cloud-native-primitives/).
47-
48-
### 1.3 AI Model Decryption
66+
### 1.4 AI Model Decryption
4967

5068
CNAP project’s Inference Service flow of getting AI model should be updated to support TEE environment since the AI model has been encrypted:
5169

5270
- Deploy CCNP as a [DaemonSet](https://intel.github.io/confidential-cloud-native-primitives/_rst/service.quote.html#deploy-as-daemonset-in-kubernetes), it will detect the TEE environment.
71+
- Fetch and verify event logs.
5372
- Get the quote and request the key from KBS.
5473
- Download the encrypted AI model from Model Server.
5574
- Decrypt AI model and load the model in memory to start AI streaming inference.
@@ -60,7 +79,7 @@ Current Cloud-Native AI Pipeline (CNAP) project already implements the new desig
6079

6180
To protect AI model, the first thing is to generate a key for model encryption, encrypt the model and register the key to KBS. Then KBS will submit further request to store the key to KMS.
6281

63-
To fetch and decrypt the model, the runtime environment should be verified by attestation. A key broker client should get a quote and send the quote to KBS to verify that it is running on an authentic TEE platform. Upon successful attestation, KBS will then respond with a wrapped key for AI model's decryption later.
82+
To fetch and decrypt the model, the runtime environment should be verified by event logs and attestation. A key broker client should get a quote and send the quote to KBS to verify that it is running on an authentic TEE platform. Upon successful attestation, KBS will then respond with a wrapped key for AI model's decryption later.
6483

6584
### 2.1 AI Model Encryption
6685

@@ -159,6 +178,7 @@ An sample working flow of a simple KBS implementation:
159178

160179
For a key broker client, here is an example working flow of key broker client to get a key from KBS:
161180

181+
- Get and replay all event logs, and verify by the measurement register.
162182
- Generate 2048 bit RSA key pair (a public key and a private key).
163183
- Encode the public key to base64 for transferring (user_data).
164184
- Get quote in the TEE with the hash of the public key for measurement (quote).
@@ -192,7 +212,45 @@ req_body = {
192212
}
193213
```
194214

195-
### 2.5 Attestation
215+
### 2.5 Fetch and Verify Event Logs
216+
217+
CCNP provides an easy way to fetch and verify event logs in TEE. After fetching event logs, we can compare the measurement replayed from event logs with the IMR (Integrated Measurement Register) values fetched using CCNP to verify that event logs have not been tampered with.
218+
219+
We can fetch, replay and verify event logs before attestation, the sample code:
220+
221+
```Python
222+
import logging
223+
224+
from ccnp import Eventlog, Measurement, MeasurementType
225+
226+
LOG = logging.getLogger(__name__)
227+
IMR_VERIFY_COUNT = 3
228+
229+
# Fetch event logs using CCNP and replay.
230+
event_logs = Eventlog.get_platform_eventlog()
231+
measurement_dict = replay(event_logs)
232+
233+
# Fetch IMR measurement (use Intel TDX RTMR as example) and verify with replayed value.
234+
for index in range(IMR_VERIFY_COUNT):
235+
# Fectch IMR measurement
236+
imr_measurement = base64.b64decode(Measurement.get_platform_measurement(
237+
MeasurementType.TYPE_TDX_RTMR, None, index))
238+
239+
# Get IMR value from replayed event logs
240+
for value in measurement_dict[index].values():
241+
imr_replayed = value
242+
break
243+
244+
if imr_measurement == imr_replayed:
245+
LOG.info("IMR[%d] passed the verification.", index)
246+
else:
247+
LOG.error("IMR[%d] did not pass the verification.", index)
248+
raise RuntimeError("Event logs verify failed.")
249+
250+
LOG.info("Event logs verify successfully.")
251+
```
252+
253+
### 2.6 Attestation
196254

197255
CCNP provides an easy way to get the quote for attestation in TEE. Before getting the quote, a RSA key pair need to be generated for wrapping purpose and the public key will be measured as the user data input to the quote fetching process.
198256

@@ -214,7 +272,7 @@ user_data = base64.b64encode(pubkey_der).decode('utf-8')
214272
quote = Quote.get_quote(user_data=user_data)
215273
```
216274

217-
### 2.6 AI Model Decryption
275+
### 2.7 AI Model Decryption
218276

219277
Just like the encryption, the AES-256-GCM encrypted data format should be:
220278

@@ -251,11 +309,12 @@ def decrypt_data(encrypted_data, key) -> bytes:
251309
## Conclusion
252310

253311
As organizations move more of their AI workloads to the cloud, AI models security, and protection has become more important. Confidential computing provides a set of technologies designed to protect data in use, such as AI models currently being processed by the machine, or currently in memory.
254-
This document describes a common architecture to “design and run” a native AI Model into confidential computing environments. (1) AI Model preprocess (2) Attestation of the cloud native environment (3) AI Model fetching and decryption.
255-
Intel’s TDX technology can provide a TEE running environment, and CCNP can simply the attestation of confidential native environment, last but not least, a sample KBS is introduced to help customer to connect with its own or vendor-independent attestation service (for example, Intel Trust Authority).
312+
This document describes a common architecture to “design and run” a native AI Model into confidential computing environments. (1) AI Model preprocess (2) Fetch and verify event logs (3) Attestation of the cloud native environment (4) AI Model fetching and decryption.
313+
Intel’s TDX technology can provide a TEE running environment, and CCNP can simplify the event logs, measurement fetching and attestation of confidential native environment, last but not least, a sample KBS is introduced to help customer to connect with its own or vendor-independent attestation service (for example, Intel Trust Authority).
256314

257315
# References
258316

259317
1. Model Provider: https://github.com/intel/cloud-native-ai-pipeline/blob/main/cnap/core/modelprovider.py
260318
2. Key Broker Client: https://github.com/intel/cloud-native-ai-pipeline/blob/main/cnap/core/keybroker.py
261-
3. CCNP: https://github.com/intel/confidential-cloud-native-primitives
319+
3. CCNP: https://github.com/cc-api/confidential-cloud-native-primitives
320+
4. TCG_PCClient Spec: https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientSpecPlat_TPM_2p0_1p04_pub.pdf

docs/secure-model-design.png

-8.38 KB
Loading

0 commit comments

Comments
 (0)