Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions crates/trident/src/osimage/cosi/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::collections::{HashMap, HashSet};

use log::warn;

use osutils::osrelease::AZURE_CONTAINER_LINUX_VARIANT_ID;

use super::{
error::{CosiMetadataError, CosiMetadataErrorKind},
metadata::{
Expand Down Expand Up @@ -82,22 +84,30 @@ impl CosiMetadata {
}

// Ensure osPackages are present and all required info is provided.
let Some(os_packages) = &self.os_packages else {
return mk_err(CosiMetadataErrorKind::V1_1OsPackagesRequired);
};
match &self.os_packages {
Some(packages) => {
// Ensure both release and arch are provided.
for os_package in packages {
if os_package.release.is_none() {
return mk_err(CosiMetadataErrorKind::V1_1OsPackageMissingRelease(
os_package.name.clone(),
));
}

// Ensure both release and arch are provided.
for os_package in os_packages {
if os_package.release.is_none() {
return mk_err(CosiMetadataErrorKind::V1_1OsPackageMissingRelease(
os_package.name.clone(),
));
if os_package.arch.is_none() {
return mk_err(CosiMetadataErrorKind::V1_1OsPackageMissingArch(
os_package.name.clone(),
));
}
}
}

if os_package.arch.is_none() {
return mk_err(CosiMetadataErrorKind::V1_1OsPackageMissingArch(
os_package.name.clone(),
));
None => {
if self.os_release.variant_id.as_deref()
!= Some(AZURE_CONTAINER_LINUX_VARIANT_ID)
{
// osPackages are required unless this is an Azure Container Linux image
return mk_err(CosiMetadataErrorKind::V1_1OsPackagesRequired);
}
Comment thread
bfjelds marked this conversation as resolved.
}
Comment thread
bfjelds marked this conversation as resolved.
}
}
Expand Down Expand Up @@ -426,6 +436,15 @@ mod tests {
CosiMetadataErrorKind::V1_1OsPackagesRequired,
);

// Azure Container Linux images may omit osPackages.
let mut acl_no_os_packages = base.clone();
acl_no_os_packages["osRelease"] =
json!("ID=azurelinux\nVERSION_ID=3.0\nVARIANT_ID=azurecontainerlinux\n");
if let Some(obj) = acl_no_os_packages.as_object_mut() {
obj.remove("osPackages");
}
parse_and_validate(acl_no_os_packages).unwrap();

// v1.1 requires per-package release.
let mut missing_release = base.clone();
missing_release["osPackages"][0]
Expand Down
Loading