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

file permissions for creating files should be constants and consistent #2152

Closed
bdw617 opened this issue Nov 17, 2023 · 1 comment
Closed
Labels
tech-debt 💳 Debt that the team has charged and needs to repay

Comments

@bdw617
Copy link
Contributor

bdw617 commented Nov 17, 2023

Describe what should be investigated or refactored

os.WriteFile() is called with various permission masks, should standardize them with a constant

here's the output from `go sec ./...`
[/zarf/src/pkg/packager/common.go:378] - G306 (CWE-276): Expect WriteFile permissions to be 0600 or less (Confidence: HIGH, Severity: MEDIUM)
    377:                        message.Debug(status)
  > 378:                        if err := os.WriteFile(path, chunk, 0644); err != nil {
    379:                                return fmt.Errorf("unable to write the file %s: %w", path, err)

Here are examples of the inconsistencies:
we're using at least 0640, 0600, 0644
unclear if we ever need to get group or other access.

os.MkdirAll() os.Mkdir() os.Chmod() should all be consistent.

➜  zarf git:(main) ✗ find . -name "*.go" | xargs grep os.WriteFile
./src/cmd/prepare.go:                   err = os.WriteFile(fileName, []byte(processedText), 0640)
./src/cmd/tools/zarf.go:                if err := os.WriteFile("tls.ca", pki.CA, 0644); err != nil {
./src/cmd/tools/zarf.go:                if err := os.WriteFile("tls.crt", pki.Cert, 0644); err != nil {
./src/cmd/tools/zarf.go:                if err := os.WriteFile("tls.key", pki.Key, 0600); err != nil {
./src/cmd/tools/zarf.go:                if err := os.WriteFile(prvKeyFileName, keyBytes.PrivateBytes, 0600); err != nil {
./src/cmd/tools/zarf.go:                if err := os.WriteFile(pubKeyFileName, keyBytes.PublicBytes, 0644); err != nil {
./src/pkg/packager/common.go:                   if err := os.WriteFile(path, chunk, 0644); err != nil {
./src/pkg/utils/io.go:  return os.WriteFile(path, []byte(text), 0600)
./src/pkg/utils/image.go:       return os.WriteFile(indexPath, indexJSONBytes, 0600)
./src/pkg/utils/json.go:        return os.WriteFile(path, data, 0644)
./src/pkg/utils/yaml.go:        return os.WriteFile(path, content, perm)
@bdw617 bdw617 added the tech-debt 💳 Debt that the team has charged and needs to repay label Nov 17, 2023
@Noxsios
Copy link
Contributor

Noxsios commented Mar 8, 2024

Fixed in #2235 by src/pkg/utils/helpers/io.go

@Noxsios Noxsios closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tech-debt 💳 Debt that the team has charged and needs to repay
Projects
Status: Done
Status: Closed
Development

No branches or pull requests

2 participants