Files
team/server/channels/app/support_packet.go
9ed85b6850 Cherry-pick Go 1.25.8 upgrade and FIPS password fixes to release-11.4 (#36123)
* ci: shard server Postgres tests into 4 parallel runners (#35739)

Cherry-pick of 00296f9b49 from master.

* updated go to version 1.25.8 (#35817)

Cherry-pick of 32a10bac62 from master.

* Move password hashers from server/v8 to server/public (#35805)

Cherry-pick of cca3f08574 from master.

* Generate instead of hard-coding test passwords, enforce new minimum for FIPS, shard CI, fix FIPS builds (#35905)

Cherry-pick of 1bdd985b41 from master.

* upgrade golangci-lint (#35845)

Cherry-pick of 157e0400b2 from master.

On release-11.4 (unlike 11.5), UpdatePostsChannelTypeByChannelId and
BackfillPostsChannelType exist in the elasticsearch/opensearch files,
so the imports they require (fmt, updatebyquery, scriptlanguage) must
be added — they were not in the cherry-pick diff since they already
existed on master.

Also updates html2text/tablewriter/olekukonko deps to fix a workspace
conflict where enterprise's Go 1.25.8 bump pulled in a newer html2text
that requires tablewriter ≥ 1.1 (was pinned to 0.0.5 via a replace
directive). Matches the subset of 866f759e4b (Mm 66662 bump deps)
relevant to this incompatibility.

* Fix FIPS-incompatible passwords and config in e2e test suites (#36001)

Cherry-pick of b51b4a8937 from master.

release-11.4 differences vs release-11.5:
- demo_plugin_installation.spec.ts also deleted (modify/delete conflict, git rm)
- authentication_2_spec.ts conflict: HEAD missing check() call; took
  incoming (check + FIPS-length passwords)
- member_invitation_ui_spec.ts: HEAD has 'Create Account' (capital A)
  matching release-11.4 button text; kept HEAD's button text with
  incoming's newTestPassword()

* fix(cypress): demo plugin (#36056)

Cherry-pick of 39f1979aa5 from master.

demo_plugin_installation.spec.ts was deleted in step 10 (modify/delete);
re-created here with both the FIPS-password change and the URL fix.

* test: clean up channel store data after TestChannelStore (#36066)

TestChannelStore sub-tests create channels, members, and team members
using fake TeamIds and UserIds (model.NewId() for non-existent rows).
These records are left in the database and cause integrity tests
(TestCheck*) running in the same binary to fail their full-table scans.

Register a t.Cleanup on TestChannelStore that purges the affected
tables entirely. A blanket purge is safe: the schema enforces no FK
constraints, and every test suite creates its own data independently.

* Fix command injection in server-test-template workflow (#36080)

Cherry-pick of 9223935f16 from master.

* fix(ci): restore testname format in sharded gotestsum runs (#36078)

run-shard-tests.sh called gotestsum directly without --format, so it
fell back to gotestsum's default (pkgname) instead of the testname
format set by the Makefile. Pass --format "${GOTESTSUM_FORMAT:-testname}"
to match the Makefile default.

Co-authored-by: Mattermost Build <[email protected]>

* fixup: drop demo_plugin playwright specs — master-only APIs

demo_plugin/helpers.ts and demo_plugin_installation.spec.ts use
installAndEnablePlugin and isPluginActive which don't exist on
release-11.4's PlaywrightExtended type. These files were re-created
by the step-11 cherry-pick of 39f1979aa5, but they don't compile on
this branch (same class of problem as actions.spec.ts in step 10).

* fixup: add missing await in PluginLinkTooltip test

The test added in 39f1979aa5 is missing an await on renderWithContext,
causing the pointer-events assertion to race. Fix from 0c7d3f27c6
(on a feature branch, not yet on master).

* fixup: drop pointer-events test incompatible with jsdom@20

The 'should not block interaction with elements outside the tooltip' test
checks getComputedStyle for pointer-events: none, which is set only in SCSS.
release-11.4 uses jest-environment-jsdom@29 (jsdom@20), which does not apply
stylesheets, so getComputedStyle always returns "". The test passes on
release-11.5+ only because they use jest-environment-jsdom@30 (jsdom@25+).

Drop the test rather than backport the jsdom upgrade.

* fixup: add missing i18n keys for elasticsearch/opensearch functions

BackfillPostsChannelType and UpdatePostsChannelTypeByChannelId exist on
release-11.4 (unlike release-11.5+). The golangci-lint cherry-pick added
new error strings to those functions referencing i18n keys that weren't
in en.json.

* fixup: run make i18n-extract to reorder keys correctly

* fixup: drop terms-and-privacy checkbox from MM-T1774 on release-11.4

The #signup-body-card-form-check-terms-and-privacy element did not exist
on release-11.4's signup page. It was added to master after this branch
was cut, so the check() call from the incoming cherry-pick causes the test
to fail with "element never found".

* fixup: remove UpdatePostsChannelTypeByChannelId/BackfillPostsChannelType

These functions were introduced by MM-67540 (allow searching public channel
messages without channel membership), which never landed on release-11.4.
The golangci-lint cherry-pick only modernizes existing code; the rerere
resolution incorrectly added the full function bodies from master.

Remove both functions and their now-unused imports (fmt, updatebyquery,
scriptlanguage) from elasticsearch.go and opensearch.go. Also remove the
two i18n keys added to support them.

Same treatment as release-11.5, where these functions were also absent.

---------

Co-authored-by: Mattermost Build <[email protected]>
2026-04-16 12:10:03 -03:00

390 lines
12 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"encoding/json"
"path/filepath"
"slices"
"sync"
"github.com/goccy/go-yaml"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
)
func (a *App) GenerateSupportPacket(rctx request.CTX, options *model.SupportPacketOptions) []model.FileData {
functions := map[string]func(rctx request.CTX) (*model.FileData, error){
"metadata": a.getSupportPacketMetadata,
"stats": a.getSupportPacketStats,
"jobs": a.getSupportPacketJobList,
"permissions": a.getSupportPacketPermissionsInfo,
"plugins": a.getPluginsFile,
"schema": a.getSupportPacketDatabaseSchema,
}
var (
// If any errors we come across within this function, we will log it in a warning.txt file so that we know why certain files did not get produced if any
warnings *multierror.Error
// Creating an array of files that we are going to be adding to our zip file
fileDatas []model.FileData
wg sync.WaitGroup
mut sync.Mutex // Protects warnings and fileDatas
)
wg.Go(func() {
for name, fn := range functions {
fileData, err := fn(rctx)
mut.Lock()
if err != nil {
rctx.Logger().Error("Failed to generate file for Support Packet",
mlog.String("file", name),
mlog.Err(err),
)
warnings = multierror.Append(warnings, err)
}
if fileData != nil {
fileDatas = append(fileDatas, *fileData)
}
mut.Unlock()
}
// Generate platform support packet
files, err := a.Srv().Platform().GenerateSupportPacket(rctx, options)
mut.Lock()
if err != nil {
warnings = multierror.Append(warnings, err)
}
if fileDatas != nil {
if cluster := a.Cluster(); cluster != nil && *a.Config().ClusterSettings.Enable {
hostname := cluster.GetMyClusterInfo().Hostname
for _, file := range files {
// When running in a cluster, the files are generated with the cluster node name as the directory, e.g. 7917b92f9e4c/mattermost.log
fileDatas = append(fileDatas, model.FileData{
Filename: filepath.Join(hostname, file.Filename),
Body: file.Body,
})
}
} else {
// When running in standalone mode, all files are generated with the same directory name, e.g. mattermost.log.
fileDatas = append(fileDatas, files...)
}
}
mut.Unlock()
})
// Run the cluster generation in a separate goroutine as CPU profile generation and file upload can take a long time
if cluster := a.Cluster(); cluster != nil && *a.Config().ClusterSettings.Enable {
wg.Go(func() {
files, err := cluster.GenerateSupportPacket(rctx, options)
mut.Lock()
if err != nil {
rctx.Logger().Error("Failed to generate Support Packet from cluster nodes", mlog.Err(err))
warnings = multierror.Append(warnings, err)
}
for _, node := range files {
fileDatas = append(fileDatas, node...)
}
mut.Unlock()
})
}
wg.Wait()
pluginContext := pluginContext(rctx)
a.ch.RunMultiHook(func(hooks plugin.Hooks, manifest *model.Manifest) bool {
// If the plugin defined the support_packet prop it means there is a UI element to include it in the support packet.
// Check if the plugin is in the list of plugins to include in the Support Packet.
if _, ok := manifest.Props["support_packet"]; ok {
if !slices.Contains(options.PluginPackets, manifest.Id) {
return true
}
}
// Otherwise, just call the hook as the plugin decided to always include it in the Support Packet.
pluginData, err := hooks.GenerateSupportData(pluginContext)
if err != nil {
rctx.Logger().Warn("Failed to generate plugin file for Support Packet", mlog.String("plugin", manifest.Id), mlog.Err(err))
warnings = multierror.Append(warnings, err)
return true
}
for _, data := range pluginData {
fileDatas = append(fileDatas, *data)
}
return true
}, plugin.GenerateSupportDataID)
// Adding a warning.txt file to the fileDatas if any warning
if warnings != nil {
fileDatas = append(fileDatas, model.FileData{
Filename: model.SupportPacketErrorFile,
Body: []byte(warnings.Error()),
})
}
return fileDatas
}
func (a *App) getSupportPacketStats(rctx request.CTX) (*model.FileData, error) {
var (
rErr *multierror.Error
err error
stats model.SupportPacketStats
)
stats.RegisteredUsers, err = a.Srv().Store().User().Count(model.UserCountOptions{IncludeDeleted: true})
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get registered user count"))
}
stats.ActiveUsers, err = a.Srv().Store().User().Count(model.UserCountOptions{})
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get active user count"))
}
stats.DailyActiveUsers, err = a.Srv().Store().User().AnalyticsActiveCount(DayMilliseconds, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get daily active user count"))
}
stats.MonthlyActiveUsers, err = a.Srv().Store().User().AnalyticsActiveCount(MonthMilliseconds, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get monthly active user count"))
}
stats.DeactivatedUsers, err = a.Srv().Store().User().AnalyticsGetInactiveUsersCount()
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get deactivated user count"))
}
stats.Guests, err = a.Srv().Store().User().AnalyticsGetGuestCount()
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get guest count"))
}
stats.BotAccounts, err = a.Srv().Store().User().Count(model.UserCountOptions{IncludeBotAccounts: true, ExcludeRegularUsers: true})
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get bot acount count"))
}
stats.Posts, err = a.Srv().Store().Post().AnalyticsPostCount(&model.PostCountOptions{})
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get post count"))
}
openChannels, err := a.Srv().Store().Channel().AnalyticsTypeCount("", model.ChannelTypeOpen)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get open channels count"))
}
privateChannels, err := a.Srv().Store().Channel().AnalyticsTypeCount("", model.ChannelTypePrivate)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get private channels count"))
}
stats.Channels = openChannels + privateChannels
stats.Teams, err = a.Srv().Store().Team().AnalyticsTeamCount(nil)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get team count"))
}
stats.SlashCommands, err = a.Srv().Store().Command().AnalyticsCommandCount("")
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get command count"))
}
stats.IncomingWebhooks, err = a.Srv().Store().Webhook().AnalyticsIncomingCount("", "")
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get incoming webhook count"))
}
stats.OutgoingWebhooks, err = a.Srv().Store().Webhook().AnalyticsOutgoingCount("")
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to get outgoing webhook count"))
}
b, err := yaml.Marshal(&stats)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to marshal Support Packet into yaml"))
}
fileData := &model.FileData{
Filename: "stats.yaml",
Body: b,
}
return fileData, rErr.ErrorOrNil()
}
func (a *App) getSupportPacketJobList(rctx request.CTX) (*model.FileData, error) {
const numberOfJobsRuns = 5
var (
rErr *multierror.Error
err error
jobs model.SupportPacketJobList
)
jobs.LDAPSyncJobs, err = a.Srv().Store().Job().GetAllByTypePage(rctx, model.JobTypeLdapSync, 0, numberOfJobsRuns)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting LDAP sync jobs"))
}
jobs.DataRetentionJobs, err = a.Srv().Store().Job().GetAllByTypePage(rctx, model.JobTypeDataRetention, 0, numberOfJobsRuns)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting data retention jobs"))
}
jobs.MessageExportJobs, err = a.Srv().Store().Job().GetAllByTypePage(rctx, model.JobTypeMessageExport, 0, numberOfJobsRuns)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting message export jobs"))
}
jobs.ElasticPostIndexingJobs, err = a.Srv().Store().Job().GetAllByTypePage(rctx, model.JobTypeElasticsearchPostIndexing, 0, numberOfJobsRuns)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting ES post indexing jobs"))
}
jobs.ElasticPostAggregationJobs, err = a.Srv().Store().Job().GetAllByTypePage(rctx, model.JobTypeElasticsearchPostAggregation, 0, numberOfJobsRuns)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting ES post aggregation jobs"))
}
jobs.MigrationJobs, err = a.Srv().Store().Job().GetAllByTypePage(rctx, model.JobTypeMigrations, 0, numberOfJobsRuns)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting migration jobs"))
}
b, err := yaml.Marshal(&jobs)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to marshal jobs list into yaml"))
}
fileData := &model.FileData{
Filename: "jobs.yaml",
Body: b,
}
return fileData, rErr.ErrorOrNil()
}
func (a *App) getSupportPacketPermissionsInfo(_ request.CTX) (*model.FileData, error) {
var (
rErr *multierror.Error
err error
permissions model.SupportPacketPermissionInfo
)
var allSchemes []*model.Scheme
perPage := 100
page := 0
for {
schemes, appErr := a.GetSchemesPage("", page, perPage)
if appErr != nil {
rErr = multierror.Append(errors.Wrap(appErr, "failed to get list of schemes"))
break
}
allSchemes = append(allSchemes, schemes...)
if len(schemes) < perPage {
break
}
page++
}
for _, s := range allSchemes {
s.Sanitize()
}
permissions.Schemes = allSchemes
roles, appErr := a.GetAllRoles()
if appErr != nil {
rErr = multierror.Append(errors.Wrap(appErr, "failed to get list of roles"))
}
for _, r := range roles {
r.Sanitize()
}
permissions.Roles = roles
b, err := yaml.Marshal(&permissions)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "failed to marshal permission info into yaml"))
}
fileData := &model.FileData{
Filename: "permissions.yaml",
Body: b,
}
return fileData, rErr.ErrorOrNil()
}
func (a *App) getPluginsFile(_ request.CTX) (*model.FileData, error) {
// Getting the plugins installed on the server, prettify it, and then add them to the file data array
plugins, appErr := a.GetPlugins()
if appErr != nil {
return nil, errors.Wrap(appErr, "failed to get plugin list for Support Packet")
}
var pluginList model.SupportPacketPluginList
for _, p := range plugins.Active {
pluginList.Enabled = append(pluginList.Enabled, p.Manifest)
}
for _, p := range plugins.Inactive {
pluginList.Disabled = append(pluginList.Disabled, p.Manifest)
}
pluginsPrettyJSON, err := json.MarshalIndent(pluginList, "", " ")
if err != nil {
return nil, errors.Wrap(err, "failed to marshal plugin list into json")
}
fileData := &model.FileData{
Filename: "plugins.json",
Body: pluginsPrettyJSON,
}
return fileData, nil
}
func (a *App) getSupportPacketMetadata(_ request.CTX) (*model.FileData, error) {
metadata, err := model.GeneratePacketMetadata(model.SupportPacketType, a.ServerId(), a.License(), nil)
if err != nil {
return nil, errors.Wrap(err, "failed to generate Packet metadata")
}
b, err := yaml.Marshal(metadata)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal Packet metadata into yaml")
}
fileData := &model.FileData{
Filename: model.PacketMetadataFileName,
Body: b,
}
return fileData, nil
}
func (a *App) getSupportPacketDatabaseSchema(rctx request.CTX) (*model.FileData, error) {
if *a.Config().SqlSettings.DriverName != model.DatabaseDriverPostgres {
return nil, nil
}
schemaInfo, err := a.Srv().Store().GetSchemaDefinition()
if err != nil {
return nil, errors.Wrap(err, "failed to get schema definition")
}
schemaDump, err := yaml.Marshal(schemaInfo)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal schema into YAML")
}
return &model.FileData{
Filename: "database_schema.yaml",
Body: schemaDump,
}, nil
}