Skip to content

Commit 8e21e75

Browse files
authored
Include attestation_interval configuration (#1146)
Signed-off-by: Sergio Arroutbi <[email protected]>
1 parent bec5d94 commit 8e21e75

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

keylime-agent.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,13 @@ ima_ml_path = "default"
358358
# If set as a relative path, it will be considered from the root path "/".
359359
# If set as an absolute path, it will use it without changes
360360
measuredboot_ml_path = "default"
361+
362+
# Push attestation model options
363+
# The interval in seconds between attestations after a successful attestation,
364+
# and also used as the retry delay after a failed attestation attempt.
365+
# This option is specific to the push attestation model.
366+
# The default is 60 seconds.
367+
#
368+
# To override attestation_interval_seconds, set
369+
# KEYLIME_AGENT_ATTESTATION_INTERVAL_SECONDS environment variable.
370+
attestation_interval_seconds = 60

keylime-push-model-agent/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ async fn run(args: &Args) -> Result<()> {
179179
attestation_client,
180180
neg_config,
181181
ctx_info,
182-
args.attestation_interval_seconds,
182+
config.attestation_interval_seconds(),
183183
);
184184
state_machine.run().await;
185185
Ok(())

keylime/src/config/base.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ pub const DEFAULT_EXP_BACKOFF_INITIAL_DELAY: u32 = 10000; // 10 seconds
9898
pub const DEFAULT_EXP_BACKOFF_MAX_RETRIES: u32 = 5;
9999
pub const DEFAULT_EXP_BACKOFF_MAX_DELAY: u32 = 300000; // 300 seconds
100100

101+
// Default attestation interval for push model (in seconds)
102+
pub const DEFAULT_ATTESTATION_INTERVAL_SECONDS: u64 = 60;
103+
101104
// TODO These should be temporary
102105
pub const DEFAULT_CERTIFICATION_KEYS_SERVER_IDENTIFIER: &str = "ak";
103106
pub static DEFAULT_PUSH_API_VERSIONS: &[&str] = &["3.0"];
@@ -163,6 +166,7 @@ pub struct AgentConfig {
163166
pub payload_key_password: String,
164167

165168
// Push attestation options
169+
pub attestation_interval_seconds: u64,
166170
pub certification_keys_server_identifier: String,
167171
pub ima_ml_count_file: String,
168172
pub registrar_api_versions: String,
@@ -320,6 +324,8 @@ impl Default for AgentConfig {
320324
trusted_client_ca: "default".to_string(),
321325
uuid: DEFAULT_UUID.to_string(),
322326
version: CONFIG_VERSION.to_string(),
327+
attestation_interval_seconds:
328+
DEFAULT_ATTESTATION_INTERVAL_SECONDS,
323329
certification_keys_server_identifier:
324330
DEFAULT_CERTIFICATION_KEYS_SERVER_IDENTIFIER.to_string(),
325331
ima_ml_count_file: DEFAULT_IMA_ML_COUNT_FILE.to_string(),
@@ -1172,4 +1178,83 @@ mod tests {
11721178
config_get_file_path("test", "", workdir, "default", false);
11731179
assert_eq!("/workdir/default", translated);
11741180
}
1181+
1182+
#[test]
1183+
fn test_attestation_interval_seconds_default() {
1184+
let config = AgentConfig::default();
1185+
assert_eq!(
1186+
config.attestation_interval_seconds,
1187+
DEFAULT_ATTESTATION_INTERVAL_SECONDS
1188+
);
1189+
assert_eq!(config.attestation_interval_seconds, 60);
1190+
}
1191+
1192+
#[test]
1193+
fn test_attestation_interval_seconds_custom() {
1194+
let tempdir = tempfile::tempdir()
1195+
.expect("failed to create temporary directory");
1196+
1197+
let config = AgentConfig {
1198+
keylime_dir: tempdir.path().display().to_string(),
1199+
attestation_interval_seconds: 5,
1200+
..AgentConfig::default()
1201+
};
1202+
1203+
assert_eq!(config.attestation_interval_seconds, 5);
1204+
1205+
// Verify that config_translate_keywords preserves the custom value
1206+
let result = config_translate_keywords(&config);
1207+
assert!(result.is_ok());
1208+
let translated = result.unwrap(); //#[allow_ci]
1209+
assert_eq!(translated.attestation_interval_seconds, 5);
1210+
}
1211+
1212+
#[test]
1213+
fn test_attestation_interval_seconds_constant_value() {
1214+
// Ensure the constant has the expected value
1215+
assert_eq!(DEFAULT_ATTESTATION_INTERVAL_SECONDS, 60);
1216+
}
1217+
1218+
#[test]
1219+
fn test_attestation_interval_from_toml() {
1220+
use std::fs;
1221+
use std::io::Write;
1222+
1223+
let tempdir = tempfile::tempdir()
1224+
.expect("failed to create temporary directory");
1225+
1226+
// Create a temporary config file with custom attestation_interval_seconds
1227+
let config_path = tempdir.path().join("agent.toml");
1228+
let mut file = fs::File::create(&config_path)
1229+
.expect("failed to create config file");
1230+
1231+
writeln!(file, "[agent]").expect("failed to write to config file");
1232+
writeln!(file, "attestation_interval_seconds = 10")
1233+
.expect("failed to write to config file");
1234+
1235+
// Load the configuration
1236+
use config::{Config, File, FileFormat};
1237+
let default_config = AgentConfig {
1238+
keylime_dir: tempdir.path().display().to_string(),
1239+
..AgentConfig::default()
1240+
};
1241+
1242+
let settings = Config::builder()
1243+
.add_source(default_config)
1244+
.add_source(File::from(config_path).format(FileFormat::Toml))
1245+
.build()
1246+
.expect("failed to build config");
1247+
1248+
#[derive(serde::Deserialize)]
1249+
struct Wrapper {
1250+
agent: AgentConfig,
1251+
}
1252+
1253+
let wrapper: Wrapper = settings
1254+
.try_deserialize()
1255+
.expect("failed to deserialize config");
1256+
1257+
// Verify the value was loaded correctly from TOML (overriding default of 60)
1258+
assert_eq!(wrapper.agent.attestation_interval_seconds, 10);
1259+
}
11751260
}

keylime/src/config/push_model.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct PushModelConfig {
3333
agent_data_path: String,
3434
#[transform(using = override_default_api_versions, error = OverrideError)]
3535
api_versions: Vec<&str>,
36+
attestation_interval_seconds: u64,
3637
certification_keys_server_identifier: String,
3738
contact_ip: String,
3839
contact_port: u32,
@@ -132,5 +133,26 @@ mod tests {
132133
);
133134
assert_eq!(config.uuid(), DEFAULT_UUID);
134135
assert_eq!(config.verifier_url(), DEFAULT_VERIFIER_URL);
136+
assert_eq!(
137+
config.attestation_interval_seconds(),
138+
DEFAULT_ATTESTATION_INTERVAL_SECONDS
139+
);
135140
} // create_default_config_test
141+
142+
#[test]
143+
fn test_attestation_interval_seconds_custom() {
144+
let tmpdir = tempfile::tempdir().expect("failed to create tmpdir");
145+
let mut config = get_testing_config(tmpdir.path(), None);
146+
147+
// Modify to use a custom attestation interval
148+
config.attestation_interval_seconds = 5;
149+
150+
assert_eq!(config.attestation_interval_seconds(), 5);
151+
152+
// Verify it's different from default
153+
assert_ne!(
154+
config.attestation_interval_seconds(),
155+
DEFAULT_ATTESTATION_INTERVAL_SECONDS
156+
);
157+
}
136158
}

0 commit comments

Comments
 (0)