Skip to content

Fix G204: replace os/exec with utilexec to address command injection warnings#148

Open
bcho wants to merge 1 commit intomainfrom
fix/code-scanning-exec-injection
Open

Fix G204: replace os/exec with utilexec to address command injection warnings#148
bcho wants to merge 1 commit intomainfrom
fix/code-scanning-exec-injection

Conversation

@bcho
Copy link
Copy Markdown
Member

@bcho bcho commented Apr 17, 2026

Summary

  • Refactors pkg/status/collector.go and pkg/auth/auth.go to use k8s.io/utils/exec (utilexec) instead of os/exec directly, eliminating gosec G204 (subprocess launched with variable) findings.
  • Injects utilexec.Interface into Collector and AuthProvider structs, improving testability via dependency injection.

Resolves https://github.com/Azure/AKSFlexNode/security/code-scanning/101
Resolves https://github.com/Azure/AKSFlexNode/security/code-scanning/4

…warnings

Refactor pkg/status/collector.go and pkg/auth/auth.go to use the
k8s.io/utils/exec interface (utilexec) instead of os/exec directly.
This resolves code scanning alerts #4 and #101 (gosec G204) and
enables dependency injection for testability.

Resolves: code-scanning/4, code-scanning/101
Copilot AI review requested due to automatic review settings April 17, 2026 04:05
@bcho bcho deployed to e2e-testing April 17, 2026 04:05 — with GitHub Actions Active
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors command execution in the status collector and auth provider to use k8s.io/utils/exec (utilexec) instead of os/exec, aiming to eliminate gosec G204 findings and enable easier mocking via an injected exec interface.

Changes:

  • Added a utilexec.Interface field to status.Collector and auth.AuthProvider, defaulting to utilexec.New() in constructors.
  • Updated status command execution to call c.exec.CommandContext(...) instead of exec.CommandContext(...).
  • Updated Azure CLI invocation to use a.exec.CommandContext(...) and switched interactive stdio wiring to SetStdin/SetStdout/SetStderr.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/status/collector.go Introduces utilexec.Interface on Collector and routes runCommand through it.
pkg/auth/auth.go Introduces utilexec.Interface on AuthProvider and updates Azure CLI command creation + interactive stdio setup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/status/collector.go
Comment thread pkg/auth/auth.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants