[MM-64686] Expose audit logging functionality via plugin API (#31204)

This commit exposes audit logging functionality to plugins via the plugin API, allowing plugins to create and log audit records. Additionally, it addresses a gob encoding issue that could cause plugin crashes when audit data contains nil pointers or unregistered types.
Этот коммит содержится в:
David Krauser
2025-06-25 20:37:32 -04:00
коммит произвёл GitHub
родитель efb960a160
Коммит aaa62a40ae
68 изменённых файлов: 878 добавлений и 750 удалений

Просмотреть файл

@@ -882,6 +882,62 @@ func (s *apiRPCServer) LogError(args *Z_LogErrorArgs, returns *Z_LogErrorReturns
return nil
}
type Z_LogAuditRecArgs struct {
A *model.AuditRecord
}
type Z_LogAuditRecReturns struct {
}
// Custom audit logging methods with gob safety checks
func (g *apiRPCClient) LogAuditRec(rec *model.AuditRecord) {
gobSafeRec := makeAuditRecordGobSafe(*rec)
_args := &Z_LogAuditRecArgs{&gobSafeRec}
_returns := &Z_LogAuditRecReturns{}
if err := g.client.Call("Plugin.LogAuditRec", _args, _returns); err != nil {
log.Printf("RPC call to LogAuditRec API failed: %s", err.Error())
}
}
func (s *apiRPCServer) LogAuditRec(args *Z_LogAuditRecArgs, returns *Z_LogAuditRecReturns) error {
if hook, ok := s.impl.(interface {
LogAuditRec(rec *model.AuditRecord)
}); ok {
hook.LogAuditRec(args.A)
} else {
return encodableError(fmt.Errorf("API LogAuditRec called but not implemented"))
}
return nil
}
type Z_LogAuditRecWithLevelArgs struct {
A *model.AuditRecord
B mlog.Level
}
type Z_LogAuditRecWithLevelReturns struct {
}
func (g *apiRPCClient) LogAuditRecWithLevel(rec *model.AuditRecord, level mlog.Level) {
gobSafeRec := makeAuditRecordGobSafe(*rec)
_args := &Z_LogAuditRecWithLevelArgs{&gobSafeRec, level}
_returns := &Z_LogAuditRecWithLevelReturns{}
if err := g.client.Call("Plugin.LogAuditRecWithLevel", _args, _returns); err != nil {
log.Printf("RPC call to LogAuditRecWithLevel API failed: %s", err.Error())
}
}
func (s *apiRPCServer) LogAuditRecWithLevel(args *Z_LogAuditRecWithLevelArgs, returns *Z_LogAuditRecWithLevelReturns) error {
if hook, ok := s.impl.(interface {
LogAuditRecWithLevel(rec *model.AuditRecord, level mlog.Level)
}); ok {
hook.LogAuditRecWithLevel(args.A, args.B)
} else {
return encodableError(fmt.Errorf("API LogAuditRecWithLevel called but not implemented"))
}
return nil
}
type Z_InstallPluginArgs struct {
PluginStreamID uint32
B bool