Documentation
¶
Overview ¶
Vault — GoStack Path-Traversal Secure Storage Subsystem.
Naming Metaphor: Why Vault? The GoStack Storage Subsystem was named Vault because a bank "vault" is an impenetrable, reinforced safe that locks valuable assets behind strict security perimeters. Vault treats file uploads and disk writes like deposits into a reinforced chamber, strictly sanitizing and jailing file paths to completely shut down directory traversal attacks (`../../etc/passwd`).
Purpose: This file implements the LocalStorage driver for the Vault storage subsystem of GoStack. It provides a standard file-system storage backend complying with the Storage interface.
Philosophy: Storage engines must be unified and secure. Writing raw paths directly in application logic causes host platform locks. Additionally, un-sanitized user file path inputs expose applications to directory traversal exploits. This driver prevents that by resolving all operations strictly within a configured root directory.
Architecture: A standalone framework package (`github.com/charledeon77/gostack-framework/framework/storage`). Implements the `contract.Storage` interface.
Choice: We chose a local OS file-system backend using standard `os` and `filepath` primitives, ensuring zero-dependency footprint. The path resolution uses strict prefix checking against the root directory to guarantee sandbox safety.
Implementation: - LocalStorage: implements storage operations.
- NewLocalStorage(rootDir): initializes and establishes root directory.
- Put(): writes file content, creating missing subdirectories automatically.
- Get(): reads file content.
- Delete(): removes file.
- Exists(): verifies file presence.
- resolvePath(): sanitizes and validates bounds constraints.
Index ¶
- type LocalStorage
- func (s *LocalStorage) Delete(path string) error
- func (s *LocalStorage) Exists(path string) (bool, error)
- func (s *LocalStorage) Get(path string) ([]byte, error)
- func (s *LocalStorage) GetStream(path string) (io.ReadCloser, error)
- func (s *LocalStorage) Put(path string, contents []byte) error
- func (s *LocalStorage) PutStream(path string, r io.Reader) error
- type S3Config
- type S3Driver
- func (s *S3Driver) Delete(path string) error
- func (s *S3Driver) Exists(path string) (bool, error)
- func (s *S3Driver) Get(path string) ([]byte, error)
- func (s *S3Driver) GetStream(path string) (io.ReadCloser, error)
- func (s *S3Driver) Put(path string, contents []byte) error
- func (s *S3Driver) PutStream(path string, r io.Reader) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LocalStorage ¶
type LocalStorage struct {
// contains filtered or unexported fields
}
LocalStorage handles file-system operations securely confined to a root path.
func NewLocalStorage ¶
func NewLocalStorage(rootDir string) (*LocalStorage, error)
NewLocalStorage instantiates a LocalStorage driver bound to the specified root directory.
func (*LocalStorage) Delete ¶
func (s *LocalStorage) Delete(path string) error
Delete removes the file at the relative target path.
func (*LocalStorage) Exists ¶
func (s *LocalStorage) Exists(path string) (bool, error)
Exists reports whether the relative target path resolves to an existing file on disk. Returns (false, err) on a path-resolution or OS-level error (F-021, F-023).
func (*LocalStorage) Get ¶
func (s *LocalStorage) Get(path string) ([]byte, error)
Get reads the file contents at the relative target path.
func (*LocalStorage) GetStream ¶ added in v1.0.23
func (s *LocalStorage) GetStream(path string) (io.ReadCloser, error)
GetStream opens the file at the relative target path and returns an io.ReadCloser stream. The caller is responsible for closing the returned reader when finished.
type S3Config ¶
type S3Config struct {
Region string
Bucket string
Prefix string // Optional path prefix for all keys
AccessKeyID string
SecretAccessKey string
Endpoint string // Optional: set for MinIO / Cloudflare R2
Timeout time.Duration // Optional: connection/request timeout (default: 30s)
}
S3Config holds the configuration parameters for an S3 connection.
type S3Driver ¶
type S3Driver struct {
// contains filtered or unexported fields
}
S3Driver implements contract.Storage backed by AWS S3 (or any S3-compatible endpoint).
func NewS3Driver ¶
NewS3Driver creates a new S3Driver from the given configuration.
func (*S3Driver) Exists ¶
Exists reports whether the given S3 key exists, using a cheap HeadObject call. Returns (false, err) on a driver or network error (F-021, F-023).
func (*S3Driver) Get ¶
Get downloads the file at the given path from S3 and returns its bytes. Enforces a 64MB read limit to prevent unbounded memory exhaustion (F-020).
func (*S3Driver) GetStream ¶ added in v1.0.23
func (s *S3Driver) GetStream(path string) (io.ReadCloser, error)
GetStream downloads the S3 object at the given path and returns its body as an io.ReadCloser stream. The caller is responsible for closing the returned stream.