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
@@ -736,6 +736,10 @@ func (m *Module) finishOIDC(ctx context.Context, in *oidcCallbackInput) (*redire
|
||||
return nil, m.accountError(ctx, err)
|
||||
}
|
||||
m.log.InfoContext(ctx, "account signed in through the identity provider", "identity", value.ID)
|
||||
m.recordAudit(ctx, AuditRecord{
|
||||
Category: "auth", Action: "auth.oidc.login", ActorID: string(value.ID), ActorKind: "user",
|
||||
ResourceKind: "identity", ResourceID: string(value.ID), Outcome: "success",
|
||||
})
|
||||
return &redirectReply{
|
||||
Location: "/",
|
||||
SetCookie: []http.Cookie{
|
||||
@@ -810,6 +814,10 @@ func (m *Module) backchannelLogout(ctx context.Context, in *backchannelLogoutInp
|
||||
if err := m.RevokeSessionsBySubject(ctx, sub.Issuer, sub.Subject); err != nil {
|
||||
return nil, m.accountError(ctx, err)
|
||||
}
|
||||
m.recordAudit(ctx, AuditRecord{
|
||||
Category: "auth", Action: "auth.oidc.backchannel_logout", ActorID: sub.Issuer + ":" + sub.Subject, ActorKind: "oidc",
|
||||
ResourceKind: "session", ResourceID: sub.Issuer + ":" + sub.Subject, Outcome: "success",
|
||||
})
|
||||
return &backchannelLogoutReply{CacheControl: "no-store"}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -283,6 +283,18 @@ type WorkflowAliases interface {
|
||||
WorkflowsUsingModel(ctx context.Context, orgID, alias string) ([]string, error)
|
||||
}
|
||||
|
||||
// AuditRecord describes a security or policy audit event emitted by governance.
|
||||
type AuditRecord struct {
|
||||
Category string
|
||||
Action string
|
||||
ActorID string
|
||||
ActorKind string
|
||||
ResourceKind string
|
||||
ResourceID string
|
||||
Outcome string
|
||||
Detail any
|
||||
}
|
||||
|
||||
// Module serves one organisation's settings.
|
||||
type Module struct {
|
||||
orgID string
|
||||
@@ -294,6 +306,7 @@ type Module struct {
|
||||
oidc *oidcLogin
|
||||
setup *SetupSignal
|
||||
channels ChannelLinks
|
||||
audit func(context.Context, AuditRecord)
|
||||
// workflows reports the saved workflows that name a model alias.
|
||||
workflows WorkflowAliases
|
||||
|
||||
@@ -320,6 +333,15 @@ func (m *Module) UseSealer(s *seal.Sealer) { m.sealer = s }
|
||||
// writes are checked against.
|
||||
func (m *Module) UseAuthorizer(a Authorizer) { m.authorizer.Store(&a) }
|
||||
|
||||
// UseAudit registers a callback that receives security and policy audit events.
|
||||
func (m *Module) UseAudit(fn func(context.Context, AuditRecord)) { m.audit = fn }
|
||||
|
||||
func (m *Module) recordAudit(ctx context.Context, r AuditRecord) {
|
||||
if m != nil && m.audit != nil {
|
||||
m.audit(ctx, r)
|
||||
}
|
||||
}
|
||||
|
||||
// authz returns the policy chain, or nil before UseAuthorizer.
|
||||
func (m *Module) authz() Authorizer {
|
||||
if a := m.authorizer.Load(); a != nil {
|
||||
|
||||
@@ -97,7 +97,16 @@ func (m *Module) PutPolicy(ctx context.Context, p Policy) (int64, error) {
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return m.store.PutAccessPolicy(ctx, policyToRow(p))
|
||||
ver, err := m.store.PutAccessPolicy(ctx, policyToRow(p))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
m.recordAudit(ctx, AuditRecord{
|
||||
Category: "policy", Action: "policy.access.update", ActorID: CallerID(ctx),
|
||||
ResourceKind: "access_policy", ResourceID: p.ID, Outcome: "success",
|
||||
Detail: map[string]any{"level": p.Level, "version": ver},
|
||||
})
|
||||
return ver, nil
|
||||
}
|
||||
|
||||
// DeletePolicy removes one stored policy after verifying no org is locked out.
|
||||
@@ -121,6 +130,11 @@ func (m *Module) DeletePolicy(ctx context.Context, p Policy) error {
|
||||
if !found {
|
||||
return ErrPolicyNotFound
|
||||
}
|
||||
m.recordAudit(ctx, AuditRecord{
|
||||
Category: "policy", Action: "policy.access.delete", ActorID: CallerID(ctx),
|
||||
ResourceKind: "access_policy", ResourceID: p.ID, Outcome: "success",
|
||||
Detail: map[string]any{"level": p.Level},
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -445,7 +445,7 @@ func (m *Module) SignInAccount(ctx context.Context, email, password string) (Acc
|
||||
now := time.Now().UTC()
|
||||
token := rand.Text()
|
||||
expires := sessionExpiry(now, settings.SessionMaxLifetimeS)
|
||||
var breakGlassID string
|
||||
var breakGlassID, refusedID string
|
||||
row, err := m.store.SignInAccount(ctx, email, sessionHash(token), expires, func(hash string) bool {
|
||||
if hash == "" {
|
||||
_, _ = HashPassword("unknown account dummy password")
|
||||
@@ -455,6 +455,7 @@ func (m *Module) SignInAccount(ctx context.Context, email, password string) (Acc
|
||||
}, func(identityID string, isOrgOwner bool) error {
|
||||
breakGlass, err := allowPasswordSignIn(settings.SSOOnly, isOrgOwner)
|
||||
if err != nil {
|
||||
refusedID = identityID
|
||||
m.log.WarnContext(ctx, "password sign-in refused: sso_only enabled", "audit", true, "identity", identityID)
|
||||
return err
|
||||
}
|
||||
@@ -464,10 +465,26 @@ func (m *Module) SignInAccount(ctx context.Context, email, password string) (Acc
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
if refusedID != "" {
|
||||
m.recordAudit(ctx, AuditRecord{
|
||||
Category: "auth", Action: "auth.password.login", ActorID: refusedID, ActorKind: "user",
|
||||
ResourceKind: "identity", ResourceID: refusedID, Outcome: "denied",
|
||||
Detail: map[string]any{"reason": "sso_only"},
|
||||
})
|
||||
}
|
||||
return AccountSession{}, mapIdentityErr(err)
|
||||
}
|
||||
if breakGlassID != "" {
|
||||
m.log.WarnContext(ctx, "break-glass local password sign-in used while sso_only is enabled", "audit", true, "identity", breakGlassID)
|
||||
m.recordAudit(ctx, AuditRecord{
|
||||
Category: "auth", Action: "auth.break_glass.login", ActorID: breakGlassID, ActorKind: "user",
|
||||
ResourceKind: "identity", ResourceID: breakGlassID, Outcome: "success",
|
||||
})
|
||||
} else {
|
||||
m.recordAudit(ctx, AuditRecord{
|
||||
Category: "auth", Action: "auth.password.login", ActorID: row.ID, ActorKind: "user",
|
||||
ResourceKind: "identity", ResourceID: row.ID, Outcome: "success",
|
||||
})
|
||||
}
|
||||
return AccountSession{Identity: identityFromRow(row), Token: token, Expires: expires}, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user