From 61da050fe80b1b0af40638941d67c539ff0bcfc0 Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Mon, 25 Jul 2022 12:20:24 -0600 Subject: [PATCH] only validate mounts for inject if eos `>=0.3.1.1` (#1686) only validate mounts for inject if `>=0.3.1.1` --- backend/src/action.rs | 9 ++++++-- backend/src/backup/mod.rs | 11 +++++++--- backend/src/config/action.rs | 11 +++++++--- backend/src/context/rpc.rs | 2 +- backend/src/init.rs | 1 - backend/src/migration.rs | 35 +++++++++++++++++++----------- backend/src/procedure/docker.rs | 6 ++++- backend/src/procedure/mod.rs | 5 ++++- backend/src/s9pk/reader.rs | 17 +++++++++------ backend/src/status/health_check.rs | 13 +++++++---- 10 files changed, 74 insertions(+), 36 deletions(-) diff --git a/backend/src/action.rs b/backend/src/action.rs index e554efd92..aca0ffc03 100644 --- a/backend/src/action.rs +++ b/backend/src/action.rs @@ -57,9 +57,14 @@ pub struct Action { } impl Action { #[instrument] - pub fn validate(&self, volumes: &Volumes, image_ids: &BTreeSet) -> Result<(), Error> { + pub fn validate( + &self, + eos_version: &Version, + volumes: &Volumes, + image_ids: &BTreeSet, + ) -> Result<(), Error> { self.implementation - .validate(volumes, image_ids, true) + .validate(eos_version, volumes, image_ids, true) .with_ctx(|_| { ( crate::ErrorKind::ValidateS9pk, diff --git a/backend/src/backup/mod.rs b/backend/src/backup/mod.rs index 2d6174999..b8f055596 100644 --- a/backend/src/backup/mod.rs +++ b/backend/src/backup/mod.rs @@ -69,12 +69,17 @@ pub struct BackupActions { pub restore: PackageProcedure, } impl BackupActions { - pub fn validate(&self, volumes: &Volumes, image_ids: &BTreeSet) -> Result<(), Error> { + pub fn validate( + &self, + eos_version: &Version, + volumes: &Volumes, + image_ids: &BTreeSet, + ) -> Result<(), Error> { self.create - .validate(volumes, image_ids, false) + .validate(eos_version, volumes, image_ids, false) .with_ctx(|_| (crate::ErrorKind::ValidateS9pk, "Backup Create"))?; self.restore - .validate(volumes, image_ids, false) + .validate(eos_version, volumes, image_ids, false) .with_ctx(|_| (crate::ErrorKind::ValidateS9pk, "Backup Restore"))?; Ok(()) } diff --git a/backend/src/config/action.rs b/backend/src/config/action.rs index 435710fba..c7db786e0 100644 --- a/backend/src/config/action.rs +++ b/backend/src/config/action.rs @@ -31,12 +31,17 @@ pub struct ConfigActions { } impl ConfigActions { #[instrument] - pub fn validate(&self, volumes: &Volumes, image_ids: &BTreeSet) -> Result<(), Error> { + pub fn validate( + &self, + eos_version: &Version, + volumes: &Volumes, + image_ids: &BTreeSet, + ) -> Result<(), Error> { self.get - .validate(volumes, image_ids, true) + .validate(eos_version, volumes, image_ids, true) .with_ctx(|_| (crate::ErrorKind::ValidateS9pk, "Config Get"))?; self.set - .validate(volumes, image_ids, true) + .validate(eos_version, volumes, image_ids, true) .with_ctx(|_| (crate::ErrorKind::ValidateS9pk, "Config Set"))?; Ok(()) } diff --git a/backend/src/context/rpc.rs b/backend/src/context/rpc.rs index aaf7cbd01..72a7f4966 100644 --- a/backend/src/context/rpc.rs +++ b/backend/src/context/rpc.rs @@ -36,7 +36,7 @@ use crate::shutdown::Shutdown; use crate::status::{MainStatus, Status}; use crate::util::io::from_yaml_async_reader; use crate::util::{AsyncFileExt, Invoke}; -use crate::{volume, Error, ErrorKind, ResultExt}; +use crate::{Error, ErrorKind, ResultExt}; #[derive(Debug, Default, Deserialize)] #[serde(rename_all = "kebab-case")] diff --git a/backend/src/init.rs b/backend/src/init.rs index 6acc7e43e..5c61311d3 100644 --- a/backend/src/init.rs +++ b/backend/src/init.rs @@ -6,7 +6,6 @@ use tokio::process::Command; use crate::context::rpc::RpcContextConfig; use crate::db::model::ServerStatus; use crate::install::PKG_DOCKER_DIR; -use crate::sound::SHUTDOWN; use crate::util::Invoke; use crate::Error; diff --git a/backend/src/migration.rs b/backend/src/migration.rs index 027ed574d..6abd8cd18 100644 --- a/backend/src/migration.rs +++ b/backend/src/migration.rs @@ -25,22 +25,31 @@ pub struct Migrations { } impl Migrations { #[instrument] - pub fn validate(&self, volumes: &Volumes, image_ids: &BTreeSet) -> Result<(), Error> { + pub fn validate( + &self, + eos_version: &Version, + volumes: &Volumes, + image_ids: &BTreeSet, + ) -> Result<(), Error> { for (version, migration) in &self.from { - migration.validate(volumes, image_ids, true).with_ctx(|_| { - ( - crate::ErrorKind::ValidateS9pk, - format!("Migration from {}", version), - ) - })?; + migration + .validate(eos_version, volumes, image_ids, true) + .with_ctx(|_| { + ( + crate::ErrorKind::ValidateS9pk, + format!("Migration from {}", version), + ) + })?; } for (version, migration) in &self.to { - migration.validate(volumes, image_ids, true).with_ctx(|_| { - ( - crate::ErrorKind::ValidateS9pk, - format!("Migration to {}", version), - ) - })?; + migration + .validate(eos_version, volumes, image_ids, true) + .with_ctx(|_| { + ( + crate::ErrorKind::ValidateS9pk, + format!("Migration to {}", version), + ) + })?; } Ok(()) } diff --git a/backend/src/procedure/docker.rs b/backend/src/procedure/docker.rs index 6e77f196c..751b01def 100644 --- a/backend/src/procedure/docker.rs +++ b/backend/src/procedure/docker.rs @@ -64,6 +64,7 @@ pub struct DockerProcedure { impl DockerProcedure { pub fn validate( &self, + eos_version: &Version, volumes: &Volumes, image_ids: &BTreeSet, expected_io: bool, @@ -85,7 +86,10 @@ impl DockerProcedure { if expected_io && self.io_format.is_none() { color_eyre::eyre::bail!("expected io-format"); } - if self.inject && !self.mounts.is_empty() { + if &**eos_version >= &emver::Version::new(0, 3, 1, 1) + && self.inject + && !self.mounts.is_empty() + { color_eyre::eyre::bail!("mounts not allowed in inject actions"); } Ok(()) diff --git a/backend/src/procedure/mod.rs b/backend/src/procedure/mod.rs index f36cefbb3..279fbd910 100644 --- a/backend/src/procedure/mod.rs +++ b/backend/src/procedure/mod.rs @@ -40,12 +40,15 @@ impl PackageProcedure { #[instrument] pub fn validate( &self, + eos_version: &Version, volumes: &Volumes, image_ids: &BTreeSet, expected_io: bool, ) -> Result<(), color_eyre::eyre::Report> { match self { - PackageProcedure::Docker(action) => action.validate(volumes, image_ids, expected_io), + PackageProcedure::Docker(action) => { + action.validate(eos_version, volumes, image_ids, expected_io) + } #[cfg(feature = "js_engine")] PackageProcedure::Script(action) => action.validate(volumes), diff --git a/backend/src/s9pk/reader.rs b/backend/src/s9pk/reader.rs index d8b04f1ab..d69e7b20b 100644 --- a/backend/src/s9pk/reader.rs +++ b/backend/src/s9pk/reader.rs @@ -153,23 +153,26 @@ impl S9pkReader { man.actions .0 .iter() - .map(|(_, action)| action.validate(&man.volumes, &validated_image_ids)) + .map(|(_, action)| { + action.validate(&man.eos_version, &man.volumes, &validated_image_ids) + }) .collect::>()?; - man.backup.validate(&man.volumes, &validated_image_ids)?; + man.backup + .validate(&man.eos_version, &man.volumes, &validated_image_ids)?; if let Some(cfg) = &man.config { - cfg.validate(&man.volumes, &validated_image_ids)?; + cfg.validate(&man.eos_version, &man.volumes, &validated_image_ids)?; } man.health_checks - .validate(&man.volumes, &validated_image_ids)?; + .validate(&man.eos_version, &man.volumes, &validated_image_ids)?; man.interfaces.validate()?; man.main - .validate(&man.volumes, &validated_image_ids, false) + .validate(&man.eos_version, &man.volumes, &validated_image_ids, false) .with_ctx(|_| (crate::ErrorKind::ValidateS9pk, "Main"))?; man.migrations - .validate(&man.volumes, &validated_image_ids)?; + .validate(&man.eos_version, &man.volumes, &validated_image_ids)?; if let Some(props) = &man.properties { props - .validate(&man.volumes, &validated_image_ids, true) + .validate(&man.eos_version, &man.volumes, &validated_image_ids, true) .with_ctx(|_| (crate::ErrorKind::ValidateS9pk, "Properties"))?; } man.volumes.validate(&man.interfaces)?; diff --git a/backend/src/status/health_check.rs b/backend/src/status/health_check.rs index 526e03cef..2705ff4ba 100644 --- a/backend/src/status/health_check.rs +++ b/backend/src/status/health_check.rs @@ -1,11 +1,11 @@ use std::collections::{BTreeMap, BTreeSet}; use chrono::{DateTime, Utc}; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use tracing::instrument; use crate::context::RpcContext; -use crate::id::{ ImageId}; +use crate::id::ImageId; use crate::procedure::{NoOutput, PackageProcedure, ProcedureName}; use crate::s9pk::manifest::PackageId; use crate::util::serde::Duration; @@ -19,11 +19,16 @@ pub use models::HealthCheckId; pub struct HealthChecks(pub BTreeMap); impl HealthChecks { #[instrument] - pub fn validate(&self, volumes: &Volumes, image_ids: &BTreeSet) -> Result<(), Error> { + pub fn validate( + &self, + eos_version: &Version, + volumes: &Volumes, + image_ids: &BTreeSet, + ) -> Result<(), Error> { for (_, check) in &self.0 { check .implementation - .validate(&volumes, image_ids, false) + .validate(eos_version, &volumes, image_ids, false) .with_ctx(|_| { ( crate::ErrorKind::ValidateS9pk,