secureuserfile

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 17 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

Index

Constants

View Source
const (
	MaxBytes   = 1 << 20
	FileMode   = os.FileMode(0o600)
	ParentMode = os.FileMode(0o700)
)

Variables

View Source
var (
	ErrTargetUnusable  = errors.New("secure user file: target unusable")
	ErrNoTargetUser    = errors.New("secure user file: no enforceable target user")
	ErrAbsoluteSymlink = fmt.Errorf("secure user file: absolute symlink: %w", ErrTargetUnusable)
	ErrSymlinkLoop     = fmt.Errorf("secure user file: symlink chain too deep: %w", ErrTargetUnusable)
	ErrDanglingSymlink = fmt.Errorf("secure user file: symlink target does not exist: %w", ErrTargetUnusable)
	ErrWriteUnverified = errors.New("secure user file: write could not be verified or rolled back")
)

Functions

This section is empty.

Types

type File

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

File owns safe byte and metadata operations for one relative path.

func (*File) Commit

func (f *File) Commit(data []byte, mode os.FileMode) error

func (*File) ContainsAny

func (f *File) ContainsAny(markers ...string) (bool, error)

ContainsAny reports whether a bounded, identity-checked leaf contains any marker without requiring mutation ownership of that leaf.

func (*File) EnsureParent

func (f *File) EnsureParent() error

EnsureParent creates and pins this file's parent directories.

func (*File) Location

func (f *File) Location() string

func (*File) MetadataSecure

func (f *File) MetadataSecure(want os.FileMode) (bool, error)

MetadataSecure verifies the current leaf's platform permission boundary.

func (*File) OpenLock

func (f *File) OpenLock() (*os.File, error)

OpenLock opens a persistent secure file suitable for an OS advisory lock.

func (*File) ParentPresent

func (f *File) ParentPresent() (bool, error)

ParentPresent reports whether every parent is an existing real directory.

func (*File) ProbeWritable

func (f *File) ProbeWritable(mode os.FileMode) error

ProbeWritable verifies that a secure temporary sibling can be created and removed without changing the managed leaf.

func (*File) PurgeBackups

func (f *File) PurgeBackups() error

func (*File) Read

func (f *File) Read() ([]byte, bool, os.FileMode, error)

func (*File) RelativePath

func (f *File) RelativePath() string

RelativePath returns the cleaned path beneath the pinned home.

func (*File) Remove

func (f *File) Remove() error

func (*File) RequireResolvedPath

func (f *File) RequireResolvedPath(expected string) error

RequireResolvedPath pins future operations to a previously recorded leaf.

func (*File) ResolvedPath

func (f *File) ResolvedPath() (string, error)

ResolvedPath returns the normalized home-relative leaf used by the latest successful mutation, or the leaf currently selected by the symlink chain.

func (*File) RestoreSnapshot

func (f *File) RestoreSnapshot() error

type Home

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

Home pins all managed file operations beneath one resolved user's home.

func OpenUserHome

func OpenUserHome(exec executor.Executor) (*Home, error)

func (*Home) ApplyMetadata

func (h *Home) ApplyMetadata(file *os.File, mode os.FileMode, directory bool) error

ApplyMetadata applies the platform's target-user ownership and permission contract to an already-open file or directory.

func (*Home) Close

func (h *Home) Close() error

func (*Home) EnsureParent

func (h *Home) EnsureParent(relativePath string) error

EnsureParent creates missing parent components without traversing symlinks.

func (*Home) GOOS

func (h *Home) GOOS() string

GOOS returns the platform used to resolve this home.

func (*Home) Getenv

func (h *Home) Getenv(name string) string

Getenv reads an environment variable in the resolved user's context.

func (*Home) MetadataSecure

func (h *Home) MetadataSecure(file *os.File, want os.FileMode) (bool, error)

MetadataSecure verifies the platform permission boundary on an open handle.

func (*Home) Open

func (h *Home) Open(relativePath, backupPrefix string, maxBytes int64) (*File, error)

Open pins one home-relative file and applies strict platform metadata.

func (*Home) Path

func (h *Home) Path() string

Path returns the pinned user's home directory.

func (*Home) User

func (h *Home) User() *user.User

User returns a copy of the resolved target identity.

func (*Home) Username

func (h *Home) Username() string

func (*Home) VerifyOwner

func (h *Home) VerifyOwner(f *os.File, name string) error

VerifyOwner checks that an opened target belongs to the resolved user.

Jump to

Keyboard shortcuts

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