Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrArchiveTooLarge is returned when extracted content exceeds the size limit ErrArchiveTooLarge = errors.New("archive content exceeds size limit") // ErrInvalidArchivePath is returned when a tar entry has a malicious path ErrInvalidArchivePath = errors.New("invalid archive path") )
Functions ¶
func ExtractTarGz ¶
ExtractTarGz extracts a tar.gz archive to destDir, aborting if the extracted content exceeds maxBytes. Returns the total extracted bytes on success.
Security considerations (runs with elevated privileges): This function implements multiple layers of defense against malicious archives: 1. Path validation - rejects absolute paths and path traversal attempts upfront 2. securejoin - safe path joining that resolves symlinks within the root 3. O_NOFOLLOW - prevents following symlinks when creating files (defense in depth) 4. Size limiting - tracks cumulative size and aborts if limit exceeded 5. io.LimitReader - secondary protection when copying file contents
The destination directory should be a freshly created temp directory to minimize TOCTOU attack surface. The same approach is used by umoci and containerd.
Types ¶
type AttachVolumeRequest ¶
AttachVolumeRequest is the domain request for attaching a volume to an instance
type Attachment ¶
Attachment represents a volume attached to an instance
type CreateVolumeFromArchiveRequest ¶
type CreateVolumeFromArchiveRequest struct {
Name string
SizeGb int // Maximum size in GB (extraction fails if content exceeds this)
Id *string // Optional custom ID
}
CreateVolumeFromArchiveRequest is the domain request for creating a volume pre-populated with content from a tar.gz archive
type CreateVolumeRequest ¶
CreateVolumeRequest is the domain request for creating a volume
type Manager ¶
type Manager interface {
ListVolumes(ctx context.Context) ([]Volume, error)
CreateVolume(ctx context.Context, req CreateVolumeRequest) (*Volume, error)
CreateVolumeFromArchive(ctx context.Context, req CreateVolumeFromArchiveRequest, archive io.Reader) (*Volume, error)
GetVolume(ctx context.Context, id string) (*Volume, error)
GetVolumeByName(ctx context.Context, name string) (*Volume, error)
DeleteVolume(ctx context.Context, id string) error
// Attachment operations (called by instance manager)
// Multi-attach rules:
// - If no attachments: allow any mode (rw or ro)
// - If existing attachment is rw: reject all new attachments
// - If existing attachments are ro: only allow new ro attachments
AttachVolume(ctx context.Context, id string, req AttachVolumeRequest) error
DetachVolume(ctx context.Context, volumeID string, instanceID string) error
// GetVolumePath returns the path to the volume data file
GetVolumePath(id string) string
// TotalVolumeBytes returns the total size of all volumes.
// Used by the resource manager for disk capacity tracking.
TotalVolumeBytes(ctx context.Context) (int64, error)
}
Manager provides volume lifecycle operations