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

fix: resolve all gosec issues #158

Merged
merged 2 commits into from
Dec 19, 2023
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 internal/sinks/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (s *AlertmanagerSink) Configure(c Client, config map[string][]byte) error {
}
caCertPool.AppendCertsFromPEM(caCert)
}

// #nosec G402
c.hclient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: insecureSkipVerify,
Expand Down
23 changes: 16 additions & 7 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *helmClient) exec(args []string) error {
sanitizedArgs := sb.String()

fmt.Println("helm " + sanitizedArgs)
cmd := exec.Command(c.helmPath, args...)
cmd := exec.Command(c.helmPath, args...) // #nosec G204
if c.stdout != nil {
cmd.Stdout = c.stdout
cmd.Stderr = c.stderr
Expand Down Expand Up @@ -142,12 +142,16 @@ func (c *helmClient) run(name, namespace string, options UpgradeOptions, command
// Write to temp file
_, err = tempFile.Write([]byte(options.Values))
if err != nil {
os.Remove(tempFile.Name())
if removeErr := os.Remove(tempFile.Name()); removeErr != nil {
klog.Errorf("failed to remove temp file %s: %v", tempFile.Name(), err)
}
return errors.Wrap(err, "write temp file")
}

// Close temp file
tempFile.Close()
if err := tempFile.Close(); err != nil {
return errors.Wrap(err, "close temp file")
}
defer os.Remove(tempFile.Name())

// Wait quickly so helm will find the file
Expand Down Expand Up @@ -215,12 +219,16 @@ func writeKubeConfig(configRaw *clientcmdapi.Config) (string, error) {
// Write to temp file
_, err = tempFile.Write(data)
if err != nil {
os.Remove(tempFile.Name())
if removeErr := os.Remove(tempFile.Name()); removeErr != nil {
klog.Errorf("failed to remove temp file %s: %v", tempFile.Name(), err)
}
return "", errors.Wrap(err, "write temp file")
}

// Close temp file
tempFile.Close()
if err := tempFile.Close(); err != nil {
return "", errors.Wrap(err, "close temp file")
}

// Okay sometimes the file is written so quickly that helm somehow
// cannot read it immediately which causes errors
Expand All @@ -233,8 +241,9 @@ func writeKubeConfig(configRaw *clientcmdapi.Config) (string, error) {
time.Sleep(time.Millisecond * 50)
continue
}

os.Remove(tempFile.Name())
if removeErr := os.Remove(tempFile.Name()); removeErr != nil {
klog.Errorf("failed to remove temp file %s: %v", tempFile.Name(), err)
}
return "", err
}
break
Expand Down
Loading