Skip to content

fix: restrict cmd template function for remote dependency configs#10026

Open
markoyoungson wants to merge 1 commit intoGoogleContainerTools:mainfrom
markoyoungson:fix/restrict-cmd-remote-configs
Open

fix: restrict cmd template function for remote dependency configs#10026
markoyoungson wants to merge 1 commit intoGoogleContainerTools:mainfrom
markoyoungson:fix/restrict-cmd-remote-configs

Conversation

@markoyoungson
Copy link
Copy Markdown

Summary

The cmd template function allows arbitrary command execution during config field expansion. Currently, this function is available to all template contexts, including remote/untrusted config dependencies fetched via git, GCS, or Google Cloud Build repos.

This change restricts the cmd function from being available when processing remote dependency configs to prevent unintended command execution from external config sources.

Changes

  • Added CmdAllowed flag in pkg/skaffold/util/env_template.go that controls whether the cmd function is permitted
  • runCmdFunc now checks CmdAllowed before executing and returns an error if not allowed
  • pkg/skaffold/parser/config.go sets CmdAllowed = false before processing remote dependency configs via processEachDependency
  • Added tests for the blocked/allowed behavior

Test plan

  • Existing tests pass — cmd still works for local configs
  • New test verifies cmd is blocked when CmdAllowed = false
  • New test verifies cmd works when CmdAllowed = true
  • Manual: local skaffold.yaml with {{cmd "echo" "hello"}} still works
  • Manual: remote git dependency with {{cmd ...}} returns an error

@markoyoungson markoyoungson requested a review from a team as a code owner March 26, 2026 04:05
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 26, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the security posture of the system by preventing arbitrary command execution from untrusted remote configuration sources. It introduces a mechanism to disable the cmd template function when processing external dependencies, thereby mitigating risks associated with malicious or compromised remote configurations. The change ensures that dynamic command execution is only permitted for local, trusted configurations, maintaining functionality where intended while bolstering overall system integrity.

Highlights

  • Security Enhancement: The cmd template function, which allows arbitrary command execution, is now restricted from being used within remote/untrusted configuration dependencies to prevent potential security vulnerabilities.
  • New CmdAllowed Flag: A new global boolean flag, CmdAllowed, was introduced in pkg/skaffold/util/env_template.go to control the availability of the cmd function.
  • Conditional Command Execution: The runCmdFunc now checks the CmdAllowed flag and returns an error if the cmd function is invoked when not permitted.
  • Remote Dependency Handling: The pkg/skaffold/parser/config.go file was updated to set CmdAllowed = false specifically when processing remote dependency configurations, ensuring the restriction is applied correctly.
  • Comprehensive Testing: New tests were added to verify that the cmd function is correctly blocked for remote contexts and continues to function as expected for local configurations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a security enhancement to prevent arbitrary command execution from remote or untrusted Skaffold configurations. It introduces a CmdAllowed flag that disables the cmd template function when processing such dependencies, and includes corresponding tests. A review comment suggests updating the placeholder issue link in the CmdAllowed variable's documentation for better traceability.

}
// CmdAllowed controls whether the `cmd` template function is permitted.
// Set to false when processing remote/untrusted config dependencies to
// prevent arbitrary command execution. See https://github.com/GoogleContainerTools/skaffold/issues/XXXXX
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The issue link XXXXX in the comment for CmdAllowed is a placeholder. Please update it with the actual issue number for better traceability and context.

@markoyoungson markoyoungson force-pushed the fix/restrict-cmd-remote-configs branch from 207fb8a to 622074f Compare March 26, 2026 04:52
@markoyoungson markoyoungson reopened this Mar 26, 2026
Prevent arbitrary command execution from untrusted remote configuration
dependencies by disabling the cmd template function when processing
remote configs.
@markoyoungson markoyoungson force-pushed the fix/restrict-cmd-remote-configs branch from 622074f to 9c10fb3 Compare March 26, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant