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

[Bug] Set file mode explicitly for regular files #1323

Merged
merged 2 commits into from
Dec 5, 2023
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
15 changes: 13 additions & 2 deletions internal/mode/static/nginx/file/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

const (
// regularFileMode defines the default file mode for regular files.
regularFileMode = 0o644
// secretFileMode defines the default file mode for files with secrets.
secretFileMode = 0o640
)
Expand Down Expand Up @@ -136,11 +138,20 @@ func writeFile(fileMgr OSFileManager, file File) error {
}
}()

if file.Type == TypeSecret {
switch file.Type {
case TypeRegular:
if err := fileMgr.Chmod(f, regularFileMode); err != nil {
resultErr = fmt.Errorf(
"failed to set file mode to %#o for %q: %w", regularFileMode, file.Path, err)
return resultErr
}
case TypeSecret:
if err := fileMgr.Chmod(f, secretFileMode); err != nil {
resultErr = fmt.Errorf("failed to set file mode for %q: %w", file.Path, err)
resultErr = fmt.Errorf("failed to set file mode to %#o for %q: %w", secretFileMode, file.Path, err)
return resultErr
}
default:
panic(fmt.Sprintf("unknown file type %d", file.Type))
}

if err := fileMgr.Write(f, file.Content); err != nil {
Expand Down
Loading