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

open-horizon#4222 - CWE-732: Insecure Directory Permissions vulnerabi… #4231

Merged
merged 1 commit into from
Jan 31, 2025
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 cli/dev/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func DependenciesExists(directory string, okToCreate bool) (bool, error) {
return false, err
} else if !exists && okToCreate {
newDir := path.Join(directory, DEFAULT_DEPENDENCY_DIR)
if err := os.MkdirAll(newDir, 0755); err != nil {
if err := os.MkdirAll(newDir, 0o755); err != nil {
return false, errors.New(i18n.GetMessagePrinter().Sprintf("could not create dependency directory %v, error: %v", newDir, err))
}
} else if !exists {
Expand Down
6 changes: 3 additions & 3 deletions cli/dev/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func CreateWorkingDir(dir string) error {
// Create the working directory with the dependencies and pattern directories in one shot. If it already exists, just keep going.
newDepDir := path.Join(dir, DEFAULT_DEPENDENCY_DIR)
if _, err := os.Stat(newDepDir); os.IsNotExist(err) {
if err := os.MkdirAll(newDepDir, 0755); err != nil {
if err := os.MkdirAll(newDepDir, 0o755); err != nil {
return errors.New(msgPrinter.Sprintf("could not create directory %v, error: %v", newDepDir, err))
}
} else if err != nil {
Expand Down Expand Up @@ -399,7 +399,7 @@ func createEnvVarMap(agreementId string,
func createContainerWorker() (*container.ContainerWorker, error) {

workloadStorageDir := "/tmp/hzn"
if err := os.MkdirAll(workloadStorageDir, 0755); err != nil {
if err := os.MkdirAll(workloadStorageDir, 0o755); err != nil {
return nil, err
}

Expand All @@ -418,7 +418,7 @@ func createContainerWorker() (*container.ContainerWorker, error) {
}

// Create the folder for SSL certificates (under authentication path)
if err := os.MkdirAll(config.GetESSSSLClientCertPath(), 0755); err != nil {
if err := os.MkdirAll(config.GetESSSSLClientCertPath(), 0o755); err != nil {
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions clusterupgrade/cluster_install_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func createNMPStatusFile(workDir string, status string) error {

if _, err := os.Stat(workDir); os.IsNotExist(err) {
glog.Infof(cuwlog(fmt.Sprintf("Work dir %v does not exist, create it...", workDir)))
if err = os.MkdirAll(workDir, 755); err != nil {
if err = os.MkdirAll(workDir, 0o755); err != nil {
glog.Infof(cuwlog(fmt.Sprintf("Failed to create dir %v, err: %v", workDir, err)))
return err
}
Expand Down Expand Up @@ -421,7 +421,7 @@ func decompress(tarGZFilePath, targetFolder string) error {

// create the target folder if it is not exist
if _, err := os.Stat(targetFolder); err != nil {
if err := os.MkdirAll(targetFolder, 0755); err != nil {
if err := os.MkdirAll(targetFolder, 0o755); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions exchange/css.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func GetObjectData(ec ExchangeContext, org string, objType string, objId string,
return fmt.Errorf("Failed to get object data : %v\n", err)
}

err = os.MkdirAll(filePath, 0755)
err = os.MkdirAll(filePath, 0o0755)
if err != nil {
return fmt.Errorf("Failed to create folder %v for agent upgrade files: %s\n", filePath, err)
}
Expand Down Expand Up @@ -370,7 +370,7 @@ func GetObjectDataByChunk(ec ExchangeContext, org string, objType string, objId
request.Close = true
}

err = os.MkdirAll(filePath, 0755)
err = os.MkdirAll(filePath, 0o755)
if err != nil {
return false, fmt.Errorf("Failed to create folder %v for agent upgrade files: %s\n", filePath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions imagefetch/image_process_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func init() {

func tConfig(t *testing.T, dir string) *config.HorizonConfig {
workloadStorageDir := path.Join(dir, "workload_storage")
if err := os.MkdirAll(workloadStorageDir, 0755); err != nil {
if err := os.MkdirAll(workloadStorageDir, 0o755); err != nil {
panic(err)
}

Expand Down Expand Up @@ -200,7 +200,7 @@ func setup(t *testing.T) (string, *bolt.DB, error) {
}

certpath := path.Join(dir, "userkeys")
if err := os.MkdirAll(certpath, 0755); err != nil {
if err := os.MkdirAll(certpath, 0o755); err != nil {
panic(err)
}

Expand Down
2 changes: 1 addition & 1 deletion policy/policy_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ func CreatePolicyFile(filepath string, org string, name string, p *Policy) (stri
// Store the policy on the filesystem in an org based hierarchy
fullFilePath := fmt.Sprintf("%v%v/", filepath, org)
fullFileName := fmt.Sprintf("%v%v.policy", fullFilePath, name)
if err := os.MkdirAll(fullFilePath, 0764); err != nil {
if err := os.MkdirAll(fullFilePath, 0o764); err != nil {
return "", errors.New(fmt.Sprintf("Error writing policy file, cannot create file path %v", fullFilePath))
} else if err := WritePolicyFile(p, fullFileName); err != nil {
return "", errors.New(fmt.Sprintf("Error writing out policy file %v, to %v, error: %v", *p, fullFileName, err))
Expand Down
2 changes: 1 addition & 1 deletion resource/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func CreateCertificate(org string, keyPath string, certPath string) error {

glog.V(5).Infof(reslog(fmt.Sprintf("creating self signed cert in %v", common.Configuration.ServerCertificate)))

if err := os.MkdirAll(certPath, 0755); err != nil {
if err := os.MkdirAll(certPath, 0o755); err != nil {
return errors.New(msgPrinter.Sprintf("unable to make directory for self signed MMS API certificate, error %v", err))
}

Expand Down
2 changes: 1 addition & 1 deletion resource/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r ResourceManager) setupFileSyncService(am *AuthenticationManager) error {
listenAddrPath := r.config.GetFileSyncServiceAPIUnixDomainSocketPath()
if listenAddrPath != "" {
if _, err := os.Stat(listenAddrPath); os.IsNotExist(err) {
os.MkdirAll(listenAddrPath, 0755)
os.MkdirAll(listenAddrPath, 0o755)
}
}

Expand Down