feat(audit,approvals,deliveries): wire audit producers, ITSM change requests, and fix Dockerfile.archie (#2153)
This commit is contained in:
26 files changed
+671
-35
No files matched your search
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/buildinfo"
|
||||
"github.com/samcharles93/archie-core/internal/platform/pg"
|
||||
"github.com/samcharles93/archie-core/internal/platform/stableid"
|
||||
"github.com/samcharles93/archie-core/modules/audit"
|
||||
"github.com/samcharles93/archie-core/modules/governance"
|
||||
"github.com/samcharles93/archie-core/modules/judgement"
|
||||
"github.com/samcharles93/archie-core/modules/runs"
|
||||
@@ -827,6 +828,22 @@ func applyBundleDB(ctx context.Context, db *sqlx.DB, log *slog.Logger, desired B
|
||||
if err := tx.Commit(); err != nil {
|
||||
return BundleDiff{}, fmt.Errorf("commit bundle: %w", err)
|
||||
}
|
||||
digest, _ := desired.Digest()
|
||||
audit.Emit(ctx, audit.NewModule(db, log, orgID), log, audit.Event{
|
||||
Category: "promotion",
|
||||
Action: "bundle.apply",
|
||||
ActorID: governance.CallerID(ctx),
|
||||
ResourceKind: "bundle",
|
||||
ResourceID: digest,
|
||||
Outcome: "success",
|
||||
Detail: map[string]any{
|
||||
"stage": stage,
|
||||
"workflows_changed": len(diff.Workflows),
|
||||
"access_policies_changed": len(diff.AccessPolicies),
|
||||
"judgement_rules_changed": len(diff.JudgementRules),
|
||||
"action_types_changed": len(diff.ActionTypes),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
logBundleApply(ctx, log, stage, dryRun, diff)
|
||||
|
||||
@@ -14,8 +14,10 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/buildinfo"
|
||||
"github.com/samcharles93/archie-core/internal/platform/pg"
|
||||
"github.com/samcharles93/archie-core/internal/platform/seal"
|
||||
"github.com/samcharles93/archie-core/modules/audit"
|
||||
"github.com/samcharles93/archie-core/modules/connectors"
|
||||
"github.com/samcharles93/archie-core/modules/events"
|
||||
"github.com/samcharles93/archie-core/modules/governance"
|
||||
)
|
||||
|
||||
const rekeyLockKey = "archie.rekey.owner"
|
||||
@@ -134,6 +136,20 @@ func Rekey(ctx context.Context, configPath string, rcfg RekeyConfig) error {
|
||||
if err := tx.Commit(); err != nil {
|
||||
return fmt.Errorf("commit rekey transaction: %w", err)
|
||||
}
|
||||
audit.Emit(ctx, audit.NewModule(db, log, orgID), log, audit.Event{
|
||||
Category: "crypto",
|
||||
Action: "sealing.rekey",
|
||||
ActorID: string(governance.SystemID),
|
||||
ActorKind: "system",
|
||||
ResourceKind: "org",
|
||||
ResourceID: orgID,
|
||||
Outcome: "success",
|
||||
Detail: map[string]any{
|
||||
"credentials_rekeyed": creds,
|
||||
"sources_rekeyed": sources,
|
||||
"backup_recipients": len(rcfg.NewBackups),
|
||||
},
|
||||
})
|
||||
log.InfoContext(ctx, "age sealing keys rotated",
|
||||
"credentials_rekeyed", creds,
|
||||
"sources_rekeyed", sources,
|
||||
|
||||
@@ -261,6 +261,7 @@ func wire(log *slog.Logger, configPath string, cfg Config, db *sqlx.DB, draining
|
||||
hear.Routes(mux)
|
||||
engine.UseReferrers(hear)
|
||||
judge := newJudgement(db, log, conns, actionTypes, policies, settings, hear)
|
||||
wireAuditAndChanges(log, auditLog, settings, allow, policies, conns, sys, tell)
|
||||
remember, err := wireMemory(db, log, cfg.StateDir, checks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -413,6 +414,47 @@ func newJudgement(db *sqlx.DB, log *slog.Logger, conns *connectors.Module, actio
|
||||
return judge
|
||||
}
|
||||
|
||||
func wireAuditAndChanges(
|
||||
log *slog.Logger,
|
||||
auditLog *audit.Module,
|
||||
settings *governance.Module,
|
||||
allow *approvals.Module,
|
||||
policies *judgement.Policies,
|
||||
conns *connectors.Module,
|
||||
sys *system.Module,
|
||||
tell *deliveries.Module,
|
||||
) {
|
||||
settings.UseAudit(func(ctx context.Context, e governance.AuditRecord) {
|
||||
audit.Emit(ctx, auditLog, log, audit.Event{
|
||||
Category: e.Category, Action: e.Action, ActorID: e.ActorID, ActorKind: e.ActorKind,
|
||||
ResourceKind: e.ResourceKind, ResourceID: e.ResourceID, Outcome: e.Outcome, Detail: e.Detail,
|
||||
})
|
||||
})
|
||||
allow.UseAudit(auditLog)
|
||||
policies.UseAudit(auditLog)
|
||||
conns.UseAudit(auditLog)
|
||||
sys.UseAudit(auditLog)
|
||||
allow.UseChangeRequests(changeRequests{tell: tell})
|
||||
}
|
||||
|
||||
type changeRequests struct {
|
||||
tell *deliveries.Module
|
||||
}
|
||||
|
||||
func (c changeRequests) Open(ctx context.Context, r approvals.Request) error {
|
||||
return c.tell.OpenChangeRequest(ctx, deliveries.ChangeRequest{
|
||||
RunID: r.RunID,
|
||||
RequestID: r.ID,
|
||||
Key: r.Key,
|
||||
ShortDescription: "Archie change: " + r.Connector + " " + r.Action,
|
||||
Description: r.Summary,
|
||||
})
|
||||
}
|
||||
|
||||
func (c changeRequests) Withdraw(ctx context.Context, r approvals.Request) error {
|
||||
return c.tell.WithdrawChangeRequest(ctx, r.RunID, r.ID, r.Key, "the approval expired")
|
||||
}
|
||||
|
||||
// orgID is the one organisation until hosting is multi-tenant.
|
||||
const orgID = "default"
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE deliveries.messages
|
||||
DROP CONSTRAINT IF EXISTS messages_kind_check;
|
||||
ALTER TABLE deliveries.messages
|
||||
ADD CONSTRAINT messages_kind_check
|
||||
CHECK (kind IN ('notification', 'approval_request', 'approval_answer', 'change_request', 'change_request_withdraw'));
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE deliveries.messages
|
||||
DROP CONSTRAINT IF EXISTS messages_kind_check;
|
||||
ALTER TABLE deliveries.messages
|
||||
ADD CONSTRAINT messages_kind_check
|
||||
CHECK (kind IN ('notification', 'approval_request', 'approval_answer'));
|
||||
Reference in new issue
Block a user