namespaces

package
v0.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePersistentNamespace

func CreatePersistentNamespace(targetPath string, pid int, nsType Type) error

CreatePersistentNamespace creates a persistent bind-mount of a namespace.

func DefaultRootlessMaps

func DefaultRootlessMaps() ([]IDMap, []IDMap)

DefaultRootlessMaps returns default UID/GID mappings for rootless mode.

func GetCurrentNamespace

func GetCurrentNamespace(nsType Type) (string, error)

GetCurrentNamespace gets the current namespace inode for a given type.

func IsRootless

func IsRootless() bool

IsRootless checks if the current process is running as non-root.

func JoinNamespace

func JoinNamespace(nsType Type, path string) error

JoinNamespace joins an existing namespace.

func NamespacePath

func NamespacePath(pid int, nsType Type) string

NamespacePath returns the path to a namespace file for a given PID.

func ParseCapability

func ParseCapability(cap string) string

ParseCapability validates and normalizes a Linux capability name.

func SetDomainname

func SetDomainname(domainname string) error

SetDomainname sets the domainname for a UTS namespace.

func SetHostname

func SetHostname(hostname string) error

SetHostname sets the hostname for a UTS namespace.

func Supported

func Supported(nsType Type) bool

Supported checks if a namespace type is supported on this kernel.

Types

type Config

type Config struct {
	User   bool
	Mount  bool
	PID    bool
	Net    bool
	UTS    bool
	IPC    bool
	Cgroup bool

	// User namespace configuration.
	UIDMappings []IDMap
	GIDMappings []IDMap

	// UTS configuration.
	Hostname   string
	Domainname string

	// Rootless mode.
	Rootless bool
}

Config holds the configuration for creating namespaces.

type IDMap

type IDMap struct {
	ContainerID uint32
	HostID      uint32
	Size        uint32
}

IDMap represents a UID/GID mapping.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages Linux namespaces for containers.

func NewManager

func NewManager(root string) *Manager

NewManager creates a new namespace manager.

func (*Manager) CreateNamespaces

func (m *Manager) CreateNamespaces(containerID string, cfg *Config) (*NamespacePaths, error)

CreateNamespaces creates namespaces for a container.

func (*Manager) DeletePersistentNamespace

func (m *Manager) DeletePersistentNamespace(containerID string) error

DeletePersistentNamespace removes a persistent namespace.

func (*Manager) GetPIDForContainer

func (m *Manager) GetPIDForContainer(containerID string) (int, error)

GetPIDForContainer retrieves the init PID for a container.

func (*Manager) SetupUserNamespace

func (m *Manager) SetupUserNamespace(pid int, cfg *Config) error

SetupUserNamespace sets up the user namespace with UID/GID mappings.

func (*Manager) TargetPath

func (m *Manager) TargetPath(containerID string, nsType Type) string

TargetPath builds a path in the namespace directory.

type NamespacePaths

type NamespacePaths struct {
	User   string
	Mount  string
	PID    string
	Net    string
	UTS    string
	IPC    string
	Cgroup string
}

NamespacePaths holds paths to namespace files.

type Type

type Type string

Type represents a Linux namespace type.

const (
	UserNS   Type = "user"
	MountNS  Type = "mount"
	PIDNS    Type = "pid"
	NetNS    Type = "net"
	UTSNS    Type = "uts"
	IPCNS    Type = "ipc"
	CgroupNS Type = "cgroup"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL