Skip to content

Commit d6f2254

Browse files
committed
Rename mr_image to os_image_hash
1 parent 5261e8b commit d6f2254

File tree

36 files changed

+236
-524
lines changed

36 files changed

+236
-524
lines changed

docs/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ cd dstack/kms/dstack-app/
8787
```
8888
It will create a template `.env` file. Edit the `.env` file and set the required variables.
8989
Especially the `KMS_CONTRACT_ADDR` variable set to the address of the KmsAuth Proxy contract deployed in the previous step.
90-
The `IMAGE_DOWNLOAD_URL` variable should be set to the URL of the dstack OS image used to verify the mr_image.
90+
The `IMAGE_DOWNLOAD_URL` variable should be set to the URL of the dstack OS image used to verify the os_image_hash.
9191
```
9292
# .env
9393
VMM_RPC=unix:../../vmm-data/vmm.sock

dstack-types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub struct SysConfig {
125125
#[derive(Deserialize, Serialize, Debug, Clone)]
126126
pub struct VmConfig {
127127
#[serde(with = "hex_bytes")]
128-
pub mr_image: Vec<u8>,
128+
pub os_image_hash: Vec<u8>,
129129
pub cpu_count: u32,
130130
pub memory_size: u64,
131131
}

dstack-util/src/system_setup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ impl<'a> Stage0<'a> {
326326
.await
327327
.context("Failed to get app key")?;
328328

329-
extend_rtmr3("mr-image", &response.mr_image)
330-
.context("Failed to extend mr-image to RTMR3")?;
329+
extend_rtmr3("os-image-hash", &response.os_image_hash)
330+
.context("Failed to extend os-image-hash to RTMR3")?;
331331

332332
let keys = AppKeys {
333333
ca_cert: tmp_ca.ca_cert,

guest-agent/rpc/proto/agent_rpc.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ message WorkerInfo {
192192
// MR Aggregated
193193
bytes mr_aggregated = 9;
194194
// MR Image
195-
bytes mr_image = 10;
195+
bytes os_image_hash = 10;
196196
// MR Key Provider
197197
bytes mr_key_provider = 11;
198198
// Key provider info

guest-agent/src/http_routes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async fn index(state: &State<AppState>) -> Result<RawHtml<String>, String> {
3232
instance_id,
3333
device_id,
3434
mr_aggregated: _,
35-
mr_image: _,
35+
os_image_hash: _,
3636
mr_key_provider: _,
3737
key_provider_info,
3838
compose_hash: _,

guest-agent/src/rpc_service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ impl WorkerRpc for ExternalRpcHandler {
356356
"rtmr2": hex::encode(app_info.rtmr2),
357357
"rtmr3": hex::encode(app_info.rtmr3),
358358
"mr_aggregated": hex::encode(app_info.mr_aggregated),
359-
"mr_image": hex::encode(&app_info.mr_image),
359+
"os_image_hash": hex::encode(&app_info.os_image_hash),
360360
"mr_key_provider": hex::encode(app_info.mr_key_provider),
361361
"compose_hash": hex::encode(&app_info.compose_hash),
362362
"device_id": hex::encode(&app_info.device_id),
@@ -370,7 +370,7 @@ impl WorkerRpc for ExternalRpcHandler {
370370
instance_id: app_info.instance_id,
371371
device_id: app_info.device_id,
372372
mr_aggregated: app_info.mr_aggregated.to_vec(),
373-
mr_image: app_info.mr_image.clone(),
373+
os_image_hash: app_info.os_image_hash.clone(),
374374
mr_key_provider: app_info.mr_key_provider.to_vec(),
375375
key_provider_info: String::from_utf8(app_info.key_provider_info).unwrap_or_default(),
376376
compose_hash: app_info.compose_hash.clone(),

kms/auth-eth/contracts/IAppAuth.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface IAppAuth {
99
bytes32 deviceId;
1010
bytes32 mrAggregated;
1111
bytes32 mrSystem;
12-
bytes32 mrImage;
12+
bytes32 osImageHash;
1313
string tcbStatus;
1414
string[] advisoryIds;
1515
}

kms/auth-eth/contracts/KmsAuth.sol

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ contract KmsAuth is
4343
mapping(bytes32 => bool) public kmsAllowedDeviceIds;
4444

4545
// Mapping of allowed image measurements
46-
mapping(bytes32 => bool) public appAllowedImages;
47-
48-
// Mapping of allowed KMS compose hashes
49-
mapping(bytes32 => bool) public appAllowedSystemMrs;
46+
mapping(bytes32 => bool) public allowedOsImages;
5047

5148
// Sequence number for app IDs - per user
5249
mapping(address => uint256) public nextAppSequence;
@@ -58,10 +55,8 @@ contract KmsAuth is
5855
event KmsAggregatedMrRemoved(bytes32 mrAggregated);
5956
event KmsDeviceAdded(bytes32 deviceId);
6057
event KmsDeviceRemoved(bytes32 deviceId);
61-
event AppImageMrAdded(bytes32 mrImage);
62-
event AppImageMrRemoved(bytes32 mrImage);
63-
event AppSystemMrAdded(bytes32 mrSystem);
64-
event AppSystemMrRemoved(bytes32 mrSystem);
58+
event OsImageHashAdded(bytes32 osImageHash);
59+
event OsImageHashRemoved(bytes32 osImageHash);
6560
event GatewayAppIdSet(string gatewayAppId);
6661

6762
/// @custom:oz-upgrades-unsafe-allow constructor
@@ -150,27 +145,15 @@ contract KmsAuth is
150145
}
151146

152147
// Function to register an image measurement
153-
function addAppImageMr(bytes32 mrImage) external onlyOwner {
154-
appAllowedImages[mrImage] = true;
155-
emit AppImageMrAdded(mrImage);
148+
function addOsImageHash(bytes32 osImageHash) external onlyOwner {
149+
allowedOsImages[osImageHash] = true;
150+
emit OsImageHashAdded(osImageHash);
156151
}
157152

158153
// Function to deregister an image measurement
159-
function removeAppImageMr(bytes32 mrImage) external onlyOwner {
160-
appAllowedImages[mrImage] = false;
161-
emit AppImageMrRemoved(mrImage);
162-
}
163-
164-
// Function to register a system MR measurement
165-
function addAppSystemMr(bytes32 mrSystem) external onlyOwner {
166-
appAllowedSystemMrs[mrSystem] = true;
167-
emit AppSystemMrAdded(mrSystem);
168-
}
169-
170-
// Function to deregister a system MR measurement
171-
function removeAppSystemMr(bytes32 mrSystem) external onlyOwner {
172-
appAllowedSystemMrs[mrSystem] = false;
173-
emit AppSystemMrRemoved(mrSystem);
154+
function removeOsImageHash(bytes32 osImageHash) external onlyOwner {
155+
allowedOsImages[osImageHash] = false;
156+
emit OsImageHashRemoved(osImageHash);
174157
}
175158

176159
// Function to check if KMS is allowed to boot
@@ -185,6 +168,11 @@ contract KmsAuth is
185168
return (false, "TCB status is not up to date");
186169
}
187170

171+
// Check if the OS image is allowed
172+
if (!allowedOsImages[bootInfo.osImageHash]) {
173+
return (false, "OS image is not allowed");
174+
}
175+
188176
// Check if the aggregated MR is allowed
189177
if (!kmsAllowedAggregatedMrs[bootInfo.mrAggregated]) {
190178
return (false, "Aggregated MR not allowed");
@@ -208,11 +196,8 @@ contract KmsAuth is
208196
}
209197

210198
// Check aggregated MR and image measurements
211-
if (
212-
!appAllowedSystemMrs[bootInfo.mrSystem] &&
213-
!appAllowedImages[bootInfo.mrImage]
214-
) {
215-
return (false, "Neither system MR nor image is allowed");
199+
if (!allowedOsImages[bootInfo.osImageHash]) {
200+
return (false, "OS image is not allowed");
216201
}
217202

218203
// Ask the app controller if the app is allowed to boot

kms/auth-eth/hardhat.config.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -142,41 +142,23 @@ task("kms:remove", "Remove a Aggregated MR of an KMS instance")
142142

143143
// Image Management Tasks
144144
task("kms:add-image", "Add an image measurement")
145-
.addPositionalParam("mrImage", "Image measurement")
146-
.setAction(async ({ mrImage }, { ethers }) => {
145+
.addPositionalParam("osImageHash", "Image measurement")
146+
.setAction(async ({ osImageHash }, { ethers }) => {
147147
const kmsAuth = await getKmsAuth(ethers);
148-
const tx = await kmsAuth.addAppImageMr(mrImage);
148+
const tx = await kmsAuth.addOsImageHash(osImageHash);
149149
await waitTx(tx);
150150
console.log("Image added successfully");
151151
});
152152

153153
task("kms:remove-image", "Remove an image measurement")
154-
.addPositionalParam("mrImage", "Image measurement")
155-
.setAction(async ({ mrImage }, { ethers }) => {
154+
.addPositionalParam("osImageHash", "Image measurement")
155+
.setAction(async ({ osImageHash }, { ethers }) => {
156156
const kmsAuth = await getKmsAuth(ethers);
157-
const tx = await kmsAuth.removeAppImageMr(mrImage);
157+
const tx = await kmsAuth.removeOsImageHash(osImageHash);
158158
await waitTx(tx);
159159
console.log("Image removed successfully");
160160
});
161161

162-
task("kms:add-system", "Add a system measurement")
163-
.addPositionalParam("mrSystem", "System measurement")
164-
.setAction(async ({ mrSystem }, { ethers }) => {
165-
const kmsAuth = await getKmsAuth(ethers);
166-
const tx = await kmsAuth.addAppSystemMr(mrSystem);
167-
await waitTx(tx);
168-
console.log("System measurement added successfully");
169-
});
170-
171-
task("kms:remove-system", "Remove a system measurement")
172-
.addPositionalParam("mrSystem", "System measurement")
173-
.setAction(async ({ mrSystem }, { ethers }) => {
174-
const kmsAuth = await getKmsAuth(ethers);
175-
const tx = await kmsAuth.removeAppSystemMr(mrSystem);
176-
await waitTx(tx);
177-
console.log("System measurement removed successfully");
178-
});
179-
180162
task("kms:add-device", "Add a device ID of an KMS instance")
181163
.addPositionalParam("deviceId", "Device ID")
182164
.setAction(async ({ deviceId }, { ethers }) => {

kms/auth-eth/run-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm run test

0 commit comments

Comments
 (0)