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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4d3bdab14c
Коммит
8f44fbf89c
@@ -164,7 +164,7 @@ func createGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec := c.MakeAuditRecord("createGroup", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("group", group)
|
||||
auditRec.AddEventParameter("group", group)
|
||||
|
||||
newGroup, err := c.App.CreateGroupWithUserIds(group)
|
||||
if err != nil {
|
||||
@@ -172,7 +172,8 @@ func createGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.AddMeta("group", newGroup)
|
||||
auditRec.AddEventResultState(newGroup)
|
||||
auditRec.AddEventObjectType("group")
|
||||
js, jsonErr := json.Marshal(newGroup)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("createGroup", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
@@ -225,7 +226,7 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec := c.MakeAuditRecord("patchGroup", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("group", group)
|
||||
auditRec.AddEventParameter("group", group)
|
||||
|
||||
if groupPatch.AllowReference != nil && *groupPatch.AllowReference {
|
||||
if groupPatch.Name == nil {
|
||||
@@ -261,7 +262,8 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
auditRec.AddMeta("patch", group)
|
||||
auditRec.AddEventResultState(group)
|
||||
auditRec.AddEventObjectType("group")
|
||||
|
||||
b, marshalErr := json.Marshal(group)
|
||||
if marshalErr != nil {
|
||||
@@ -310,9 +312,9 @@ func linkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec := c.MakeAuditRecord("linkGroupSyncable", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("group_id", c.Params.GroupId)
|
||||
auditRec.AddMeta("syncable_id", syncableID)
|
||||
auditRec.AddMeta("syncable_type", syncableType)
|
||||
auditRec.AddEventParameter("group_id", c.Params.GroupId)
|
||||
auditRec.AddEventParameter("syncable_id", syncableID)
|
||||
auditRec.AddEventParameter("syncable_type", syncableType)
|
||||
|
||||
var patch *model.GroupSyncablePatch
|
||||
err = json.Unmarshal(body, &patch)
|
||||
@@ -321,6 +323,8 @@ func linkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.AddEventParameter("patch", patch)
|
||||
|
||||
if !*c.App.Channels().License().Features.LDAPGroups {
|
||||
c.Err = model.NewAppError("Api4.createGroupSyncable", "api.ldap_groups.license_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
@@ -344,6 +348,9 @@ func linkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.AddEventResultState(groupSyncable)
|
||||
auditRec.AddEventObjectType("group_syncable")
|
||||
|
||||
c.App.Srv().Go(func() {
|
||||
c.App.SyncRolesAndMembership(c.AppContext, syncableID, syncableType, false)
|
||||
})
|
||||
@@ -465,9 +472,9 @@ func patchGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec := c.MakeAuditRecord("patchGroupSyncable", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("group_id", c.Params.GroupId)
|
||||
auditRec.AddMeta("old_syncable_id", syncableID)
|
||||
auditRec.AddMeta("old_syncable_type", syncableType)
|
||||
auditRec.AddEventParameter("group_id", c.Params.GroupId)
|
||||
auditRec.AddEventParameter("old_syncable_id", syncableID)
|
||||
auditRec.AddEventParameter("old_syncable_type", syncableType)
|
||||
|
||||
var patch *model.GroupSyncablePatch
|
||||
err = json.Unmarshal(body, &patch)
|
||||
@@ -476,6 +483,8 @@ func patchGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.AddEventParameter("patch", patch)
|
||||
|
||||
if !*c.App.Channels().License().Features.LDAPGroups {
|
||||
c.Err = model.NewAppError("Api4.patchGroupSyncable", "api.ldap_groups.license_error", nil, "",
|
||||
http.StatusNotImplemented)
|
||||
@@ -502,8 +511,8 @@ func patchGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.AddMeta("new_syncable_id", groupSyncable.SyncableId)
|
||||
auditRec.AddMeta("new_syncable_type", groupSyncable.Type)
|
||||
auditRec.AddEventResultState(groupSyncable)
|
||||
auditRec.AddEventObjectType("group_syncable")
|
||||
|
||||
c.App.Srv().Go(func() {
|
||||
c.App.SyncRolesAndMembership(c.AppContext, syncableID, syncableType, false)
|
||||
@@ -538,9 +547,9 @@ func unlinkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec := c.MakeAuditRecord("unlinkGroupSyncable", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("group_id", c.Params.GroupId)
|
||||
auditRec.AddMeta("syncable_id", syncableID)
|
||||
auditRec.AddMeta("syncable_type", syncableType)
|
||||
auditRec.AddEventParameter("group_id", c.Params.GroupId)
|
||||
auditRec.AddEventParameter("syncable_id", syncableID)
|
||||
auditRec.AddEventParameter("syncable_type", syncableType)
|
||||
|
||||
if !*c.App.Channels().License().Features.LDAPGroups {
|
||||
c.Err = model.NewAppError("Api4.unlinkGroupSyncable", "api.ldap_groups.license_error", nil, "", http.StatusNotImplemented)
|
||||
@@ -978,7 +987,7 @@ func deleteGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec := c.MakeAuditRecord("deleteGroup", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("group_id", c.Params.GroupId)
|
||||
auditRec.AddEventParameter("group_id", c.Params.GroupId)
|
||||
|
||||
_, err = c.App.DeleteGroup(c.Params.GroupId)
|
||||
if err != nil {
|
||||
@@ -1027,7 +1036,7 @@ func addGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec := c.MakeAuditRecord("addGroupMembers", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("addGroupMembers", newMembers)
|
||||
auditRec.AddEventParameter("addGroupMembers", newMembers)
|
||||
|
||||
members, err := c.App.UpsertGroupMembers(c.Params.GroupId, newMembers.UserIds)
|
||||
if err != nil {
|
||||
@@ -1080,7 +1089,7 @@ func deleteGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec := c.MakeAuditRecord("deleteGroupMembers", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("deleteGroupMembers", deleteBody)
|
||||
auditRec.AddEventParameter("deleteGroupMembers", deleteBody)
|
||||
|
||||
members, err := c.App.DeleteGroupMembers(c.Params.GroupId, deleteBody.UserIds)
|
||||
if err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user