Documentation
¶
Overview ¶
Package identity checks that the git author and committer identities a commit would use match the person's OWN identity record, kept on their own machine under the user-level home (record.go), and recognises a machine identity in either role. Nothing in a repository names who may commit to it (itd-2610240918547728, adr-2610241022541063); a repository that still stores the identity pin itd-131 introduced is migrated (migrate.go).
It is the single source of truth for the managed-repo identity gate: `ahoy doctor` surfaces a divergence as a detection gap, and `abcd ahoy --identity` exits non-zero on one, so a stray repo-local override (e.g. a sandbox "Test User") or a harness's machine identity is caught before the commit rather than discovered later.
Index ¶
- Constants
- Variables
- func IsMachineAddress(role Role, email string) bool
- func IsMachineName(name string) bool
- func IsToolIdentity(role Role, name, email string) bool
- func LoadRecordForTest(home, rootSHA string) (Record, RecordRef, bool, error)
- func Outranking(root string, want Effective) ([]string, error)
- func WriteLocal(root string, id Effective) error
- func WriteRecord(home string, ref RecordRef, r Record) error
- type Effective
- type LegacyPin
- type MigrationPlan
- type MigrationResult
- type Proposal
- type Record
- type RecordRef
- type RecordScope
- type Result
- type Role
- type Status
Constants ¶
const LegacyPinRelPath = provenance.LegacyPinRelPath
LegacyPinRelPath is the identity pin itd-131 committed into a repository. It named one person as who commits there, so every other contributor was told to commit as them (iss-2610240830397793). Nothing gates on it any more; the migration below moves it to its owner's machine and out of the repository.
Variables ¶
var ErrRecordRefused = errors.New("identity record refused")
ErrRecordRefused wraps every record that is there and cannot be trusted or read: the gate fails closed on it, exactly as the shell guard does.
Functions ¶
func IsMachineAddress ¶ added in v0.11.1
IsMachineAddress reports the STRUCTURAL address signals alone, in role: a bot mailbox in either role, and a mailbox named for not being read as the author. The mailbox is the discriminator, never the host: a person's forge privacy address (`1234+name@users.noreply.github.com`) is not a machine's.
func IsMachineName ¶ added in v0.11.1
IsMachineName reports the STRUCTURAL name signal alone: the `[bot]` suffix the forge stamps on an app's account name. It names no vendor, so a reader that must not decide on a vendor token (the contributors page) can use it.
func IsToolIdentity ¶ added in v0.11.1
IsToolIdentity reports whether name <email> is a machine identity in the given role of a commit: an AI vendor's name or mail domain, the forge's own `[bot]` account, a bot mailbox, or a configured automation's name shape (a trailing `bot`, `robot` or `automation` word ending the name or the mailbox's local part), in either role; and, in the AUTHOR role only, a mailbox named for not being read (`noreply@`). The asymmetry is the attribution gate's own — the forge stamps `GitHub <noreply@github.com>` as the committer of every web-UI merge made on a human's click, so it passes as a committer and nowhere else.
It is how the routine case becomes machine-visible: an autonomous run that commits under the harness's default identity is flagged wherever the identity gate runs, before the attribution gate refuses the pull request in CI.
func LoadRecordForTest ¶ added in v0.16.0
LoadRecordForTest is loadRecord for another package's tests, which read back the record a verb wrote; no production code outside this package reads the record by hand.
func Outranking ¶ added in v0.11.1
Outranking names every source that outranks a repository's user.name and user.email for either role and holds a value other than want: a GIT_AUTHOR_* / GIT_COMMITTER_* environment override, or an author.* / committer.* config key. Writing repo-local user.* cannot change what such a source stamps, so a caller that would write it asks this first and, when the list is not empty, says what to unset instead of writing to no effect.
func WriteLocal ¶ added in v0.11.1
WriteLocal sets user.name and user.email in the repository's own .git/config (never the global or system file), as the person running it: a plain git invocation, never a privileged one. Both fields are required.
func WriteRecord ¶ added in v0.16.0
WriteRecord writes r as the record ref names, for the person whose home directory is home, creating the user-level home (and the per-repository folder) at abcdhome.DirMode and the file at abcdhome.FileMode. It refuses a record the shell guard could not read back (a double-quote, backslash or control character), an incomplete one, and a machine identity: the record names a person, and a machine is the one thing it must never name.
The write goes through the home-scope primitives, so a symlinked level is refused rather than written through, and it is atomic, so a crash never leaves a half-written record the gate would then refuse.
Types ¶
type Effective ¶
Effective is the identity git would actually stamp on a commit in the repo, resolved as git resolves the author: the GIT_AUTHOR_NAME/GIT_AUTHOR_EMAIL environment overrides first, then git config's local > global > system layering.
func EffectiveIdentity ¶
EffectiveIdentity returns the author identity git would stamp on a commit in root. Each field is resolved the way git resolves it: the GIT_AUTHOR_NAME / GIT_AUTHOR_EMAIL environment override first (an agent or CI sandbox that exports one lands a mis-attributed commit a config-only check would wave through), then the role's own author.name / author.email config key, which git ranks ahead of user.* (iss-2609261454332615), then user.name / user.email. Config keys follow git's layering: command-line configuration (`git -c`, as a hook inherits it), then local, global and system. An unset name or email yields an empty field, not an error.
type LegacyPin ¶ added in v0.16.0
type LegacyPin struct {
Name string
Email string
ProductionMode string
// Unknown lists any member the migration does not know how to carry. A
// pin holding one is never removed: removing it would drop a setting.
Unknown []string
}
LegacyPin is what a repository's committed identity pin holds.
type MigrationPlan ¶ added in v0.16.0
type MigrationPlan struct {
Pin LegacyPin
// Owner is true when this person's git identity — the one git resolves in
// the repository, or their global one — is the pinned identity. Only an
// owner's machine receives the pin; on anyone else's it is not copied, and
// nothing shown to them names it.
Owner bool
// Target is where an owner's record goes: the repository's own record
// (keyed on its root commit), else the machine-wide default for a
// repository with no commit yet.
Target RecordRef
// Existing is the record already at Target, if any. A different record is
// never overwritten: the person's own record wins over the repository's pin.
Existing Record
ExistingFound bool
// Blocker, when set, is why the pin cannot be removed without losing
// something: a member the migration cannot carry, a pin that names no
// complete human identity, or a production mode that conflicts with the one
// the repository already declares.
Blocker string
}
MigrationPlan is what moving a repository's committed pin would do, for one person on one machine. It is computed without writing anything.
func PlanMigration ¶ added in v0.16.0
func PlanMigration(root, home string) (MigrationPlan, bool, error)
PlanMigration reads the repository's committed pin and says what moving it would do for the person whose home directory is home. found is false when the repository stores no pin.
type MigrationResult ¶ added in v0.16.0
type MigrationResult struct {
// Recorded is true when the pin was written as the owner's record at
// RecordAt; false when an identical record was already there (Kept) or a
// different one was (KeptDifferent).
Recorded bool
Kept bool
KeptDifferent bool
RecordAt RecordRef
// ProductionModeMoved is true when the pin's production_mode was written
// to provenance.DeclaredModeRelPath.
ProductionModeMoved bool
// Removed is true when the pin left the working tree.
Removed bool
}
MigrationResult says what ApplyMigration did.
func ApplyMigration ¶ added in v0.16.0
func ApplyMigration(root, home string, plan MigrationPlan) (MigrationResult, error)
ApplyMigration carries out plan for its owner, in this order: the owner's record (never overwriting a different one), the production mode into its own committed file, then the pin's removal from the working tree. It refuses a plan with a Blocker, and one whose person is not the owner: on anyone else's machine the pin is neither copied nor removed by abcd.
type Proposal ¶ added in v0.11.1
type Proposal struct {
Identity Effective
// From names the source for the person being asked.
From string
}
Proposal is the human identity the gate offers when the effective one diverges, and where it was read from.
func Propose ¶ added in v0.11.1
Propose returns the identity to offer when the effective one diverges: the person's own record on this machine, else their global git identity (user.name/user.email in the caller's global config). The chain is disk-only by decision (itd-131, adr-38): no network lookup in an implicit path. A machine identity is never proposed, and nothing a repository commits is ever read as the proposal (itd-2610240918547728): a contributor is never offered anyone's identity but their own. ok is false when neither source holds a complete human identity.
func ProposeRecord ¶ added in v0.16.0
ProposeRecord returns the identity to offer a person who has not recorded who they commit as on this machine: their usual git identity, which is the global user.name/user.email, else the identity git resolves in this repository when that is a complete human one. A machine identity is never proposed. ok is false when no human identity can be read from disk.
type RecordRef ¶ added in v0.16.0
type RecordRef struct {
Scope RecordScope `json:"scope"`
Rel string `json:"rel"`
Display string `json:"display"`
}
RecordRef names one record file: its scope, its slash path relative to the person's home directory (the form fsutil's home-scope primitives take), and the tilde form a message shows.
func MachineRecordRef ¶ added in v0.16.0
func MachineRecordRef() RecordRef
MachineRecordRef is the machine-wide default record.
type RecordScope ¶ added in v0.16.0
type RecordScope string
RecordScope says which of the two records a RecordRef names.
const ( // ScopeMachine is the machine-wide default record. ScopeMachine RecordScope = "machine" // ScopeRepository is the record for one repository, by its root commit. ScopeRepository RecordScope = "repository" )
type Result ¶
type Result struct {
Status Status
// Record is the person's own record, when one applies (Recorded).
Record Record
Recorded bool
// RecordAt names the record that applies, or would: the repository's own
// record when one exists, else the machine-wide default.
RecordAt RecordRef
Effective Effective
Reason string
// Committer is the committer identity git would stamp (effectiveCommitter).
Committer Effective
// CommitterDiverges reports a committer that differs from the author and is
// not the recorded identity either: a GIT_COMMITTER_* override, a
// committer.* config key, or an author override the committer does not
// share. A committer that is the same wrong identity as the author is not
// reported again — the author status already says so, and one fix mends
// both.
CommitterDiverges bool
// CommitterReason says what diverges, for the person reading the gap.
CommitterReason string
// AuthorIsTool and CommitterIsTool report a machine identity in that role
// (IsToolIdentity), recorded or not.
AuthorIsTool bool
CommitterIsTool bool
}
Result carries the comparison outcome and the identities for reporting.
Status and Effective describe the AUTHOR. The committer is reported beside them rather than folded into Status.
func Check ¶
Check resolves the effective author and committer, loads the person's own record for the repository at root (from the home directory os.UserHomeDir names), and compares them.
func (Result) Blocks ¶
Blocks reports whether a pre-commit hook should refuse the commit, on the shell guard's terms: a mismatch with the person's own record, an unset author, or a machine identity in either role blocks wherever it is found; a committer that diverges blocks when a record applies. With no record, a human identity — whatever launched the run supplied — commits.
type Role ¶ added in v0.11.1
type Role string
Role is one of the two identities git stamps on a commit. The author is who wrote the change and the committer is who recorded it; the contributor graph reads both, so the gate resolves both.
type Status ¶
type Status int
Status is the outcome of comparing the effective identity to the person's own record.
const ( // StatusOK: a record applies and the effective identity matches it. StatusOK Status = iota // StatusNoRecord: no record on this machine applies to the repo. Nothing // to compare against; a machine identity is still refused (Blocks). StatusNoRecord // StatusMismatch: a record applies and the effective identity differs. StatusMismatch // StatusUnset: git has no author identity configured. StatusUnset )