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

kms: Allow upgrade base image #69

Merged
merged 2 commits into from
Dec 19, 2024
Merged
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
8 changes: 7 additions & 1 deletion kms/rpc/proto/kms_rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import "google/protobuf/empty.proto";

package kms;

message GetAppKeyRequest {
// When upgradable is true, the disk encryption key is derived without the rootfs hash
// so that the app can upgrade the base image
bool upgradable = 1;
}

// The kms public RPC service.
service KMS {
// Request the app key given the app id and tdx quote
rpc GetAppKey(google.protobuf.Empty) returns (AppKeyResponse) {
rpc GetAppKey(GetAppKeyRequest) returns (AppKeyResponse) {
// Retrieves the app key and certificate given the app id and tdx quote
}
// Request the app environment encryption public key given the app id
Expand Down
27 changes: 14 additions & 13 deletions kms/src/main_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use anyhow::{bail, Context, Result};
use kms_rpc::{
kms_server::{KmsRpc, KmsServer},
AppId, AppKeyResponse, PublicKeyResponse,
AppId, AppKeyResponse, GetAppKeyRequest, PublicKeyResponse,
};
use ra_rpc::{CallContext, RpcCall};
use ra_tls::{
Expand Down Expand Up @@ -111,7 +111,7 @@ impl RpcHandler {
}

impl KmsRpc for RpcHandler {
async fn get_app_key(self) -> Result<AppKeyResponse> {
async fn get_app_key(self, request: GetAppKeyRequest) -> Result<AppKeyResponse> {
let attest = self.ensure_attested()?;
let app_id = attest.decode_app_id().context("Failed to decode app ID")?;
let instance_id = attest
Expand All @@ -133,17 +133,18 @@ impl KmsRpc for RpcHandler {
&[app_id.as_bytes(), "app-key".as_bytes()],
)
.context("Failed to derive app key")?;

let app_disk_key = derive_ecdsa_key_pair(
&state.root_ca.key,
&[
rootfs_hash.as_bytes(),
app_id.as_bytes(),
instance_id.as_bytes(),
"app-disk-crypt-key".as_bytes(),
],
)
.context("Failed to derive app disk key")?;
let mut context_data = if request.upgradable {
vec![]
} else {
vec![rootfs_hash.as_bytes()]
};
context_data.extend(vec![
app_id.as_bytes(),
instance_id.as_bytes(),
"app-disk-crypt-key".as_bytes(),
]);
let app_disk_key = derive_ecdsa_key_pair(&state.root_ca.key, &context_data)
.context("Failed to derive app disk key")?;

let env_crypt_key = {
let secret = derive_dh_secret(
Expand Down
6 changes: 3 additions & 3 deletions tdxctl/src/fde_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{

use anyhow::{bail, Context, Result};
use fs_err as fs;
use kms_rpc::GetAppKeyRequest;
use ra_rpc::client::RaClient;
use serde::{Deserialize, Serialize};
use tracing::{info, warn};
Expand Down Expand Up @@ -96,8 +97,7 @@ struct InstanceInfo {

impl InstanceInfo {
fn is_bootstrapped(&self) -> bool {
self.bootstrapped
.unwrap_or_else(|| !self.instance_id.is_empty())
self.bootstrapped.unwrap_or(!self.instance_id.is_empty())
}
}

Expand Down Expand Up @@ -228,7 +228,7 @@ impl SetupFdeArgs {
)?;
let kms_client = kms_rpc::kms_client::KmsClient::new(ra_client);
let response = kms_client
.get_app_key()
.get_app_key(GetAppKeyRequest { upgradable: true })
.await
.context("Failed to get app key")?;
let keys_json =
Expand Down
Loading