Documentation
¶
Overview ¶
Package filesystem resolves paths and enforces filesystem allowlists.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatchGlob ¶ added in v0.7.0
MatchGlob reports whether the slash-separated path rel matches pattern. "*" and "?" stay within one path segment and "**" spans segments. A pattern without a slash matches the base name at any depth.
func ResolvePath ¶
ResolvePath resolves a user-supplied path against baseDir (for relative paths), expands special prefixes, and resolves any existing symlink ancestors.
Types ¶
type ExpandedRule ¶ added in v0.7.0
ExpandedRule is an allowlist rule with its pattern expanded to an absolute path, and Dir the directory its globs sit under.
func ExpandRules ¶ added in v0.7.0
func ExpandRules(patterns []string, baseDir string) ([]ExpandedRule, error)
ExpandRules expands each of the ordered rules the way NewPolicy does, to pass them on to another enforcer such as a CLI session's own permission rules. Patterns keep their case and the OS's separators.
type IgnoreMatcher ¶ added in v0.7.0
type IgnoreMatcher struct {
// contains filtered or unexported fields
}
IgnoreMatcher evaluates .gitignore rules collected from a directory tree.
func (*IgnoreMatcher) AddGitignore ¶ added in v0.7.0
func (m *IgnoreMatcher) AddGitignore(dir, relDir string) error
AddGitignore loads the .gitignore file in dir, whose slash-separated path relative to the walk root is relDir ("" for the root itself). A missing file is not an error.
func (*IgnoreMatcher) AddPattern ¶ added in v0.7.0
func (m *IgnoreMatcher) AddPattern(relDir, line string)
AddPattern adds a single gitignore pattern line scoped to relDir.
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy evaluates ordered allow/deny filesystem rules.
func NewPolicy ¶
NewPolicy compiles the provided ordered rules. Relative paths are resolved relative to baseDir.
func PolicyFromAgent ¶
func PolicyFromAgent(cfg *config.AgentConfig, agentDir string) (*Policy, error)
PolicyFromAgent creates a path policy from an agent config. Relative paths in the allowlist are resolved relative to agentDir.
func (*Policy) Allows ¶
Allows reports whether the resolved path is allowed by the ordered rule set.
func (*Policy) Decide ¶ added in v0.7.0
Decide reports whether the resolved path is allowed and the rule that decided it, as written: the last rule that matches. The rule is empty when none matches.
func (*Policy) MayAllowWithin ¶ added in v0.7.0
MayAllowWithin reports whether the policy could allow dir itself or any path beneath it, so a search rooted at dir is worth running.