safechroot

package
v0.0.0-...-4cb4cf9 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const BindMountPointFlags = unix.MS_BIND | unix.MS_MGC_VAL

BindMountPointFlags is a set of flags to do a bind mount.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chroot

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

Chroot represents a Chroot environment with automatic synchronization protections and guaranteed cleanup code even on SIGTERM so long as registerSIGTERMCleanup is invoked.

func NewChroot

func NewChroot(rootDir string, isExistingDir bool) *Chroot

NewChroot creates a new Chroot struct

func (*Chroot) AddFiles

func (c *Chroot) AddFiles(filesToCopy ...FileToCopy) (err error)

AddFiles copies each file 'Src' to the relative path chrootRootDir/'Dest' in the chroot.

func (*Chroot) Close

func (c *Chroot) Close(leaveOnDisk bool) (err error)

Close will unmount the chroot and cleanup its files. This call will block until the chroot cleanup runs. Only one Chroot will close at a given time.

func (*Chroot) CopyOutFile

func (c *Chroot) CopyOutFile(srcPath string, destPath string) (err error)

CopyOutFile copies file 'srcPath' in the chroot to the host at 'destPath'

func (*Chroot) Initialize

func (c *Chroot) Initialize(tarPath string, extraDirectories []string, extraMountPoints []*MountPoint,
	includeDefaultMounts bool,
) (err error)

Initialize initializes a Chroot, creating directories and mount points.

  • tarPath is an optional path to a tar file that will be extracted at the root of the chroot.
  • extraDirectories is an optional slice of additional directories that should be created before attempting to mount inside the chroot.
  • extraMountPoints is an optional slice of additional mount points that should be created inside the chroot, they will automatically be unmounted on a Chroot Close.

This call will block until the chroot initializes successfully. Only one Chroot will initialize at a given time.

func (*Chroot) MoveOutFile

func (c *Chroot) MoveOutFile(srcPath string, destPath string) (err error)

MoveOutFile moves file 'srcPath' in the chroot to the host at 'destPath', deleting the 'srcPath' file.

func (*Chroot) RootDir

func (c *Chroot) RootDir() string

RootDir returns the Chroot's root directory.

func (*Chroot) Run

func (c *Chroot) Run(toRun func() error) (err error)

Run runs a given function inside the Chroot. This function will synchronize with all other Chroots to ensure only one Chroot command is executed at a given time.

func (*Chroot) UnsafeRun

func (c *Chroot) UnsafeRun(toRun func() error) (err error)

UnsafeRun runs a given function inside the Chroot. This function will not synchronize with other Chroots. The invoker is responsible for ensuring safety.

type ChrootInterface

type ChrootInterface interface {
	RootDir() string
	Run(toRun func() error) error
	UnsafeRun(toRun func() error) error
	AddFiles(filesToCopy ...FileToCopy) error
}

type DummyChroot

type DummyChroot struct {
}

DummyChroot is a placeholder that implements ChrootInterface.

func (*DummyChroot) AddFiles

func (d *DummyChroot) AddFiles(filesToCopy ...FileToCopy) (err error)

func (*DummyChroot) RootDir

func (d *DummyChroot) RootDir() string

func (*DummyChroot) Run

func (d *DummyChroot) Run(toRun func() error) (err error)

func (*DummyChroot) UnsafeRun

func (d *DummyChroot) UnsafeRun(toRun func() error) (err error)

type FileToCopy

type FileToCopy struct {
	Src         string
	Dest        string
	Permissions *os.FileMode
}

FileToCopy represents a file to copy into a chroot using AddFiles. Dest is relative to the chroot directory.

type MountPoint

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

MountPoint represents a system mount point used by a Chroot. It is guaranteed to be unmounted on application exit even on a SIGTERM so long as registerSIGTERMCleanup is invoked. The fields of MountPoint mirror those of the `mount` syscall.

func NewMountPoint

func NewMountPoint(source, target, fstype string, flags uintptr, data string) (mountPoint *MountPoint)

NewMountPoint creates a new MountPoint struct to be created by a Chroot

func NewOverlayMountPoint

func NewOverlayMountPoint(chrootDir, source, target, lowerDir, upperDir, workDir string) (mountPoint *MountPoint, extaDirsNeeds []string)

NewOverlayMountPoint creates a new MountPoint struct and extra directories slice configured for a given overlay

func NewPreDefaultsMountPoint

func NewPreDefaultsMountPoint(source, target, fstype string, flags uintptr, data string) (mountPoint *MountPoint)

NewPreDefaultsMountPoint creates a new MountPoint struct to be created by a Chroot but before the default mount points.

Jump to

Keyboard shortcuts

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