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

Handle whitespace in keylime.conf #409

Merged
merged 1 commit into from
Jul 20, 2022
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
18 changes: 15 additions & 3 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,19 @@ impl KeylimeConfig {
Ok(s) => bool::from_str(&s.to_lowercase())?,
Err(_) => ALLOW_PAYLOAD_REV_ACTIONS,
};

let run_as = if permissions::get_euid() == 0 {
match config_get(&conf_name, &conf, "cloud_agent", "run_as") {
Ok(user_group) => Some(user_group),
Ok(user_group) => {
if user_group.is_empty() {
warn!("Cannot drop privileges since 'run_as' is empty in 'cloud_agent' section of keylime.conf.");
None
} else {
Some(user_group)
}
}
Err(_) => {
warn!("Cannot drop privileges since 'run_as' is empty or missing in 'cloud_agent' section of keylime.conf.");
warn!("Cannot drop privileges since 'run_as' is missing in 'cloud_agent' section of keylime.conf.");
None
}
}
Expand Down Expand Up @@ -698,7 +706,7 @@ fn config_get(
}
};
let value = match section.get(key) {
Some(value) => value,
Some(value) => value.trim(),
None =>
// TODO: Make Error::Configuration an alternative with data instead of string
{
Expand All @@ -709,6 +717,10 @@ fn config_get(
}
};

if value.is_empty() {
warn!("Cannot find value for key {} in file {}", key, conf_name);
};

Ok(value.to_string())
}

Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,12 @@ async fn main() -> Result<()> {
// Drop privileges
if let Some(user_group) = &config.run_as {
permissions::chown(user_group, &mount);
permissions::run_as(user_group);
if let Err(e) = permissions::run_as(user_group) {
let message = "The user running the Keylime agent should be set in keylime.conf, using the parameter `run_as`, with the format `user:group`".to_string();

error!("Configuration error: {}", &message);
return Err(Error::Configuration(message));
}
}

info!("Starting server with API version {}...", API_VERSION);
Expand Down