feat(audit,approvals,deliveries): wire audit producers, ITSM change requests, and fix Dockerfile.archie (#2153)

This commit is contained in:
sam committed 2026-11-28 00:42:37 +11:00
1 parent fdfcbab4bd
commit d0d79cbf91
26 files changed
+671 -35

No files matched your search

+13 -4
View File
@@ -15,14 +15,17 @@ import (
// the extension contract: a connector that declares one must declare a schema
// that accepts what core sends.
const (
DeliveryMessage = "message"
DeliveryChatMessage = "chat_message"
DeliveryMessage = "message"
DeliveryChatMessage = "chat_message"
DeliveryChangeRequest = "change_request"
DeliveryChangeRequestWithdraw = "change_request_withdraw"
)
// coreDeliveries lists, for each delivery core sends itself, every payload
// shape core may put in it: a message always has a title, and may also carry
// a body and, for an approval request, its request id; a chat message always
// has a chat id and text.
// has a chat id and text; change requests carry short_description and
// description; withdrawals carry key and reason.
var coreDeliveries = map[string][]jsontext.Value{
DeliveryMessage: {
jsontext.Value(`{"title":"a title"}`),
@@ -33,13 +36,19 @@ var coreDeliveries = map[string][]jsontext.Value{
DeliveryChatMessage: {
jsontext.Value(`{"chat_id":"a chat","text":"a message"}`),
},
DeliveryChangeRequest: {
jsontext.Value(`{"short_description":"a change","description":"details"}`),
},
DeliveryChangeRequestWithdraw: {
jsontext.Value(`{"key":"req:change_request","reason":"approval expired"}`),
},
}
// checkCoreDeliveries refuses a declaration of a delivery core sends itself
// whose input schema rejects a payload core sends, so the mismatch surfaces
// when the connector loads rather than when a delivery is mid-flight.
func checkCoreDeliveries(caps Capabilities) error {
for _, name := range []string{DeliveryMessage, DeliveryChatMessage} {
for _, name := range []string{DeliveryMessage, DeliveryChatMessage, DeliveryChangeRequest, DeliveryChangeRequestWithdraw} {
d, ok := caps.Delivery(name)
if !ok {
continue
+1
View File
@@ -110,6 +110,7 @@ func (m *Module) saveCatalogueSource(ctx context.Context, src store.Source) (*ht
return nil, huma.NewError(http.StatusInternalServerError, "couldn't save the catalogue source")
}
m.log.InfoContext(ctx, "catalogue source set", "audit", true, "action", "catalogue.source")
m.emitAudit(ctx, "catalogue.source", "catalogue", src.Location, nil)
return m.getCatalogueSource(ctx, nil)
}
+1
View File
@@ -251,6 +251,7 @@ func (m *Module) saveInstallation(ctx context.Context, auth authority, a store.I
}
m.log.InfoContext(ctx, "installation saved", "audit", true, "action", "installation.save",
"installation", a.ID.String(), "scope", a.Scope, "package", a.PackageName)
m.emitAudit(ctx, "installation.save", "installation", a.ID.String(), map[string]any{"scope": a.Scope, "package": a.PackageName})
view, err := m.viewOf(a, auth.manages(a.Owner()))
if err != nil {
return nil, huma.NewError(http.StatusInternalServerError, err.Error())
+18
View File
@@ -20,8 +20,10 @@ import (
"github.com/jmoiron/sqlx"
"github.com/samcharles93/archie-core/internal/platform/seal"
"github.com/samcharles93/archie-core/modules/audit"
"github.com/samcharles93/archie-core/modules/connectors/internal/catalogue"
"github.com/samcharles93/archie-core/modules/connectors/internal/store"
"github.com/samcharles93/archie-core/modules/governance"
)
// validName is the shape of a connector name: it appears in logs and URLs.
@@ -35,6 +37,7 @@ type Module struct {
host *Host
store registry
sealer *seal.Sealer
audit audit.Recorder
log *slog.Logger
// sources and fetcher read the catalogue and its artifacts, and pkgMu
// serialises changes to a package's versions.
@@ -80,6 +83,21 @@ func (m *Module) Use(recheck Recheck) {
m.recheck = recheck
}
// UseAudit configures the audit recorder notified on extension and catalogue changes.
func (m *Module) UseAudit(r audit.Recorder) { m.audit = r }
func (m *Module) emitAudit(ctx context.Context, action, resourceKind, resourceID string, detail any) {
audit.Emit(ctx, m.audit, m.log, audit.Event{
Category: "extensions",
Action: action,
ActorID: governance.CallerID(ctx),
ResourceKind: resourceKind,
ResourceID: resourceID,
Outcome: "success",
Detail: detail,
})
}
// UseRemotes configures static remote gRPC+mTLS extension endpoints.
func (m *Module) UseRemotes(cfg RemoteConfig) error {
return m.host.UseRemotes(cfg)
+2
View File
@@ -137,6 +137,7 @@ func (m *Module) register(ctx context.Context, source catalogueSnapshot, entry c
}
m.log.InfoContext(ctx, "package version registered", "audit", true, "action", "package.register",
"package", entry.Name, "version", v.Version, "digest", v.Digest)
m.emitAudit(ctx, "package.register", "package", entry.Name, map[string]any{"version": v.Version, "digest": v.Digest})
return pkg, ver, nil
}
@@ -183,6 +184,7 @@ func (m *Module) acceptGrants(ctx context.Context, v store.Version, want *grants
}
m.log.InfoContext(ctx, "package version accepted", "audit", true, "action", "package.accept",
"version_id", v.ID.String(), "version", v.Version)
m.emitAudit(ctx, "package.accept", "package_version", v.ID.String(), map[string]any{"version": v.Version})
return accepted, nil
}
+2
View File
@@ -66,6 +66,7 @@ func (m *Module) removeAs(ctx context.Context, in *nameInput, contract string) (
// There is no audit trail module yet, so the removal is a structured log
// line.
m.log.InfoContext(ctx, "accepted package removed", "audit", true, "action", "package.remove", "contract", contract, "package", name)
m.emitAudit(ctx, "package.remove", "package", name, map[string]any{"contract": contract})
return httpapi.OK(packageState{Name: name, State: "removed"}), nil
}
@@ -143,6 +144,7 @@ func (m *Module) removeInstallation(ctx context.Context, in *installationInput)
}
m.log.InfoContext(ctx, "installation removed", "audit", true, "action", "installation.remove",
"installation", a.ID.String(), "scope", a.Scope, "package", a.PackageName)
m.emitAudit(ctx, "installation.remove", "installation", a.ID.String(), map[string]any{"scope": a.Scope, "package": a.PackageName})
return httpapi.OK(packageState{Name: a.Name, State: "removed"}), nil
}