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

Use minimum(user only) file permissions #453

Merged
merged 1 commit into from
Nov 28, 2022
Merged
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
10 changes: 5 additions & 5 deletions internal/osutil/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (

// WriteFile writes to a path with all parent directories created.
func WriteFile(path string, data []byte) error {
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
return err
}
return os.WriteFile(path, data, 0666)
return os.WriteFile(path, data, 0600)
}

// WriteFileWithPermission writes to a path with all parent directories created.
func WriteFileWithPermission(path string, data []byte, perm fs.FileMode, overwrite bool) error {
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
return err
}
flag := os.O_WRONLY | os.O_CREATE
Expand Down Expand Up @@ -56,7 +56,7 @@ func CopyToDir(src, dst string) (int64, error) {
}
defer source.Close()

if err := os.MkdirAll(dst, 0755); err != nil {
if err := os.MkdirAll(dst, 0700); err != nil {
return 0, err
}
certFile := filepath.Join(dst, filepath.Base(src))
Expand All @@ -65,7 +65,7 @@ func CopyToDir(src, dst string) (int64, error) {
return 0, err
}
defer destination.Close()
err = destination.Chmod(0644)
err = destination.Chmod(0600)
if err != nil {
return 0, err
}
Expand Down