From bc4ac4436df126d0d922ec9a6c407a68e586bb6a Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 27 Nov 2026 02:21:13 +1100 Subject: [PATCH] docs(connectors): clarify catalogue and guard comments (#2119) --- modules/connectors/installations.go | 7 +++---- modules/connectors/internal/catalogue/fetch.go | 8 ++++---- modules/connectors/internal/catalogue/grants.go | 4 ++-- modules/connectors/internal/catalogue/oci.go | 6 ++---- modules/connectors/internal/catalogue/oci_test.go | 4 ++-- modules/connectors/internal/host/host.go | 3 +-- modules/connectors/internal/store/store.go | 10 +++++----- modules/connectors/module.go | 5 +++-- modules/connectors/packages.go | 13 ++++++------- modules/connectors/scope_test.go | 4 ++-- 10 files changed, 30 insertions(+), 34 deletions(-) diff --git a/modules/connectors/installations.go b/modules/connectors/installations.go index 36b2cd812..3d04c103e 100644 --- a/modules/connectors/installations.go +++ b/modules/connectors/installations.go @@ -295,10 +295,9 @@ func checkAccepted(a store.Installed, req installationRequest) error { return nil } -// checkGrants bounds what an organisation or a person may grant an extension. -// The instance's installations of a package are what an administrator -// accepted, so an installation below them may see only the environment -// variables those pass on. Each installation names its own egress hosts. +// checkGrants limits organisation and personal installations to environment +// variables granted to the package at instance scope. Only an instance +// installation can request unrestricted egress. func checkGrants(a store.Installed, req installationRequest, installed []store.Installed) error { if a.Scope == store.ScopeInstance { return nil diff --git a/modules/connectors/internal/catalogue/fetch.go b/modules/connectors/internal/catalogue/fetch.go index 57afc882b..6bdeb6071 100644 --- a/modules/connectors/internal/catalogue/fetch.go +++ b/modules/connectors/internal/catalogue/fetch.go @@ -42,7 +42,7 @@ func NewFetcher(dir string) *Fetcher { return &Fetcher{Dir: dir, Client: &http.Client{Timeout: 5 * time.Minute}} } -// CheckSource validates a catalogue source, which can also be an OCI repository. +// CheckSource accepts OCI repositories, HTTPS URLs, loopback HTTP URLs and absolute paths. func CheckSource(loc string) error { if isOCI(loc) || checkLocation(loc) == nil { return nil @@ -150,9 +150,9 @@ func (f *Fetcher) readAll(ctx context.Context, loc string) ([]byte, error) { return data, nil } -// FetchVersion keeps the verified binary and returns its path and SHA-256. -// An OCI version pins the manifest, not the binary, so its binary has a -// separate digest for the host to check at launch. +// FetchVersion saves the verified binary and returns its path and SHA-256. +// OCI catalogue entries pin the manifest. The host checks the binary's own +// digest before starting it. func (f *Fetcher) FetchVersion(ctx context.Context, name, location string, v Version) (path, digest string, err error) { if b := v.binary; b != nil { layer, err := fetchLayer(ctx, b.repository, b.layer, 64<<20) diff --git a/modules/connectors/internal/catalogue/grants.go b/modules/connectors/internal/catalogue/grants.go index 2bc48877c..0831e093f 100644 --- a/modules/connectors/internal/catalogue/grants.go +++ b/modules/connectors/internal/catalogue/grants.go @@ -37,7 +37,7 @@ func tidy(in []string) []string { return slices.Compact(out) } -// Covers reports whether every grant in want is one g holds. +// Covers reports whether g includes every requested grant. func (g Grants) Covers(want Grants) bool { return subset(want.Egress, g.Egress) && subset(want.Env, g.Env) && subset(want.Credentials, g.Credentials) } @@ -51,7 +51,7 @@ func subset(want, have []string) bool { return true } -// Added returns what want asks for beyond g. +// Added returns the requested grants that g doesn't include. func (g Grants) Added(want Grants) Grants { return Grants{ Egress: missing(want.Egress, g.Egress), diff --git a/modules/connectors/internal/catalogue/oci.go b/modules/connectors/internal/catalogue/oci.go index 55173873c..ebda2f1db 100644 --- a/modules/connectors/internal/catalogue/oci.go +++ b/modules/connectors/internal/catalogue/oci.go @@ -88,8 +88,8 @@ func (f *Fetcher) repository(loc string) (*remote.Repository, error) { return r, nil } -// ReadOCI verifies the catalogue before fetching any package metadata. Every -// descriptor is then verified against the catalogue's immutable manifest pin. +// ReadOCI verifies the catalogue signature, then checks each package manifest +// against the digest in the signed catalogue. func (f *Fetcher) ReadOCI(ctx context.Context, loc string, key ed25519.PublicKey) (Document, error) { r, err := f.repository(loc) if err != nil { @@ -191,8 +191,6 @@ func packageEntry(p publishedPackage, meta packageMetadata, binary *ociBinary) E } } -// fetchManifest and fetchLayer carry the bounded, digest-checked OCI reads -// used by the signed catalogue and its pinned packages. func fetchManifest(ctx context.Context, r *remote.Repository, ref, pin string) (ocispec.Manifest, error) { _, stream, err := r.FetchReference(ctx, ref) if err != nil { diff --git a/modules/connectors/internal/catalogue/oci_test.go b/modules/connectors/internal/catalogue/oci_test.go index 8533c009f..1eeeec114 100644 --- a/modules/connectors/internal/catalogue/oci_test.go +++ b/modules/connectors/internal/catalogue/oci_test.go @@ -16,8 +16,8 @@ import ( ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) -// TestReadOCIChecksSignatureAndPackagePin ensures a registry can't substitute -// a different grants or settings descriptor for a signed catalogue entry. +// TestReadOCIChecksSignatureAndPackagePin checks that a registry can't replace +// the package manifest that declares settings and grants. func TestReadOCIChecksSignatureAndPackagePin(t *testing.T) { key, signer, err := ed25519.GenerateKey(nil) if err != nil { diff --git a/modules/connectors/internal/host/host.go b/modules/connectors/internal/host/host.go index b2654fd1b..68ddb9a80 100644 --- a/modules/connectors/internal/host/host.go +++ b/modules/connectors/internal/host/host.go @@ -43,8 +43,7 @@ type Spec struct { // Env names the host environment variables the extension may see. PATH and // HOME are always passed so a plugin can find the CLI it wraps. Env []string - // Egress is the accepted host list. The extension can reach only these - // hosts through its proxy. + // Egress lists the hosts the extension may reach through its proxy. Egress []string } diff --git a/modules/connectors/internal/store/store.go b/modules/connectors/internal/store/store.go index 6dc94d3ac..d99a2a214 100644 --- a/modules/connectors/internal/store/store.go +++ b/modules/connectors/internal/store/store.go @@ -27,8 +27,8 @@ type Source struct { Generation int64 `db:"generation"` } -// CatalogueSource returns the override and the active source's freshness mark. -// An empty location selects the built-in source. +// CatalogueSource returns the configured override and the newest issue time +// accepted from the active source. An empty location means there's no override. func (s *Store) CatalogueSource(ctx context.Context) (Source, error) { var out Source err := s.db.GetContext(ctx, &out, ` @@ -62,8 +62,8 @@ func (s *Store) PutCatalogueSource(ctx context.Context, src Source) error { return nil } -// AdvanceCatalogue records freshness only for the source that was read. The -// built-in source keeps its own mark when the operator selects an override. +// AdvanceCatalogue rejects reads from an earlier source generation and never +// lowers the issue time. An override doesn't reset Archipelago's issue time. func (s *Store) AdvanceCatalogue(ctx context.Context, generation int64, issuedAt time.Time) (bool, error) { if generation == 0 { if _, err := s.db.ExecContext(ctx, `INSERT INTO connectors.catalogue_source (location, public_key) @@ -325,7 +325,7 @@ var ( ErrDefaultVersion = errors.New("the version is the package's default") // ErrVersionPinned means an installation pins the version. ErrVersionPinned = errors.New("an installation pins the version") - // ErrCatalogueChanged means a different source or newer catalogue superseded the fetch. + // ErrCatalogueChanged means the source changed or a newer catalogue was accepted during the fetch. ErrCatalogueChanged = errors.New("the catalogue changed while the package was being fetched") ) diff --git a/modules/connectors/module.go b/modules/connectors/module.go index bb96d3d61..f74c63c3b 100644 --- a/modules/connectors/module.go +++ b/modules/connectors/module.go @@ -293,8 +293,9 @@ func (m *Module) connectorsFor(ctx context.Context) []*Connector { return out } -// Guards lists every enabled guard in scope. A narrower installation can't -// shadow a guard, and an unavailable guard must still contribute a verdict. +// Guards returns the enabled guards that apply to the caller. A same-named +// installation can't replace an inherited guard. An unavailable guard still +// participates so an action can't proceed without review. func (m *Module) Guards(ctx context.Context) []*Guard { scope := ScopeFromContext(ctx) owners := scope.owners() diff --git a/modules/connectors/packages.go b/modules/connectors/packages.go index 94d8260dc..9341587d7 100644 --- a/modules/connectors/packages.go +++ b/modules/connectors/packages.go @@ -205,9 +205,9 @@ func (m *Module) relaunchFollowers(ctx context.Context, packageID uuid.UUID, ski return errors.Join(errs...) } -// promote launches followers before changing the durable default. A restart -// during promotion still loads the old version. On failure, restore each -// installation that was touched, including the one that failed to start. +// promote leaves the saved default unchanged until every enabled follower starts +// on the new version. If promotion fails, it restarts each affected installation +// on its previous version. func (m *Module) promote(ctx context.Context, pkg store.Package, v store.Version) error { installed, err := m.store.List(ctx) if err != nil { @@ -592,10 +592,9 @@ func errNoVersion(name, version string) error { return huma.NewError(http.StatusNotFound, fmt.Sprintf("%s has no version %s", name, version)) } -// UpdateAuto fetches the newest catalogue version of every package whose -// policy is auto. One whose grants the default version's cover becomes the -// default; one that asks for more waits for an operator. One package that -// fails doesn't stop the rest. +// UpdateAuto updates packages set to update automatically. A version that +// requests additional grants waits for operator acceptance. A failed update +// doesn't stop other updates. func (m *Module) UpdateAuto(ctx context.Context) error { pkgs, err := m.store.Packages(ctx) if err != nil { diff --git a/modules/connectors/scope_test.go b/modules/connectors/scope_test.go index da572e8a6..7da086d83 100644 --- a/modules/connectors/scope_test.go +++ b/modules/connectors/scope_test.go @@ -108,8 +108,8 @@ func TestOverridesNameTheScopeThatSetThem(t *testing.T) { } } -// TestInheritedGuardStillJudges guards against a saved override or a -// narrower installation masking an unavailable enforcing guard. +// TestInheritedGuardStillJudges checks that an unavailable enforcing guard +// still applies despite a saved override and a same-named personal guard. func TestInheritedGuardStillJudges(t *testing.T) { instance := store.Installed{ID: uuid.New(), Scope: store.ScopeInstance, Name: "hours", Contract: store.ContractGuard, Enabled: true} personal := store.Installed{ID: uuid.New(), Scope: store.ScopePerson, PersonID: "me", Name: "hours", Contract: store.ContractGuard, Enabled: true}