mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-31 07:19:06 +00:00
Merge pull request #8986 from pmores/drop-shim-v2-address-value-validation
runtime-rs: fix interoperability issues between runtime-rs and cri-o
This commit is contained in:
commit
6ead48ec06
@ -38,12 +38,14 @@ pub(crate) trait Forwarder {
|
||||
/// `TTRPC_ADDRESS` existing. Otherwise, fall back to `LogForwarder`.
|
||||
pub(crate) async fn new_event_publisher(namespace: &str) -> Result<Box<dyn Forwarder>> {
|
||||
let fwd: Box<dyn Forwarder> = match env::var(TTRPC_ADDRESS_ENV) {
|
||||
Ok(address) => Box::new(
|
||||
Ok(address) if !address.is_empty() => Box::new(
|
||||
ContainerdForwarder::new(namespace, &address)
|
||||
.await
|
||||
.context("new containerd forwarder")?,
|
||||
),
|
||||
Err(_) => Box::new(
|
||||
// an empty address doesn't match the arm above so catch it here
|
||||
// and handle it the same way as if it's missing altogether
|
||||
Ok(_) | Err(_) => Box::new(
|
||||
LogForwarder::new(namespace)
|
||||
.await
|
||||
.context("new log forwarder")?,
|
||||
|
@ -4,7 +4,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
use std::{os::unix::fs::FileTypeExt, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use kata_sys_util::validate;
|
||||
@ -38,11 +38,7 @@ impl Args {
|
||||
/// The id, namespace, address and publish_binary are mandatory for START, RUN and DELETE.
|
||||
/// And bundle is mandatory for DELETE.
|
||||
pub fn validate(&mut self, should_check_bundle: bool) -> Result<()> {
|
||||
if self.id.is_empty()
|
||||
|| self.namespace.is_empty()
|
||||
|| self.address.is_empty()
|
||||
|| self.publish_binary.is_empty()
|
||||
{
|
||||
if self.id.is_empty() || self.namespace.is_empty() || self.publish_binary.is_empty() {
|
||||
return Err(anyhow!(Error::ArgumentIsEmpty(format!(
|
||||
"id: {} namespace: {} address: {} publish_binary: {}",
|
||||
&self.id, &self.namespace, &self.address, &self.publish_binary
|
||||
@ -52,21 +48,6 @@ impl Args {
|
||||
validate::verify_id(&self.id).context("verify container id")?;
|
||||
validate::verify_id(&self.namespace).context("verify namespace")?;
|
||||
|
||||
// Ensure `address` is a valid path.
|
||||
let path = PathBuf::from(self.address.clone())
|
||||
.canonicalize()
|
||||
.context(Error::InvalidPath(self.address.clone()))?;
|
||||
let md = path
|
||||
.metadata()
|
||||
.context(Error::FileGetMetadata(format!("{:?}", path)))?;
|
||||
if !md.file_type().is_socket() {
|
||||
return Err(Error::InvalidArgument).context("address is not socket");
|
||||
}
|
||||
self.address = path
|
||||
.to_str()
|
||||
.map(|v| v.to_owned())
|
||||
.ok_or(Error::InvalidArgument)?;
|
||||
|
||||
// Ensure `bundle` is a valid path.
|
||||
if should_check_bundle {
|
||||
if self.bundle.is_empty() {
|
||||
@ -182,10 +163,7 @@ mod tests {
|
||||
arg.clone()
|
||||
},
|
||||
should_check_bundle: false,
|
||||
result: Err(anyhow!(Error::ArgumentIsEmpty(format!(
|
||||
"id: {} namespace: {} address: {} publish_binary: {}",
|
||||
&arg.id, &arg.namespace, &arg.address, &arg.publish_binary
|
||||
)))),
|
||||
result: Ok(()),
|
||||
},
|
||||
TestData {
|
||||
arg: {
|
||||
@ -276,22 +254,6 @@ mod tests {
|
||||
should_check_bundle: true,
|
||||
result: Ok(()),
|
||||
},
|
||||
TestData {
|
||||
arg: {
|
||||
arg.address = default_address.clone() + "/..";
|
||||
arg.clone()
|
||||
},
|
||||
should_check_bundle: true,
|
||||
result: Err(anyhow!(Error::InvalidPath(arg.address.clone()))),
|
||||
},
|
||||
TestData {
|
||||
arg: {
|
||||
arg.address = default_address.clone() + "/..";
|
||||
arg.clone()
|
||||
},
|
||||
should_check_bundle: true,
|
||||
result: Err(anyhow!(Error::InvalidPath(arg.address.clone()))),
|
||||
},
|
||||
TestData {
|
||||
arg: {
|
||||
arg.address = default_address;
|
||||
|
@ -61,7 +61,6 @@ impl ShimExecutor {
|
||||
fn new_command(&self) -> Result<std::process::Command> {
|
||||
if self.args.id.is_empty()
|
||||
|| self.args.namespace.is_empty()
|
||||
|| self.args.address.is_empty()
|
||||
|| self.args.publish_binary.is_empty()
|
||||
{
|
||||
return Err(anyhow!("invalid param"));
|
||||
|
Loading…
Reference in New Issue
Block a user