Skip to content

Commit

Permalink
Deny unknown fields in selinux manifest configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Obenhuber committed Oct 19, 2023
1 parent ee02529 commit db3a63a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions northstar-runtime/src/npk/manifest/selinux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::common::non_nul_string::NonNulString;

/// SELinux configuration
#[derive(Clone, Eq, PartialEq, Debug, Validate, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Selinux {
/// Default SE label (mount option context=...).
#[validate(custom = "validate_context")]
Expand Down Expand Up @@ -59,3 +60,15 @@ fn validate_context_with_space() {
fn validate_invalid_empty_context() {
assert!(validate_context("").is_err());
}

#[test]
fn deserialize_unknown_field() {
serde_json::from_str::<Selinux>(
"{
\"mount_context\": \"system_u:object_r:container_file_t:s0\",
\"exec\": \"system_u:object_r:container_file_t:s0\",
\"unknown\": \"system_u:object_r:container_file_t:s0\"
}",
)
.expect_err("unknown field should not be deserialized");
}

0 comments on commit db3a63a

Please sign in to comment.