os.Chmod
GSC-G302Excessive permissions granted to a file/directory. This warning is triggered whenever permission greater than 0600 is granted.
Generally, all security rules follow the principle of least privilege, except when the file being created needs to be accessed by anyone other than the user creating it.
package main
import (
"fmt"
"os"
)
func main() {
err := os.Chmod("/tmp/somefile", 0777)
if err != nil {
fmt.Println("Error when changing file permissions!")
return
}
}
package main
import (
"fmt"
"os"
)
func main() {
err := os.Chmod("/tmp/mydir", 0400)
if err != nil {
fmt.Println("Error")
return
}
}