Skip to content

Commit

Permalink
restrict file permissions from "machines add" (#2648)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Dec 8, 2023
1 parent b1f8569 commit 84cbff1
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/capi.go
Expand Up @@ -106,7 +106,7 @@ func NewCapiRegisterCmd() *cobra.Command {
return fmt.Errorf("unable to marshal api credentials: %w", err)
}
if dumpFile != "" {
err = os.WriteFile(dumpFile, apiConfigDump, 0600)
err = os.WriteFile(dumpFile, apiConfigDump, 0o600)
if err != nil {
return fmt.Errorf("write api credentials in '%s' failed: %w", dumpFile, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/config_backup.go
Expand Up @@ -72,7 +72,7 @@ func backupHub(dirPath string) error {
if err != nil {
return fmt.Errorf("failed marshaling upstream parsers : %s", err)
}
err = os.WriteFile(upstreamParsersFname, upstreamParsersContent, 0644)
err = os.WriteFile(upstreamParsersFname, upstreamParsersContent, 0o644)
if err != nil {
return fmt.Errorf("unable to write to %s %s : %s", itemType, upstreamParsersFname, err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/console.go
Expand Up @@ -241,7 +241,7 @@ func dumpConsoleConfig(c *csconfig.LocalApiServerCfg) error {
log.Debugf("Empty console_path, defaulting to %s", c.ConsoleConfigPath)
}

if err := os.WriteFile(c.ConsoleConfigPath, out, 0600); err != nil {
if err := os.WriteFile(c.ConsoleConfigPath, out, 0o600); err != nil {
return fmt.Errorf("while dumping console config to %s: %w", c.ConsoleConfigPath, err)
}

Expand Down Expand Up @@ -282,7 +282,7 @@ func SetConsoleOpts(args []string, wanted bool) error {
return fmt.Errorf("cannot marshal credentials: %s", err)
}
log.Infof("Updating credentials file: %s", csConfig.API.Server.OnlineClient.CredentialsFilePath)
err = os.WriteFile(csConfig.API.Server.OnlineClient.CredentialsFilePath, fileContent, 0600)
err = os.WriteFile(csConfig.API.Server.OnlineClient.CredentialsFilePath, fileContent, 0o600)
if err != nil {
return fmt.Errorf("cannot write credentials file: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/machines.go
Expand Up @@ -332,7 +332,7 @@ func (cli cliMachines) add(cmd *cobra.Command, args []string) error {
return fmt.Errorf("unable to marshal api credentials: %s", err)
}
if dumpFile != "" && dumpFile != "-" {
err = os.WriteFile(dumpFile, apiConfigDump, 0644)
err = os.WriteFile(dumpFile, apiConfigDump, 0o600)
if err != nil {
return fmt.Errorf("write api credentials in '%s' failed: %s", dumpFile, err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/simulation.go
Expand Up @@ -48,7 +48,7 @@ func dumpSimulationFile() error {
if err != nil {
return fmt.Errorf("unable to marshal simulation configuration: %s", err)
}
err = os.WriteFile(csConfig.ConfigPaths.SimulationFilePath, newConfigSim, 0644)
err = os.WriteFile(csConfig.ConfigPaths.SimulationFilePath, newConfigSim, 0o644)
if err != nil {
return fmt.Errorf("write simulation config in '%s' failed: %s", csConfig.ConfigPaths.SimulationFilePath, err)
}
Expand All @@ -66,7 +66,7 @@ func disableGlobalSimulation() error {
if err != nil {
return fmt.Errorf("unable to marshal new simulation configuration: %s", err)
}
err = os.WriteFile(csConfig.ConfigPaths.SimulationFilePath, newConfigSim, 0644)
err = os.WriteFile(csConfig.ConfigPaths.SimulationFilePath, newConfigSim, 0o644)
if err != nil {
return fmt.Errorf("unable to write new simulation config in '%s' : %s", csConfig.ConfigPaths.SimulationFilePath, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/support.go
Expand Up @@ -423,7 +423,7 @@ cscli support dump -f /tmp/crowdsec-support.zip
log.Fatalf("could not finalize zip file: %s", err)
}

err = os.WriteFile(outFile, w.Bytes(), 0600)
err = os.WriteFile(outFile, w.Bytes(), 0o600)
if err != nil {
log.Fatalf("could not write zip file to %s: %s", outFile, err)
}
Expand Down

0 comments on commit 84cbff1

Please sign in to comment.