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 ¶
- Variables
- func CleanPath(path string) (string, error)
- func NewBucketFS(rootFS billy.Filesystem, bucket string) (billy.Filesystem, error)
- func NewMetadataFS(rootFS billy.Filesystem) (billy.Filesystem, error)
- func NewMinIOFS(rootFS billy.Filesystem) (billy.Filesystem, error)
- func NewRootFS(dataDir string) (billy.Filesystem, error)
- func NewUploadStagingFS(rootFS billy.Filesystem, bucket string) (billy.Filesystem, error)
- func ValidatePathSafe(path string) error
- type ReadOnlyFS
- func (r ReadOnlyFS) Create(filename string) (billy.File, error)
- func (r ReadOnlyFS) MkdirAll(filename string, perm os.FileMode) error
- func (r ReadOnlyFS) OpenFile(name string, flag int, perm os.FileMode) (billy.File, error)
- func (r ReadOnlyFS) Remove(filename string) error
- func (r ReadOnlyFS) Rename(oldpath, newpath string) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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) Remove ¶
func (r ReadOnlyFS) Remove(filename string) error
func (ReadOnlyFS) Rename ¶
func (r ReadOnlyFS) Rename(oldpath, newpath string) error