-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sandboxer: Replace features with bin parameter
Fix #54
- Loading branch information
Showing
15 changed files
with
335 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ target | |
!**/src/api/mod.rs | ||
shim/Cargo.lock | ||
vmm/common/Cargo.lock | ||
!/vmm/sandbox/src/bin/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2022 The Kuasar Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use std::str::FromStr; | ||
|
||
use anyhow::Result; | ||
use vmm_sandboxer::{ | ||
cloud_hypervisor::{ | ||
config::CloudHypervisorVMConfig, factory::CloudHypervisorVMFactory, | ||
hooks::CloudHypervisorHooks, | ||
}, | ||
load_config, | ||
sandbox::KuasarSandboxer, | ||
CONFIG_CLH_PATH, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
// Initialize logging | ||
let mut builder = env_logger::Builder::from_default_env(); | ||
builder.format_timestamp_micros(); | ||
|
||
// Initialize sandboxer | ||
let sandboxer = init_cloud_hypervisor_sandboxer().await?; | ||
|
||
// If 'log_level' field isn't set in the config file, keep the log level from the default env | ||
// Otherwise, set the log level configured in the config file | ||
if !sandboxer.log_level().is_empty() { | ||
let log_level = log::LevelFilter::from_str(sandboxer.log_level())?; | ||
builder.filter_level(log_level); | ||
} | ||
builder.init(); | ||
|
||
// Run the sandboxer | ||
containerd_sandbox::run("kuasar-sandboxer", sandboxer) | ||
.await | ||
.unwrap(); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn init_cloud_hypervisor_sandboxer( | ||
) -> Result<KuasarSandboxer<CloudHypervisorVMFactory, CloudHypervisorHooks>> { | ||
let (config, persist_dir_path) = | ||
load_config::<CloudHypervisorVMConfig>(CONFIG_CLH_PATH).await?; | ||
let hooks = CloudHypervisorHooks {}; | ||
let mut s = KuasarSandboxer::new(config.sandbox, config.hypervisor, hooks); | ||
if !persist_dir_path.is_empty() { | ||
s.recover(&persist_dir_path).await?; | ||
} | ||
Ok(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2022 The Kuasar Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use std::{env, path::Path, str::FromStr}; | ||
|
||
use anyhow::Result; | ||
use vmm_sandboxer::{ | ||
kata_config::KataConfig, | ||
qemu::{factory::QemuVMFactory, hooks::QemuHooks}, | ||
sandbox::KuasarSandboxer, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
// Initialize logging | ||
let mut builder = env_logger::Builder::from_default_env(); | ||
builder.format_timestamp_micros(); | ||
|
||
// Initialize sandboxer | ||
let sandboxer = init_qemu_sandboxer().await?; | ||
|
||
// If 'log_level' field isn't set in the config file, keep the log level from the default env | ||
// Otherwise, set the log level configured in the config file | ||
if !sandboxer.log_level().is_empty() { | ||
let log_level = log::LevelFilter::from_str(sandboxer.log_level())?; | ||
builder.filter_level(log_level); | ||
} | ||
builder.init(); | ||
|
||
// Run the sandboxer | ||
containerd_sandbox::run("kuasar-sandboxer", sandboxer) | ||
.await | ||
.unwrap(); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn init_qemu_sandboxer() -> Result<KuasarSandboxer<QemuVMFactory, QemuHooks>> { | ||
// For compatibility with kata config | ||
let config_path = env::var("KATA_CONFIG_PATH") | ||
.unwrap_or_else(|_| "/usr/share/defaults/kata-containers/configuration.toml".to_string()); | ||
|
||
let path = Path::new(&config_path); | ||
if path.exists() { | ||
KataConfig::init(path).await?; | ||
} | ||
|
||
let vmm_config = KataConfig::hypervisor_config("qemu", |h| h.clone()).await?; | ||
let vmm_config = vmm_config.to_qemu_config()?; | ||
let sandbox_config = KataConfig::sandbox_config("qemu").await?; | ||
let hooks = QemuHooks::new(vmm_config.clone()); | ||
let mut s = KuasarSandboxer::new(sandbox_config, vmm_config, hooks); | ||
|
||
// Check for "--dir" argument and recover from persisted directory | ||
let os_args: Vec<_> = env::args_os().collect(); | ||
for i in 0..os_args.len() { | ||
if os_args[i].to_str().unwrap() == "--dir" { | ||
let persist_dir_path = os_args[i + 1].to_str().unwrap().to_string(); | ||
if Path::new(&persist_dir_path).exists() { | ||
s.recover(&persist_dir_path).await?; | ||
} | ||
} | ||
} | ||
|
||
Ok(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2022 The Kuasar Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use std::str::FromStr; | ||
|
||
use anyhow::Result; | ||
use env_logger::Builder; | ||
use vmm_sandboxer::{ | ||
load_config, | ||
sandbox::KuasarSandboxer, | ||
stratovirt::{ | ||
config::StratoVirtVMConfig, factory::StratoVirtVMFactory, hooks::StratoVirtHooks, | ||
}, | ||
CONFIG_STRATOVIRT_PATH, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
// Initialize logging | ||
let mut builder = Builder::from_default_env(); | ||
builder.format_timestamp_micros(); | ||
|
||
// Initialize sandboxer | ||
let sandboxer = init_stratovirt_sandboxer().await?; | ||
|
||
// If 'log_level' field isn't set in the config file, keep the log level from the default env | ||
// Otherwise, set the log level configured in the config file | ||
if !sandboxer.log_level().is_empty() { | ||
let log_level = log::LevelFilter::from_str(sandboxer.log_level())?; | ||
builder.filter_level(log_level); | ||
} | ||
builder.init(); | ||
|
||
// Run the sandboxer | ||
containerd_sandbox::run("kuasar-sandboxer", sandboxer) | ||
.await | ||
.unwrap(); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn init_stratovirt_sandboxer() -> Result<KuasarSandboxer<StratoVirtVMFactory, StratoVirtHooks>> | ||
{ | ||
let (config, persist_dir_path) = | ||
load_config::<StratoVirtVMConfig>(CONFIG_STRATOVIRT_PATH).await?; | ||
let hooks = StratoVirtHooks::new(config.hypervisor.clone()); | ||
let mut s = KuasarSandboxer::new(config.sandbox, config.hypervisor, hooks); | ||
if !persist_dir_path.is_empty() { | ||
s.recover(&persist_dir_path).await?; | ||
} | ||
Ok(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.