MM-22273 New auditing system (phase 1) (#13967)
* New auditing API outputting to syslog via TLS * New config section for specifying remote syslog server IP, port, and cert. * Legacy audit API retained for access history feature
Этот коммит содержится в:
@@ -6,6 +6,7 @@ package api4
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/audit"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
@@ -29,6 +30,11 @@ func createOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := c.MakeAuditRecord("createOAuthApp", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("oauth_app_name", oauthApp.Name)
|
||||
auditRec.AddMeta("oauth_app_desc", oauthApp.Description)
|
||||
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OAUTH)
|
||||
return
|
||||
@@ -46,7 +52,11 @@ func createOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
auditRec.AddMeta("oauth_app_id", rapp.Id)
|
||||
auditRec.AddMeta("client_id", rapp.Id)
|
||||
c.LogAudit("client_id=" + rapp.Id)
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
w.Write([]byte(rapp.ToJson()))
|
||||
}
|
||||
@@ -57,6 +67,11 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := c.MakeAuditRecord("updateOAuthApp", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("oauth_app_id", c.Params.AppId)
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OAUTH)
|
||||
return
|
||||
@@ -67,6 +82,7 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.SetInvalidParam("oauth_app")
|
||||
return
|
||||
}
|
||||
auditRec.AddMeta("oauth_app_name", oauthApp.Name)
|
||||
|
||||
// The app being updated in the payload must be the same one as indicated in the URL.
|
||||
if oauthApp.Id != c.Params.AppId {
|
||||
@@ -74,8 +90,6 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
oldOauthApp, err := c.App.GetOAuthApp(c.Params.AppId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
@@ -97,6 +111,7 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
c.LogAudit("success")
|
||||
|
||||
w.Write([]byte(updatedOauthApp.ToJson()))
|
||||
@@ -174,6 +189,9 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := c.MakeAuditRecord("deleteOAuthApp", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("oauth_app_id", c.Params.AppId)
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
@@ -186,6 +204,7 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
auditRec.AddMeta("oauth_app_name", oauthApp.Name)
|
||||
|
||||
if c.App.Session().UserId != oauthApp.CreatorId && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH)
|
||||
@@ -198,7 +217,9 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
c.LogAudit("success")
|
||||
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
@@ -208,6 +229,10 @@ func regenerateOAuthAppSecret(c *Context, w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := c.MakeAuditRecord("regenerateOAuthAppSecret", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("oauth_app_id", c.Params.AppId)
|
||||
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OAUTH)
|
||||
return
|
||||
@@ -218,6 +243,7 @@ func regenerateOAuthAppSecret(c *Context, w http.ResponseWriter, r *http.Request
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
auditRec.AddMeta("oauth_app_name", oauthApp.Name)
|
||||
|
||||
if oauthApp.CreatorId != c.App.Session().UserId && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH)
|
||||
@@ -230,7 +256,9 @@ func regenerateOAuthAppSecret(c *Context, w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
c.LogAudit("success")
|
||||
|
||||
w.Write([]byte(oauthApp.ToJson()))
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user