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 33e1d0a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion examples/inspect/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ rlimits:
hard: 20000
suppl_groups: [src, inet]
selinux:
context: unconfined_u:object_r:user_home_t:s0
mount_context: unconfined_u:object_r:user_home_t:s0
exec: unconfined_u:object_r:inspect_t:s0
3 changes: 2 additions & 1 deletion examples/test-container/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ seccomp:
clone: any # Needed for socket tests.
clone3: any # Needed for socket tests.
selinux:
context: unconfined_u:object_r:user_home_t:s0
mount_context: unconfined_u:object_r:user_home_t:s0
exec: unconfined_u:object_r:test_container_t:s0
sockets:
datagram:
type: datagram
Expand Down
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 33e1d0a

Please sign in to comment.