sandbox

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 11 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 sandbox reads a Flatpak sandbox's file grants and explains a file error that they cause (docs/design/app.md#the-flatpak). A vault outside the grants fails with a plain "no such file or directory" or "permission denied", which does not tell a person that a narrowed --filesystem is the cause. Grants reads the [Context] filesystems of /.flatpak-info and says how far a path is covered; Explain turns a file error on an uncovered path into one that names the fix, and only when it is sure: a grant it cannot decode or resolve, or a path that Flatpak always exposes, leaves the plain error.

Index

Constants

View Source
const AppID = "org.frostyard.Frostnotes"

AppID is the Frostnotes Flatpak's application ID, as internal/config.AppID.

View Source
const InfoPath = "/.flatpak-info"

InfoPath is the file that a Flatpak sandbox holds at its root.

Variables

This section is empty.

Functions

func Quote

func Quote(s string) string

Quote returns s for a POSIX shell: as it is when it holds only plain characters, else in single quotes.

Types

type Env

type Env struct {
	// Home is the home directory, what the grant "home" and "~" name.
	Home string
	// RuntimeDir is $XDG_RUNTIME_DIR, what "xdg-run" names.
	RuntimeDir string
	// ConfigHome is the sandbox's $XDG_CONFIG_HOME (in a Flatpak,
	// ~/.var/app/<ID>/config), where Flatpak puts a copy of the host's
	// user-dirs.dirs; it is read before Home's .config/user-dirs.dirs.
	ConfigHome string
	// HostDataHome, HostConfigHome, HostCacheHome and HostStateHome are the
	// host's $XDG_*_HOME, which Flatpak passes on as HOST_XDG_*_HOME when
	// the host sets them; "xdg-data" and its kin name them, and the XDG
	// defaults under Home when they are empty.
	HostDataHome, HostConfigHome, HostCacheHome, HostStateHome string
}

Env is what the grants depend on besides /.flatpak-info.

func EnvFromOS

func EnvFromOS() Env

EnvFromOS returns the Env of this process.

type Error

type Error struct {
	Path     string
	ReadOnly bool // the grants cover Path, but read only
	App      string
	Cause    error
}

Error says that the sandbox's file access keeps the app from a path.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the file error that this explains.

type Grants

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

Grants are a sandbox's file grants. The zero value, and nil, grant nothing; Explain on nil leaves an error as it is, which is how code outside a Flatpak asks.

func Load

func Load(infoPath string, env Env) (*Grants, error)

Load reads the file grants of the sandbox described by the file at infoPath. An error that matches fs.ErrNotExist means this is no Flatpak.

func Parse

func Parse(r io.Reader, env Env) (*Grants, error)

Parse reads the [Context] filesystems of a /.flatpak-info from r. A value it cannot decode, or an entry it cannot understand or resolve, makes the grants uncertain (Certain).

func (*Grants) Access

func (g *Grants) Access(p string) Mode

Access says how far the grants cover p, an absolute path: the entry with the deepest root that holds p decides, a later entry beating an earlier one of the same root, so "!~/Secret" under "home" leaves ~/Secret out and "~/Notes:rw" under "home:ro" opens it.

func (*Grants) App

func (g *Grants) App() string

App is the sandbox's application ID.

func (*Grants) Certain

func (g *Grants) Certain() bool

Certain says whether every grant was decoded and resolved. Explain says nothing when it is not: coverage cannot be disproved.

func (*Grants) Explain

func (g *Grants) Explain(p string, err error) error

Explain returns err as it is, unless it is a file error that the grants explain for p: no such file, permission denied or not permitted on a path that the grants do not cover, or a read-only file system on one that they cover at most read-only. It then returns an *Error that says what to grant. It says nothing, and returns err, when it cannot be sure: a nil Grants (not in a Flatpak), grants that are not Certain, and a path that Flatpak always exposes (Exposed). A path that the grants cover keeps its plain error too.

func (*Grants) Exposed

func (g *Grants) Exposed(p string) bool

Exposed says whether Flatpak gives the sandbox p whatever the grants say. Under /run only /run/media is left out.

type Mode

type Mode int

Mode is how far the grants let the app reach a path.

const (
	None Mode = iota
	ReadOnly
	ReadWrite
)

The modes: no access, read only, and read and write.

Jump to

Keyboard shortcuts

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