From f000a183fc00114982fd69078305c4106a1afcc9 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Fri, 13 Feb 2026 04:39:35 -0500 Subject: [PATCH] MM-67335 Fix export files having mismatched permissions (#35182) (10.11) (#35248) Automatic Merge --- server/cmd/mmctl/commands/export.go | 9 +++++++-- server/cmd/mmctl/commands/export_e2e_test.go | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/server/cmd/mmctl/commands/export.go b/server/cmd/mmctl/commands/export.go index 53282692d4..9c0c70a379 100644 --- a/server/cmd/mmctl/commands/export.go +++ b/server/cmd/mmctl/commands/export.go @@ -257,9 +257,14 @@ func downloadFile(path string, downloadFn func(*os.File) (string, error), retrie return "", fmt.Errorf("%s file already exists", fileType) case err != nil: // file does not exist, we create it - outFile, err = os.Create(path) + outFile, err = os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0600) default: - // no error, file exists, we open it + // no error, file exists, we double check the permissions and then open it + permErr := os.Chmod(path, 0600) + if permErr != nil { + return "", fmt.Errorf("failed to change permissions on output file: %w", permErr) + } + outFile, err = os.OpenFile(path, os.O_WRONLY, 0600) } diff --git a/server/cmd/mmctl/commands/export_e2e_test.go b/server/cmd/mmctl/commands/export_e2e_test.go index 67a2ad4b21..8cf5be3b12 100644 --- a/server/cmd/mmctl/commands/export_e2e_test.go +++ b/server/cmd/mmctl/commands/export_e2e_test.go @@ -5,6 +5,7 @@ package commands import ( "fmt" + "io/fs" "os" "path/filepath" "strings" @@ -256,6 +257,10 @@ func (s *MmctlE2ETestSuite) TestExportDownloadCmdF() { s.Require().Len(printer.GetLines(), 1) s.Require().True(strings.HasPrefix(printer.GetLines()[0].(string), "Export file downloaded to ")) s.Require().Empty(printer.GetErrorLines()) + + info, err := os.Stat(downloadPath) + s.Require().Nil(err) + s.Require().Equal(fs.FileMode(0600), info.Mode().Perm(), fmt.Sprintf("expected %o, got %o", fs.FileMode(0600), info.Mode().Perm())) }) s.RunForSystemAdminAndLocal("MM-T3842 - full download", func(c client.Client) { @@ -285,6 +290,10 @@ func (s *MmctlE2ETestSuite) TestExportDownloadCmdF() { s.Require().Nil(err) s.Require().Equal(expected, actual) + + info, err := os.Stat(downloadPath) + s.Require().Nil(err) + s.Require().Equal(fs.FileMode(0600), info.Mode().Perm(), fmt.Sprintf("expected %o, got %o", fs.FileMode(0600), info.Mode().Perm())) }) }