Skip to content

Commit c6afa59

Browse files
author
weiliu2
committed
add lint fix
1 parent 9369be3 commit c6afa59

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

pkg/privatecluster/tool_installer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (t *ToolInstaller) InstallKubelogin(ctx context.Context) error {
5959
if _, err := utils.RunCommandWithOutputContext(ctx, "cp", binaryPath, "/usr/local/bin/kubelogin"); err != nil {
6060
return fmt.Errorf("failed to install kubelogin: %w", err)
6161
}
62-
_ = os.Chmod("/usr/local/bin/kubelogin", 0755)
62+
_ = os.Chmod("/usr/local/bin/kubelogin", 0755) // #nosec G302 -- binary must be executable
6363

6464
t.logger.Infof("kubelogin v%s installed", kubeloginVersion)
6565
return nil
@@ -79,7 +79,7 @@ func (t *ToolInstaller) InstallKubectl(ctx context.Context, kubernetesVersion st
7979
if _, err := utils.RunCommandWithOutputContext(ctx, "curl", "-L", "-o", "/usr/local/bin/kubectl", url); err != nil {
8080
return fmt.Errorf("failed to download kubectl: %w", err)
8181
}
82-
_ = os.Chmod("/usr/local/bin/kubectl", 0755)
82+
_ = os.Chmod("/usr/local/bin/kubectl", 0755) // #nosec G302 -- binary must be executable
8383

8484
t.logger.Infof("kubectl v%s installed", kubernetesVersion)
8585
return nil

pkg/privatecluster/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func ReadFileContent(path string) (string, error) {
5555

5656
// WriteFileContent writes content to a file with specified permissions.
5757
func WriteFileContent(path, content string, perm os.FileMode) error {
58-
return os.WriteFile(path, []byte(content), perm) // #nosec G306 -- perm is from trusted internal code
58+
return os.WriteFile(path, []byte(content), perm) // #nosec G306 G703 -- perm and path are from trusted internal code
5959
}
6060

6161
// AddHostsEntry adds an entry to /etc/hosts if it doesn't exist.
@@ -125,7 +125,7 @@ func FixSSHKeyOwnership(keyPath string) error {
125125

126126
for _, path := range []string{keyPath, keyPath + ".pub"} {
127127
if utils.FileExists(path) {
128-
cmd := exec.Command("chown", fmt.Sprintf("%s:%s", u.Uid, u.Gid), path) // #nosec G204 -- chown with uid/gid
128+
cmd := exec.Command("chown", fmt.Sprintf("%s:%s", u.Uid, u.Gid), path) // #nosec G204 G702 -- chown with uid/gid from user.Lookup
129129
if err := cmd.Run(); err != nil {
130130
return fmt.Errorf("failed to change ownership of %s: %w", path, err)
131131
}

pkg/utils/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ func RunCommandWithOutput(name string, args ...string) (string, error) {
3434

3535
// RunCommandWithOutputContext executes a command with context and returns its combined output.
3636
func RunCommandWithOutputContext(ctx context.Context, name string, args ...string) (string, error) {
37-
cmd := exec.CommandContext(ctx, name, args...)
37+
cmd := exec.CommandContext(ctx, name, args...) // #nosec G204 -- same pattern as RunCommandWithOutput
3838
output, err := cmd.CombinedOutput()
3939
return string(output), err
4040
}
4141

4242
// RunCommandSilentContext executes a command with context and returns only whether it succeeded.
4343
func RunCommandSilentContext(ctx context.Context, name string, args ...string) bool {
44-
cmd := exec.CommandContext(ctx, name, args...)
44+
cmd := exec.CommandContext(ctx, name, args...) // #nosec G204 -- same pattern as RunSystemCommand
4545
return cmd.Run() == nil
4646
}
4747

0 commit comments

Comments
 (0)