diff --git a/api4/config.go b/api4/config.go index 6148e00e44..cd009c46a1 100644 --- a/api4/config.go +++ b/api4/config.go @@ -152,6 +152,16 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) { *cfg.PluginSettings.MarketplaceURL = *appCfg.PluginSettings.MarketplaceURL } + // There are some settings that cannot be changed in a cloud env + if c.App.Channels().License() != nil && *c.App.Channels().License().Features.Cloud { + // Both of them cannot be nil since cfg.SetDefaults is called earlier for cfg, + // and appCfg is the existing earlier config and if it's nil, server sets a default value. + if *appCfg.ComplianceSettings.Directory != *cfg.ComplianceSettings.Directory { + c.Err = model.NewAppError("updateConfig", "api.config.update_config.not_allowed_security.app_error", map[string]interface{}{"Name": "ComplianceSettings.Directory"}, "", http.StatusForbidden) + return + } + } + c.App.HandleMessageExportConfig(cfg, appCfg) if err := cfg.IsValid(); err != nil { @@ -276,6 +286,14 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) { } } + // There are some settings that cannot be changed in a cloud env + if c.App.Channels().License() != nil && *c.App.Channels().License().Features.Cloud { + if cfg.ComplianceSettings.Directory != nil && *appCfg.ComplianceSettings.Directory != *cfg.ComplianceSettings.Directory { + c.Err = model.NewAppError("patchConfig", "api.config.update_config.not_allowed_security.app_error", map[string]interface{}{"Name": "ComplianceSettings.Directory"}, "", http.StatusForbidden) + return + } + } + if cfg.MessageExportSettings.EnableExport != nil { c.App.HandleMessageExportConfig(cfg, appCfg) } diff --git a/api4/config_test.go b/api4/config_test.go index 86007f7555..b1f59d1eb1 100644 --- a/api4/config_test.go +++ b/api4/config_test.go @@ -247,6 +247,18 @@ func TestUpdateConfig(t *testing.T) { assert.Equal(t, newURL, *cfg2.PluginSettings.MarketplaceURL) }) + t.Run("Should not be able to modify ComplianceSettings.Directory in cloud", func(t *testing.T) { + th.App.Srv().SetLicense(model.NewTestLicense("cloud")) + defer th.App.Srv().RemoveLicense() + + cfg2 := th.App.Config().Clone() + *cfg2.ComplianceSettings.Directory = "hellodir" + + _, resp, err = th.SystemAdminClient.UpdateConfig(cfg2) + require.Error(t, err) + CheckForbiddenStatus(t, resp) + }) + t.Run("System Admin should not be able to clear Site URL", func(t *testing.T) { siteURL := cfg.ServiceSettings.SiteURL defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.SiteURL = siteURL })