[MM-55296] Added warning in Workspace dashboard if Mattermost is running as root (#27999)
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"runtime"
|
||||
@@ -144,7 +145,7 @@ func generateSupportPacket(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
reqs := c.App.Config().ClientRequirements
|
||||
|
||||
s := make(map[string]string)
|
||||
s := make(map[string]any)
|
||||
s[model.STATUS] = model.StatusOk
|
||||
s["AndroidLatestVersion"] = reqs.AndroidLatestVersion
|
||||
s["AndroidMinVersion"] = reqs.AndroidMinVersion
|
||||
@@ -196,9 +197,20 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
s[model.STATUS] = model.StatusUnhealthy
|
||||
}
|
||||
|
||||
w.Header().Set(model.STATUS, s[model.STATUS])
|
||||
w.Header().Set(dbStatusKey, s[dbStatusKey])
|
||||
w.Header().Set(filestoreStatusKey, s[filestoreStatusKey])
|
||||
if res, ok := s[model.STATUS].(string); ok {
|
||||
w.Header().Set(model.STATUS, res)
|
||||
}
|
||||
if res, ok := s[dbStatusKey].(string); ok {
|
||||
w.Header().Set(dbStatusKey, res)
|
||||
}
|
||||
if res, ok := s[filestoreStatusKey].(string); ok {
|
||||
w.Header().Set(filestoreStatusKey, res)
|
||||
}
|
||||
|
||||
// Checking if mattermost is running as root, if the user is system admin
|
||||
if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageSystem) {
|
||||
s["root_status"] = os.Geteuid() == 0
|
||||
}
|
||||
}
|
||||
|
||||
if deviceID := r.FormValue("device_id"); deviceID != "" {
|
||||
@@ -210,7 +222,8 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if s[model.STATUS] != model.StatusOk && r.FormValue("use_rest_semantics") != "true" {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
w.Write([]byte(model.MapToJSON(s)))
|
||||
|
||||
w.Write(model.ToJSON(s))
|
||||
}
|
||||
|
||||
func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -61,34 +61,46 @@ func TestGetPing(t *testing.T) {
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
th.App.ReloadConfig()
|
||||
resp, err := client.DoAPIGet(context.Background(), "/system/ping", "")
|
||||
respMap, resp, err := client.GetPingWithOptions(context.Background(), model.SystemPingOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
respBytes, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
respString := string(respBytes)
|
||||
require.NotContains(t, respString, "TestFeatureFlag")
|
||||
_, ok := respMap["TestFeatureFlag"]
|
||||
assert.Equal(t, false, ok)
|
||||
|
||||
// Run the environment variable override code to test
|
||||
os.Setenv("MM_FEATUREFLAGS_TESTFEATURE", "testvalueunique")
|
||||
defer os.Unsetenv("MM_FEATUREFLAGS_TESTFEATURE")
|
||||
th.App.ReloadConfig()
|
||||
|
||||
resp, err = client.DoAPIGet(context.Background(), "/system/ping", "")
|
||||
respMap, resp, err = client.GetPingWithOptions(context.Background(), model.SystemPingOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
respBytes, err = io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
respString = string(respBytes)
|
||||
require.Contains(t, respString, "testvalue")
|
||||
_, ok = respMap["TestFeatureFlag"]
|
||||
assert.Equal(t, true, ok)
|
||||
}, "ping feature flag test")
|
||||
|
||||
t.Run("ping root_status test", func(t *testing.T) {
|
||||
respMap, resp, err := th.SystemAdminClient.GetPingWithOptions(context.Background(), model.SystemPingOptions{FullStatus: true})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
_, ok := respMap["root_status"]
|
||||
assert.Equal(t, true, ok)
|
||||
})
|
||||
|
||||
t.Run("ping root_status test with client user", func(t *testing.T) {
|
||||
respMap, resp, err := th.Client.GetPingWithOptions(context.Background(), model.SystemPingOptions{FullStatus: true})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
_, ok := respMap["root_status"]
|
||||
assert.Equal(t, false, ok)
|
||||
})
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
th.App.ReloadConfig()
|
||||
resp, err := client.DoAPIGet(context.Background(), "/system/ping?device_id=platform:id", "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
var respMap map[string]string
|
||||
var respMap map[string]any
|
||||
err = json.NewDecoder(resp.Body).Decode(&respMap)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "unknown", respMap["CanReceiveNotifications"]) // Unrecognized platform
|
||||
|
||||
Ссылка в новой задаче
Block a user