Skip to content

Commit 77f67e1

Browse files
committed
keylimeclt: add support for --tpm-policy
Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent 7c01e59 commit 77f67e1

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

keylimectl/src/commands/agent.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub async fn execute(
161161
cert_dir,
162162
verify,
163163
push_model,
164+
tpm_policy,
164165
} => add_agent(
165166
AddAgentParams {
166167
agent_id: uuid,
@@ -173,6 +174,7 @@ pub async fn execute(
173174
cert_dir: cert_dir.as_deref(),
174175
verify: *verify,
175176
push_model: *push_model,
177+
tpm_policy: tpm_policy.as_deref(),
176178
},
177179
config,
178180
output,
@@ -258,6 +260,8 @@ struct AddAgentParams<'a> {
258260
verify: bool,
259261
/// Whether to use push model (agent connects to verifier)
260262
push_model: bool,
263+
/// Optional TPM policy in JSON format
264+
tpm_policy: Option<&'a str>,
261265
}
262266

263267
/// Add an agent to the verifier for continuous attestation monitoring
@@ -501,13 +505,17 @@ async fn add_agent(
501505
// Build the request payload
502506
let cv_agent_ip = params.verifier_ip.unwrap_or(&agent_ip);
503507

508+
// Resolve TPM policy from CLI argument or default
509+
let tpm_policy = resolve_tpm_policy(params.tpm_policy);
510+
504511
let mut request_data = json!({
505512
"cloudagent_ip": cv_agent_ip,
506513
"cloudagent_port": agent_port,
507514
"verifier_ip": config.verifier.ip,
508515
"verifier_port": config.verifier.port,
509516
"ak_tpm": agent_data.get("aik_tpm"),
510517
"mtls_cert": agent_data.get("mtls_cert"),
518+
"tpm_policy": tpm_policy,
511519
});
512520

513521
// Add V key from attestation if available
@@ -824,6 +832,7 @@ async fn update_agent(
824832
cert_dir: None, // Use default cert handling
825833
verify: false, // Skip verification during update
826834
push_model: existing_push_model, // Preserve existing model
835+
tpm_policy: None, // Use default policy during update
827836
},
828837
config,
829838
output,
@@ -1367,10 +1376,19 @@ fn load_payload_file(path: &str) -> Result<String, CommandError> {
13671376
})
13681377
}
13691378

1379+
/// Resolve TPM policy from various sources with proper precedence
1380+
///
1381+
/// Precedence order:
1382+
/// 1. Explicit CLI --tmp-policy argument
1383+
/// 2. Default empty policy "{}"
1384+
fn resolve_tpm_policy(explicit_policy: Option<&str>) -> String {
1385+
explicit_policy.unwrap_or("{}").to_string()
1386+
}
1387+
13701388
/// Generate a random string of the specified length
13711389
///
13721390
/// Uses system time as seed for a simple random string generator. This is a simple
1373-
/// replacement for the missing tpm_util::random_password function.
1391+
/// replacement for the missing tmp_util::random_password function.
13741392
fn generate_random_string(length: usize) -> String {
13751393
let charset: &[u8] =
13761394
b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

keylimectl/src/commands/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ mod tests {
926926
"port": 9002,
927927
"verifier_ip": "192.168.1.1",
928928
"verifier_port": 8881,
929-
"tmp_policy": "{}",
929+
"tpm_policy": "{}",
930930
"ima_policy": "{}",
931931
"aik_tpm": "a".repeat(1024), // 1KB key
932932
"ek_tpm": "b".repeat(1024), // 1KB key

keylimectl/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ enum AgentAction {
176176
/// Use push model (agent connects to verifier)
177177
#[arg(long)]
178178
push_model: bool,
179+
180+
/// TPM policy in JSON format
181+
#[arg(long, value_name = "POLICY")]
182+
tpm_policy: Option<String>,
179183
},
180184

181185
/// Remove an agent from the verifier

0 commit comments

Comments
 (0)