Skip to content

Commit

Permalink
Add permissions check to Backup tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Jan 29, 2025
1 parent 7b2663b commit 87d6132
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ func TestBackup(t *testing.T, setupType int, streamMode string, stripes int, cDe
return vterrors.Errorf(vtrpc.Code_UNKNOWN, "test failure: %s", test.name)
}
}

t.Run("check for files created with global permissions", func(t *testing.T) {
t.Logf("Confirming that none of the MySQL data directories that we've created have files with global permissions")
for _, ks := range localCluster.Keyspaces {
for _, shard := range ks.Shards {
for _, tablet := range shard.Vttablets {
cluster.ConfirmDataDirHasNoGlobalPerms(t, tablet)
}
}
}
})

return nil
}

Expand Down
18 changes: 18 additions & 0 deletions go/test/endtoend/cluster/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package cluster

import (
"context"
"errors"
"fmt"
"os"
"os/exec"
"path"
"reflect"
"strings"
Expand Down Expand Up @@ -509,3 +511,19 @@ func PrintFiles(t *testing.T, dir string, files ...string) {
}
}
}

// ConfirmDataDirHasNoGlobalPerms confirms that no files in the tablet's data directory
// have any global/other permissions set.
func ConfirmDataDirHasNoGlobalPerms(t *testing.T, tablet *Vttablet) {
datadir := tablet.VttabletProcess.Directory
if _, err := os.Stat(datadir); errors.Is(err, os.ErrNotExist) {
t.Logf("Data directory %s no longer exists, skipping permissions check", datadir)
return
}
// List any files which have any of the other bits set.
cmd := exec.Command("find", datadir, "-perm", "+00007")
out, err := cmd.CombinedOutput()
require.NoError(t, err, "Error running find command: %s", string(out))
so := string(out)
require.Empty(t, so, "Found files with global permissions: %s", so)
}

0 comments on commit 87d6132

Please sign in to comment.