Documentation
¶
Overview ¶
Package needs owns a repository's list of the outside tools it needs (.abcd/needs.json), the list's grammar, and the judge every copy of a program passes before abcd will register or start it (itd-2611041815429986, under the trust rule adr-2611041815445203).
The list is data about what a repository needs, never about where a copy lives: it holds a tool's name, why it is needed and, for Go, which file declares its version, and no path, checksum or version of its own. Its grammar is strict so that nothing else can ride in on it: one JSON document, no repeated key, no field the grammar does not name, a name from a narrow alphabet that is never a shell, git, abcd, node or a command a runner starts, a reason that cannot carry a path to type, and a version file from a closed set for its tool.
The judge (judge.go) is the runner's admit rule, extracted so that the runner calls it (Rule.Admit), with the further checks a person's registration is held to (Rule.Judge): the path's own name, every link on the way and what it points at, every directory above them, and their owners.
This is a filter against mistakes, not a boundary (adr-42). It refuses what it reads, and nothing in it can stop a program running on the person's own account from editing a PATH, a home file or anything else that account can write. The package reads bytes it is handed and the file system's metadata; it never runs a program, never writes, and never reaches a network.
Index ¶
Constants ¶
const ( // MaxListBytes bounds the list, so a hostile one cannot hold a reader. MaxListBytes = 64 << 10 // MaxReasonRunes bounds a reason: a sentence, not a document. MaxReasonRunes = 160 )
const ListPath = ".abcd/needs.json"
ListPath is where a repository keeps its tool list, relative to its root.
const SchemaVersion = 1
SchemaVersion is the one version of the list this build reads.
Variables ¶
var ErrReserved = errors.New("reserved")
ErrReserved is checkName's answer for a name in the reserved set.
Functions ¶
func ReservedForTest ¶
ReservedForTest is isReserved, the seam the runner package's test holds each runner's command to: this package cannot import runner, and runner's production code never asks which names are reserved.
func VersionFiles ¶
VersionFiles is versionFiles for a caller outside the package: the files at a repository's root that say it uses name, the closed set the trim at the load gate's disk floor tells a repository's toolchain by (worktree.TrimForFloor).
Types ¶
type Kind ¶
type Kind int
Kind is why the judge refused a copy.
const ( // Relative: the path is not absolute. Relative Kind = iota + 1 // Unresolved: the path, a link on its way or a directory above it does not // exist, or its links do not end. Unresolved // Unreachable: a link leads through a directory this account cannot enter. Unreachable // Unexaminable: something on the way could not be examined. Unexaminable // Writable: the file, or a directory it is reached through, is one group // or other can write. Writable // Inside: the path, a link on its way or its target lies within a guarded // tree: the repository a role runs in, or the checkout it belongs to. Inside // WrongName: the path's own last part is not the tool's name. WrongName // ForeignOwner: the file, or a directory it is reached through, is owned // by an account other than this one or root. ForeignOwner // NotRegular: what the path resolves to is not a regular file. NotRegular )
type ListError ¶
type ListError struct {
// contains filtered or unexported fields
}
ListError is parseList's refusal of a document the strict decode would not read: one that is not one JSON document, holds a repeated key or a field the grammar does not name, or a value of the wrong type. Its text is fixed, because the decoder's names the key the repository wrote; Unwrap hands the decoder's error to errors.As (a *jsonstrict.DuplicateKeyError, say), and a caller that prints what it unwraps repeats the repository's text.
type Refusal ¶
Refusal is the judge's answer for a copy it refuses: why, and the path on the way that it refused, which may be the copy, a link, a directory above either, or the file a link ends at.
type Rule ¶
type Rule struct {
// Guards are the trees a program must not lie within: the repository a
// role runs in and the checkout it belongs to, each held with every git
// working tree it lies in (tools.GuardForms). "" is skipped.
Guards []string
// ReachedThrough is a further path the program was reached through, held
// to the guards as the path is; "" for none.
ReachedThrough string
// Group reads the owning group of a stat result; nil reads it from the
// result itself. The runner's tests narrow it.
Group func(os.FileInfo) (uint32, bool)
}
Rule is what a copy is judged against.
func (Rule) Admit ¶
Admit is the runner's admit rule: it returns the file p resolves to, or a *Refusal when p is not absolute, does not resolve, when it, the directory p reaches it through or the directory it resolves into is one group or other can write (darwin's admin group aside, adminGroupWritableOnly), or when p, the file or ReachedThrough lies within a guard, lexically or after symlink resolution. Its checks and their order are the runner's; it adds two refusals after them. A route the system does not take as its text shows, or that ends elsewhere than the system's resolution of p, cannot be examined (Unexaminable; tools.Walk says when). And the location of any link on p's route lies within a guard (Inside): a step of p's chain or a directory link in the middle of a folder path, the file the route ends at, ReachedThrough's own location (its directory resolved, and its name), and the links on ReachedThrough's route while all of it exists.
func (Rule) Judge ¶
Judge is Admit with the checks a registration of name is held to: p's own last part is name; each step of p's link chain is held to the guards as written, and every link on its route (tools.Walk) where it lies; every directory above each step as written, above each link on the route, above the file it ends at and above each real directory the route passes through is one no one else can write, a sticky directory admitted over an entry this account or root owns; each of those directories and the file is owned by this account or root; and the file is a regular one.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Reason string `json:"reason"`
VersionFile string `json:"version_file,omitempty"`
}
Tool is one entry: a name, why the repository needs it, and the file that declares its version, "" for a tool abcd checks no version of.
type Verdict ¶
Verdict is what Judge admitted: the path as given, cleaned; the file it resolves to; and each step its links pass through after the path, the last being the file itself, empty when the path is no link. Callers use Verdict.Path and never the raw input: Clean is lexical, so a raw a/link/../b names what the system reaches through link, while Path names the file the judge examined.