mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-16 07:05:14 +00:00
env: Check for root privileges
Check for root privileges early on. Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
1016bc17b7
commit
fb40c71a21
@ -13,6 +13,7 @@ use crate::utils;
|
|||||||
use kata_types::config::TomlConfig;
|
use kata_types::config::TomlConfig;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
|
use nix::unistd::Uid;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
@ -441,6 +442,10 @@ pub fn get_env_info(toml_config: &TomlConfig) -> Result<EnvInfo> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_env(env_args: EnvArgument) -> Result<()> {
|
pub fn handle_env(env_args: EnvArgument) -> Result<()> {
|
||||||
|
if !Uid::effective().is_root() {
|
||||||
|
return Err(anyhow!("kata-ctl env command requires root privileges to get host information. Please run as root or use sudo"));
|
||||||
|
}
|
||||||
|
|
||||||
let mut file: Box<dyn Write> = if let Some(path) = env_args.file {
|
let mut file: Box<dyn Write> = if let Some(path) = env_args.file {
|
||||||
Box::new(
|
Box::new(
|
||||||
File::create(path.as_str()).with_context(|| format!("Error creating file {}", path))?,
|
File::create(path.as_str()).with_context(|| format!("Error creating file {}", path))?,
|
||||||
|
Loading…
Reference in New Issue
Block a user