path

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package path provides filesystem abstraction and security for DirIO.

This package wraps go-billy to provide: - Chroot-based filesystem isolation - Path traversal attack prevention - Scoped filesystem access for buckets and metadata

Design principles: - Filesystem-level security only (path traversal, null bytes, absolute paths) - NO S3 validation (that belongs in API handlers) - Generic and reusable for any filesystem access

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPath indicates a path failed security validation
	ErrInvalidPath = errors.New("invalid path: security violation")

	// ErrPathTraversal indicates an attempt to escape the filesystem boundary
	ErrPathTraversal = errors.New("path traversal detected")

	// ErrAbsolutePath indicates an absolute path was provided where relative is required
	ErrAbsolutePath = errors.New("absolute paths not allowed")

	// ErrNullByte indicates a null byte in the path
	ErrNullByte = errors.New("null byte in path")
)

Functions

func CleanPath

func CleanPath(path string) (string, error)

CleanPath sanitizes a path for safe filesystem access. Returns the cleaned path or an error if the path is unsafe.

This uses filepath.Clean to normalize the path, then validates it. Always returns forward slashes for consistency with S3 conventions.

func NewBucketFS

func NewBucketFS(rootFS billy.Filesystem, bucket string) (billy.Filesystem, error)

NewBucketFS creates a filesystem scoped to a specific bucket directory. This ensures bucket operations cannot access other buckets or system directories.

The bucket parameter should be the bucket name (already validated by API layer). This function only validates path safety, not S3 naming rules.

Creates the bucket directory if it doesn't exist.

func NewMetadataFS

func NewMetadataFS(rootFS billy.Filesystem) (billy.Filesystem, error)

NewMetadataFS creates a read/write filesystem scoped to the DirIO metadata directory. This is used for storing DirIO's own metadata (bucket info, policies, etc.)

Creates the metadata directory if it doesn't exist.

func NewMinIOFS

func NewMinIOFS(rootFS billy.Filesystem) (billy.Filesystem, error)

NewMinIOFS creates a read-only filesystem scoped to the MinIO metadata directory. This is used for importing existing MinIO data.

Returns an error if the MinIO directory doesn't exist.

func NewRootFS

func NewRootFS(dataDir string) (billy.Filesystem, error)

NewRootFS creates a chroot-protected filesystem at the specified data directory. This is the root filesystem for all DirIO operations.

The filesystem is isolated to dataDir using chroot, preventing any access outside this directory tree.

func NewUploadStagingFS

func NewUploadStagingFS(rootFS billy.Filesystem, bucket string) (billy.Filesystem, error)

NewUploadStagingFS creates a filesystem scoped to the upload staging area for a bucket. All in-progress write state (PutObject temp files, multipart parts) lives here, completely outside the bucket directory, so it can never appear in S3 listings.

Creates the staging directory if it doesn't exist.

func ValidatePathSafe

func ValidatePathSafe(path string) error

ValidatePathSafe checks if a path is safe from a filesystem security perspective. This function checks for: - Path traversal attempts (../) - Absolute paths - Null bytes - Empty paths

This does NOT validate S3 naming rules - that's the API layer's responsibility.

Types

type ReadOnlyFS

type ReadOnlyFS struct {
	billy.Filesystem
}

func (ReadOnlyFS) Create

func (r ReadOnlyFS) Create(filename string) (billy.File, error)

func (ReadOnlyFS) MkdirAll

func (r ReadOnlyFS) MkdirAll(filename string, perm os.FileMode) error

func (ReadOnlyFS) OpenFile

func (r ReadOnlyFS) OpenFile(name string, flag int, perm os.FileMode) (billy.File, error)

func (ReadOnlyFS) Remove

func (r ReadOnlyFS) Remove(filename string) error

func (ReadOnlyFS) Rename

func (r ReadOnlyFS) Rename(oldpath, newpath string) error

Jump to

Keyboard shortcuts

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