#[derive(Debug, Clone, Copy)]
#[allow(clippy::struct_excessive_bools)]
pub struct OsCapabilities {
pub user_namespaces: bool,
pub pid_namespace: bool,
pub mount_namespace: bool,
pub network_namespace: bool,
pub memfd_secret: bool,
pub seccomp_notify: bool,
pub ptrace_restricted: bool,
}
impl OsCapabilities {
#[must_use]
pub fn detect() -> Self {
#[cfg(target_os = "linux")]
{
Self {
user_namespaces: super::user_namespaces_available(),
pid_namespace: true,
mount_namespace: true,
network_namespace: true,
memfd_secret: std::path::Path::new("/sys/kernel/security").exists(),
seccomp_notify: std::path::Path::new("/proc/sys/kernel/seccomp").exists(),
ptrace_restricted: std::fs::read_to_string("/proc/sys/kernel/yama/ptrace_scope")
.is_ok_and(|v| v.trim() != "0"),
}
}
#[cfg(not(target_os = "linux"))]
{
Self {
user_namespaces: false,
pid_namespace: false,
mount_namespace: false,
network_namespace: false,
memfd_secret: false,
seccomp_notify: false,
ptrace_restricted: false,
}
}
}
}