Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli,log: change the default file permissions #44043

Merged
merged 3 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cli/haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func runGenHAProxyCmd(cmd *cobra.Command, args []string) error {
var f *os.File
if haProxyPath == "-" {
w = os.Stdout
} else if f, err = os.OpenFile(haProxyPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755); err != nil {
} else if f, err = os.OpenFile(haProxyPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
return err
} else {
w = f
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ select '''

for _, test := range tests {
// Populate the test input.
if f, err = os.OpenFile(fname, os.O_WRONLY, 0666); err != nil {
if f, err = os.OpenFile(fname, os.O_WRONLY, 0644); err != nil {
fmt.Fprintln(stderr, err)
return
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ func runStart(cmd *cobra.Command, args []string, disableReplication bool) error
return err
}

// Change the permission mask for all created files.
//
// We're considering everything produced by a cockroach node
// to potentially contain sensitive information, so it should
// not be world-readable.
disableOtherPermissionBits()

// TODO(knz): the following call is not in the right place.
// See: https://github.com/cockroachdb/cockroach/issues/44041
if s, err := serverCfg.Stores.GetPreventedStartupMessage(); err != nil {
return err
} else if s != "" {
Expand Down
6 changes: 6 additions & 0 deletions pkg/cli/start_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ func maybeRerunBackground() (bool, error) {
}
return false, nil
}

func disableOtherPermissionBits() {
mask := unix.Umask(0000)
mask |= 00007
_ = unix.Umask(mask)
}
4 changes: 4 additions & 0 deletions pkg/cli/start_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ func handleSignalDuringShutdown(os.Signal) {
func maybeRerunBackground() (bool, error) {
return false, nil
}

func disableOtherPermissionBits() {
// No-op on windows, which does not support umask.
}
2 changes: 1 addition & 1 deletion pkg/cli/systembench/disk_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func newTempFile(dir string) (*os.File, error) {
}

return os.OpenFile(tempFileName,
os.O_RDWR|os.O_APPEND, 0660)
os.O_RDWR|os.O_APPEND, 0640)
}

// Run runs I/O benchmarks specified by diskOpts.
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/log/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func create(
fname := filepath.Join(dir, name)
// Open the file os.O_APPEND|os.O_CREATE rather than use os.Create.
// Append is almost always more efficient than O_RDRW on most modern file systems.
f, err = os.OpenFile(fname, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
f, err = os.OpenFile(fname, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err == nil {
symlink := filepath.Join(dir, link)

Expand Down