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

Add check to prevent the Parsec service from running as root #219

Merged
merged 1 commit into from
Aug 18, 2020
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
5 changes: 5 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# (Required) Core settings apply to the service as a whole rather than to individual components within it.
[core_settings]
# Whether or not to allow the service to run as the root user. If this is false, the service will refuse to
# start if it is run as root. If this is true, the safety check is disabled and the service will be allowed to
# start even if it is being run as root. The recommended (and default) setting is FALSE; allowing Parsec to
# run as root violates the principle of least privilege.
#allow_root = false
# Size of the thread pool used for processing requests. Defaults to the number of processors on
# the machine.
#thread_pool_size = 8
Expand Down
4 changes: 4 additions & 0 deletions e2e_tests/provider_cfg/all/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
log_timestamp = false
log_error_details = true

# The container runs the Parsec service as root, so make sure we disable root
# checks.
allow_root = true

[listener]
listener_type = "DomainSocket"
timeout = 200 # in milliseconds
Expand Down
4 changes: 4 additions & 0 deletions e2e_tests/provider_cfg/mbed-crypto/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
log_timestamp = false
log_error_details = true

# The container runs the Parsec service as root, so make sure we disable root
# checks.
allow_root = true

[listener]
listener_type = "DomainSocket"
# The timeout needs to be smaller than the test client timeout (five seconds) as it is testing
Expand Down
4 changes: 4 additions & 0 deletions e2e_tests/provider_cfg/pkcs11/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
log_timestamp = false
log_error_details = true

# The container runs the Parsec service as root, so make sure we disable root
# checks.
allow_root = true

[listener]
listener_type = "DomainSocket"
# The timeout needs to be smaller than the test client timeout (five seconds) as it is testing
Expand Down
4 changes: 4 additions & 0 deletions e2e_tests/provider_cfg/tpm/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
log_timestamp = false
log_error_details = true

# The container runs the Parsec service as root, so make sure we disable root
# checks.
allow_root = true

[listener]
listener_type = "DomainSocket"
# The timeout needs to be smaller than the test client timeout (five seconds) as it is testing
Expand Down
12 changes: 12 additions & 0 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use std::sync::{
};
use std::time::Duration;
use structopt::StructOpt;
use users::get_current_uid;

/// Parsec is the Platform AbstRaction for SECurity, a new open-source initiative to provide a
/// common API to secure services in a platform-agnostic way.
Expand Down Expand Up @@ -84,6 +85,17 @@ fn main() -> Result<()> {
)
})?;

// Guard against running as root. This check can be overridden by changing `allow_root` inside
// the config file.
let allow_root = config.core_settings.allow_root.unwrap_or(false);
if !allow_root && get_current_uid() == 0 {
return Err(Error::new(
ErrorKind::Other,
"Insecure configuration; the Parsec service should not be running as root! You can \
modify `allow_root` in the config file to bypass this check (not recommended).",
));
}

log_setup(&config);

info!("Parsec started. Configuring the service...");
Expand Down
1 change: 1 addition & 0 deletions src/utils/service_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct CoreSettings {
pub log_timestamp: Option<bool>,
pub body_len_limit: Option<usize>,
pub log_error_details: Option<bool>,
pub allow_root: Option<bool>,
}

#[derive(Deserialize, Debug)]
Expand Down