Skip to content
Merged
Changes from 2 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
31 changes: 31 additions & 0 deletions src/runtime/miscellaneous.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::error::OciSpecError;
use crate::runtime::LinuxIdMapping;
use derive_builder::Builder;
use getset::{CopyGetters, Getters, MutGetters, Setters};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -76,6 +77,22 @@ pub struct Mount {
#[serde(default, skip_serializing_if = "Option::is_none")]
/// Options are fstab style mount options.
options: Option<Vec<String>>,

#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "uidMappings"
)]
/// UID mappings used for changing file owners w/o calling chown, fs should support it. Every mount point could have its own mapping.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about being a bit more verbose here:

Suggested change
/// UID mappings used for changing file owners w/o calling chown, fs should support it. Every mount point could have its own mapping.
/// UID mappings for ID-mapped mounts (Linux 5.12+).
///
/// Specifies how to map UIDs from the source filesystem to the destination mount point.
/// This allows changing file ownership without calling chown.
///
/// **Important**: If specified, gid_mappings MUST also be specified.
/// The mount options SHOULD include "idmap" or "ridmap".
///
/// See: https://github.com/opencontainers/runtime-spec/blob/main/config.md#posix-platform-mounts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saschagrunert
Sorry for the late response.
I've fixed your review comments.

uid_mappings: Option<Vec<LinuxIdMapping>>,

#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "gidMappings"
)]
/// GID mappings used for changing file owners w/o calling chown, fs should support it. Every mount point could have its own mapping.
gid_mappings: Option<Vec<LinuxIdMapping>>,
Comment on lines 80 to 111
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the OCI spec, uidMappings and gidMappings must be specified together. The current implementation allows setting one without the other.

I'd say we could add validation in the builder or as a separate validation method, like:

  • Add a custom build() validation in derive_builder
  • Add a validation method on Mount to check consistency
  • Document this requirement in the field comments

}

/// utility function to generate default config for mounts.
Expand All @@ -86,6 +103,8 @@ pub fn get_default_mounts() -> Vec<Mount> {
typ: "proc".to_string().into(),
source: PathBuf::from("proc").into(),
options: None,
uid_mappings: None,
gid_mappings: None,
},
Mount {
destination: PathBuf::from("/dev"),
Expand All @@ -98,6 +117,8 @@ pub fn get_default_mounts() -> Vec<Mount> {
"size=65536k".into(),
]
.into(),
uid_mappings: None,
gid_mappings: None,
},
Mount {
destination: PathBuf::from("/dev/pts"),
Expand All @@ -112,6 +133,8 @@ pub fn get_default_mounts() -> Vec<Mount> {
"gid=5".into(),
]
.into(),
uid_mappings: None,
gid_mappings: None,
},
Mount {
destination: PathBuf::from("/dev/shm"),
Expand All @@ -125,12 +148,16 @@ pub fn get_default_mounts() -> Vec<Mount> {
"size=65536k".into(),
]
.into(),
uid_mappings: None,
gid_mappings: None,
},
Mount {
destination: PathBuf::from("/dev/mqueue"),
typ: "mqueue".to_string().into(),
source: PathBuf::from("mqueue").into(),
options: vec!["nosuid".into(), "noexec".into(), "nodev".into()].into(),
uid_mappings: None,
gid_mappings: None,
},
Mount {
destination: PathBuf::from("/sys"),
Expand All @@ -143,6 +170,8 @@ pub fn get_default_mounts() -> Vec<Mount> {
"ro".into(),
]
.into(),
uid_mappings: None,
gid_mappings: None,
},
Mount {
destination: PathBuf::from("/sys/fs/cgroup"),
Expand All @@ -156,6 +185,8 @@ pub fn get_default_mounts() -> Vec<Mount> {
"ro".into(),
]
.into(),
uid_mappings: None,
gid_mappings: None,
},
]
}
Expand Down
Loading