Files
archie/internal/domain/storepkg/authority.go
T
sam ed35b826ad feat(store): record accepted package authority against the pin
An archie package declares its authority; nothing in the tree recorded the
operator's acceptance of it. This lands the acceptance-record slice of
docs/prds/store.md ("Authority"):

- storepkg.Authority gains Covers (the upper-bound predicate: equal or
  narrower applies, wider does not) and Validate (forge-permission
  vocabulary, no blank grants).
- Installed carries AcceptedAuthority (nil until accepted); install leaves it
  unset, so an unaccepted package has no authority.
- AcceptPackageAuthority on the storepkg Manager records the acceptance
  against the pinned digest and refuses grants the package does not declare
  (storepkg.ErrAuthorityNotDeclared), carried over the wire.
- staterpc gains the admin-only AcceptPackageAuthority RPC;
  InstalledPackage carries accepted_authority.
2026-09-30 07:40:06 +10:00

60 lines
1.7 KiB
Go

package storepkg
import (
"fmt"
"strings"
)
// Covers reports whether accepted authority is an upper bound of the
// requested authority: every grant the request asks for is one the accepted
// record grants, per field, never across fields. The acceptance record and
// the update-widening check share this predicate (docs/prds/store.md,
// "Authority": an update whose authority is equal or narrower applies).
func (a Authority) Covers(b Authority) bool {
return listCovers(a.CredentialServices, b.CredentialServices) &&
listCovers(a.EgressHosts, b.EgressHosts) &&
listCovers(a.ForgePermissions, b.ForgePermissions) &&
listCovers(a.Triggers, b.Triggers) &&
listCovers(a.Tools, b.Tools)
}
func listCovers(have, want []string) bool {
granted := make(map[string]struct{}, len(have))
for _, grant := range have {
granted[grant] = struct{}{}
}
for _, grant := range want {
if _, ok := granted[grant]; !ok {
return false
}
}
return true
}
// Validate checks authority grant values: forge permissions use the
// descriptor's vocabulary and every grant list rejects blank entries.
func (a Authority) Validate() error {
for _, permission := range a.ForgePermissions {
if !validForgePermission(permission) {
return fmt.Errorf("invalid forge permission %q", permission)
}
}
fields := []struct {
name string
grants []string
}{
{name: "credential service", grants: a.CredentialServices},
{name: "egress host", grants: a.EgressHosts},
{name: "trigger", grants: a.Triggers},
{name: "tool", grants: a.Tools},
}
for _, field := range fields {
for i, grant := range field.grants {
if strings.TrimSpace(grant) == "" {
return fmt.Errorf("%s %d: name is required", field.name, i)
}
}
}
return nil
}