Skip to content

Commit 95ccd5c

Browse files
authored
Merge pull request #241 from cgwalters/require-privileges
cli: Explicitly require root privileges
2 parents 05f557f + 7e40a48 commit 95ccd5c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/src/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ pub(crate) fn require_root() -> Result<()> {
245245
/// A few process changes that need to be made for writing.
246246
#[context("Preparing for write")]
247247
pub(crate) async fn prepare_for_write() -> Result<()> {
248+
crate::cli::require_root()?;
248249
if ostree_ext::container_utils::is_ostree_container()? {
249250
anyhow::bail!(
250251
"Detected container (ostree base); this command requires a booted host system."

lib/src/privtests.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,24 @@ pub(crate) fn impl_run_container() -> Result<()> {
104104
let sh = Shell::new()?;
105105
let host: Host = serde_yaml::from_str(&cmd!(sh, "bootc status").read()?)?;
106106
assert!(host.status.is_container);
107+
println!("ok status");
108+
107109
for c in ["upgrade", "update"] {
108110
let o = Command::new("bootc").arg(c).output()?;
109111
let st = o.status;
110112
assert!(!st.success());
111113
let stderr = String::from_utf8(o.stderr)?;
112-
assert!(stderr.contains("this command requires a booted host system"));
114+
assert!(stderr.contains("This command requires full root privileges"));
113115
}
116+
println!("ok upgrade/update are errors in container");
117+
118+
let o = Command::new("runuser")
119+
.args(["-u", "bin", "bootc", "upgrade"])
120+
.output()?;
121+
assert!(!o.status.success());
122+
let stderr = String::from_utf8(o.stderr)?;
123+
assert!(stderr.contains("requires root privileges"));
124+
114125
println!("ok container integration testing");
115126
Ok(())
116127
}

lib/src/status.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ pub(crate) fn get_status(
261261
}
262262

263263
/// Implementation of the `bootc status` CLI command.
264+
#[context("Status")]
264265
pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
265266
let host = if ostree_ext::container_utils::is_ostree_container()? {
266267
let status = HostStatus {
@@ -271,6 +272,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
271272
r.status = status;
272273
r
273274
} else {
275+
crate::cli::require_root()?;
274276
let sysroot = super::cli::get_locked_sysroot().await?;
275277
let booted_deployment = sysroot.booted_deployment();
276278
let (_deployments, host) = get_status(&sysroot, booted_deployment.as_ref())?;

0 commit comments

Comments
 (0)