Audit logging -- convert audit logs to use the new schema (#20526)

* Audit logging - new schema added, old schema removed.

* fix linter error by running goimports

* Address review comments

* Address review comments

* Example usage of new audit logging API for the updateUserAuth call

* fixed unit test on auditing updating user record

* Changed the `TestUpdateConfigDiffInAuditRecord` testcase---it failed, because this PR changes how the `meta` field is serialized into the audit log records.

* fix linter error

* use string constants for record keys

* new audit api calls for api4/bot

* `Auditable` interface implementations for model classes

* New audit calls for channel api

* New audit calls for channel_local

* renamed receivers for required style reasons

* New audit calls for api4/command

* renamed receiver

* New audit calls for api4/command_local

* renamed receiver

* fix unit test to reflect changes in the Auditable implementation of the user class

* new audit calls for compliance

* new audit calls for configs

* remove auditRec.addMeta from updateConfig and patchConfig

* new audit calls for config_local

* new audit calls

* new audit calls for ldap, license apis

* new audit calls

* new audit calls

* new audit calls

* new audit calls

* new audit calls

* new audit calls

* new audit calls

* new audit calls

* fix linter error

* fixed linter error

* fixed "user update" test

* Don't include all of config when audit logging config changes. Also fix unit test on TestUpdateConfigDiffInAuditRecord

* address review comments

* Added Auditable() method for UserPatch

* Fix duplicative method declaration from merge

* Fix styling and API changes issues introduced with merge

* Fix broken test

Co-authored-by: Daniel Schalla <daniel@schalla.me>
Этот коммит содержится в:
Ossi Väänänen
2022-07-14 14:52:46 +03:00
коммит произвёл GitHub
родитель 4d3bdab14c
Коммит 8f44fbf89c
60 изменённых файлов: 885 добавлений и 275 удалений

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

@@ -42,6 +42,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec := c.MakeAuditRecord("createIncomingHook", audit.Fail)
defer c.LogAuditRec(auditRec)
auditRec.AddEventParameter("incoming_webhook", hook)
auditRec.AddMeta("channel", channel)
c.LogAudit("attempt")
@@ -79,7 +80,8 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
}
auditRec.Success()
auditRec.AddMeta("hook", incomingHook)
auditRec.AddEventResultState(incomingHook)
auditRec.AddEventObjectType("hook")
c.LogAudit("success")
w.WriteHeader(http.StatusCreated)
@@ -107,8 +109,9 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
}
auditRec := c.MakeAuditRecord("updateIncomingHook", audit.Fail)
auditRec.AddEventParameter("hook_id", c.Params.HookId)
auditRec.AddEventParameter("updated_hook", updatedHook)
defer c.LogAuditRec(auditRec)
auditRec.AddMeta("hook_id", c.Params.HookId)
c.LogAudit("attempt")
oldHook, err := c.App.GetIncomingWebhook(c.Params.HookId)
@@ -116,7 +119,8 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
c.Err = err
return
}
auditRec.AddMeta("team_id", oldHook.TeamId)
auditRec.AddEventPriorState(oldHook)
auditRec.AddEventObjectType("incoming_webhook")
if updatedHook.TeamId == "" {
updatedHook.TeamId = oldHook.TeamId
@@ -163,6 +167,7 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
auditRec.AddEventResultState(incomingHook)
auditRec.Success()
c.LogAudit("success")
@@ -238,6 +243,7 @@ func getIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec := c.MakeAuditRecord("getIncomingHook", audit.Fail)
defer c.LogAuditRec(auditRec)
auditRec.AddEventParameter("hook_id", c.Params.HookId)
auditRec.AddMeta("hook_id", hook.Id)
auditRec.AddMeta("hook_display", hook.DisplayName)
auditRec.AddMeta("channel_id", hook.ChannelId)
@@ -297,6 +303,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec := c.MakeAuditRecord("deleteIncomingHook", audit.Fail)
defer c.LogAuditRec(auditRec)
auditRec.AddEventParameter("hook_id", c.Params.HookId)
auditRec.AddMeta("hook_id", hook.Id)
auditRec.AddMeta("hook_display", hook.DisplayName)
auditRec.AddMeta("channel_id", channel.Id)
@@ -321,6 +328,8 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
auditRec.AddEventPriorState(hook)
auditRec.AddEventObjectType("incoming_webhook")
auditRec.Success()
ReturnStatusOK(w)
}
@@ -345,10 +354,7 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec := c.MakeAuditRecord("updateOutgoingHook", audit.Fail)
defer c.LogAuditRec(auditRec)
auditRec.AddMeta("hook_id", updatedHook.Id)
auditRec.AddMeta("hook_display", updatedHook.DisplayName)
auditRec.AddMeta("channel_id", updatedHook.ChannelId)
auditRec.AddMeta("team_id", updatedHook.TeamId)
auditRec.AddEventParameter("updated_hook", updatedHook)
c.LogAudit("attempt")
oldHook, err := c.App.GetOutgoingWebhook(c.Params.HookId)
@@ -401,8 +407,8 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
}
auditRec := c.MakeAuditRecord("createOutgoingHook", audit.Fail)
auditRec.AddEventParameter("hook", hook)
defer c.LogAuditRec(auditRec)
auditRec.AddMeta("hook_id", hook.Id)
c.LogAudit("attempt")
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), hook.TeamId, model.PermissionManageOutgoingWebhooks) {
@@ -434,9 +440,8 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
}
auditRec.Success()
auditRec.AddMeta("hook_display", rhook.DisplayName)
auditRec.AddMeta("channel_id", rhook.ChannelId)
auditRec.AddMeta("team_id", rhook.TeamId)
auditRec.AddEventResultState(rhook)
auditRec.AddEventObjectType("outgoing_webhook")
c.LogAudit("success")
w.WriteHeader(http.StatusCreated)
@@ -518,6 +523,7 @@ func getOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec := c.MakeAuditRecord("getOutgoingHook", audit.Fail)
defer c.LogAuditRec(auditRec)
auditRec.AddEventParameter("hook_id", c.Params.HookId)
auditRec.AddMeta("hook_id", hook.Id)
auditRec.AddMeta("hook_display", hook.DisplayName)
auditRec.AddMeta("channel_id", hook.ChannelId)
@@ -580,6 +586,8 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
return
}
auditRec.AddEventResultState(rhook)
auditRec.AddEventObjectType("outgoing_webhook")
auditRec.Success()
c.LogAudit("success")
@@ -602,6 +610,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec := c.MakeAuditRecord("deleteOutgoingHook", audit.Fail)
defer c.LogAuditRec(auditRec)
auditRec.AddEventParameter("hook_id", c.Params.HookId)
auditRec.AddMeta("hook_id", hook.Id)
auditRec.AddMeta("hook_display", hook.DisplayName)
auditRec.AddMeta("channel_id", hook.ChannelId)