Skip to main content

UserNamespaceConfig

Struct UserNamespaceConfig 

Source
pub struct UserNamespaceConfig {
    pub uid_mappings: Vec<IdMapping>,
    pub gid_mappings: Vec<IdMapping>,
}
Expand description

User namespace configuration

Fields§

§uid_mappings: Vec<IdMapping>

UID mappings

§gid_mappings: Vec<IdMapping>

GID mappings

Implementations§

Source§

impl UserNamespaceConfig

Source

pub fn rootless() -> Self

Create config for rootless mode

Maps container root (UID/GID 0) to current user. This is the historic Nucleus rootless mapping (“nomap”): only container uid 0 is usable, so workloads that refuse euid 0 (e.g. PostgreSQL) cannot run. Prefer UserNamespaceConfig::keep_id or UserNamespaceConfig::subuid_auto when /etc/subuid is configured.

Source

pub fn keep_id() -> Result<Self>

Rootless “keep-id” mapping (Podman --userns=keep-id).

Maps the calling user’s own uid/gid to itself inside the namespace, and maps container root (0) to the start of the delegated subuid/subgid range. Because the workload keeps the host uid, bind-mounted host files owned by the user are directly accessible with no ownership shifting — this is the recommended rootless mode for workloads like PostgreSQL that (a) refuse euid 0 and (b) read user-owned bind mounts.

Requires /etc/subuid and /etc/subgid for the calling user.

Source

pub fn subuid_auto() -> Result<Self>

Rootless “auto” mapping (Podman/Docker rootless default).

Maps container root (0) to the calling user, and container 1..N to the delegated subuid/subgid range. Workloads therefore run as their image / configured uid (e.g. 999 for the Postgres image) mapped into the subuid range. Unlike Self::keep_id, bind-mounted host files owned by the user are not automatically accessible to a non-zero workload uid — the caller must align ownership (as with Docker/Podman rootless bind mounts).

Source

pub fn from_map_specs( uid_specs: &[String], gid_specs: &[String], ) -> Result<Self>

Build a mapping from explicit container:host:size triplets (Podman --uidmap / Docker --userns-uid-map syntax).

Source

pub fn for_unprivileged_rootless(workload_uid: Option<u32>) -> Self

Choose a rootless mapping for the current (unprivileged) process.

When the workload requests a non-zero uid (--user N), the historic rootless() mapping (only container 0) would make that uid unmappable. If /etc/subuid is configured, transparently pick keep_id so the requested uid maps to the caller’s own uid; otherwise fall back to the trivial rootless() mapping (the caller will get a clear validation error pointing at /etc/subuid).

Source

pub fn needs_setuid_helper(&self) -> bool

Whether the configured mapping can be written to /proc/<pid>/{u,g}id_map by an unprivileged process directly. The kernel only permits this for the trivial single 0 <own> 1 mapping; anything else requires the setuid newuidmap/newgidmap helpers (which authorize via /etc/subuid).

Source

pub fn root_remapped() -> Self

Create config for root-remapped mode

When running as host root, maps container UID 0 to a high unprivileged UID range so a container escape does not yield real host root.

Source

pub fn custom( uid_mappings: Vec<IdMapping>, gid_mappings: Vec<IdMapping>, ) -> Result<Self>

Create config with custom mappings (validated)

Trait Implementations§

Source§

impl Clone for UserNamespaceConfig

Source§

fn clone(&self) -> UserNamespaceConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UserNamespaceConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more