Skip to content

Commit

Permalink
replace find subcommand with fs.WalkDir
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Robenolt <[email protected]>
  • Loading branch information
mattrobenolt committed Jan 30, 2025
1 parent 704c9e2 commit cee9409
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions go/test/endtoend/cluster/vttablet_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -721,12 +722,41 @@ func (vttablet *VttabletProcess) ConfirmDataDirHasNoGlobalPerms(t *testing.T) {
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)

var allowedFiles = []string{
path.Join("data", "client-cert.pem"),
path.Join("data", "public_key.pem"),
path.Join("data", "server-cert.pem"),
}

var matches []string
fsys := os.DirFS(datadir)
err := fs.WalkDir(fsys, ".", func(p string, d fs.DirEntry, _ error) error {
// first check if the file should be skipped
for _, name := range allowedFiles {
if strings.HasSuffix(p, name) {
return nil
}
}

info, err := d.Info()
if err != nil {
return err
}

// check if any global bit is on the filemode
if info.Mode()&0007 != 0 {
matches = append(matches, fmt.Sprintf(
"%s %s",
path.Join(datadir, p),
info.Mode(),
))
}
return nil
})

require.NoError(t, err, "Error walking directory")
require.Empty(t, matches, "Found files with global permissions: %s", strings.Join(matches, "\n"))
}

// VttabletProcessInstance returns a VttabletProcess handle for vttablet process
Expand Down

0 comments on commit cee9409

Please sign in to comment.