-
Notifications
You must be signed in to change notification settings - Fork 149
WIP: Add better filter capabilities to kubernetes tools #744
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe changes update two kubectl-related tools in a YAML configuration file, replacing simple command executions with shell scripts. These scripts introduce support for optional regex-based output filtering through new parameters ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
holmes/plugins/toolsets/kubernetes.yaml (1)
50-81
: Second script has identical injection & error-handling gapsReplicate the fixes suggested for the first script (
set -euo pipefail
, safe pattern handling, early exit on empty result).
Avoiding duplication keeps both tools equally safe.
🧹 Nitpick comments (1)
holmes/plugins/toolsets/kubernetes.yaml (1)
37-43
: Early-exit when include yields no matchesIf the include filter finds nothing,
filtered_output
is overwritten with the “No matches…” message, after which the exclude filter may run on that message, producing confusing output.
Better: emit the message andexit 0
immediately once no matches remain.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
holmes/plugins/toolsets/kubernetes.yaml
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
holmes/plugins/toolsets/**/*.yaml
📄 CodeRabbit Inference Engine (CLAUDE.md)
Toolsets must be located in holmes/plugins/toolsets/{name}.yaml or {name}/
Files:
holmes/plugins/toolsets/kubernetes.yaml
🧠 Learnings (3)
📚 Learning: applies to holmes/plugins/toolsets/**/*.yaml : toolsets must be located in holmes/plugins/toolsets/{...
Learnt from: CR
PR: robusta-dev/holmesgpt#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-06T08:36:24.907Z
Learning: Applies to holmes/plugins/toolsets/**/*.yaml : Toolsets must be located in holmes/plugins/toolsets/{name}.yaml or {name}/
Applied to files:
holmes/plugins/toolsets/kubernetes.yaml
📚 Learning: in the kubernetes logs toolset for holmes, both current and previous logs are intentionally fetched ...
Learnt from: nherment
PR: robusta-dev/holmesgpt#408
File: holmes/plugins/toolsets/kubernetes_logs.py:90-97
Timestamp: 2025-05-15T05:13:43.169Z
Learning: In the Kubernetes logs toolset for Holmes, both current and previous logs are intentionally fetched and combined for each pod, even though this requires more API calls. This design ensures all logs are captured even when pods restart but retain their name, providing complete diagnostic information.
Applied to files:
holmes/plugins/toolsets/kubernetes.yaml
📚 Learning: in robusta-dev/holmesgpt config.example.yaml, the azuremonitorlogs toolset configuration shows "enab...
Learnt from: vishiy
PR: robusta-dev/holmesgpt#782
File: config.example.yaml:31-49
Timestamp: 2025-08-05T00:42:23.792Z
Learning: In robusta-dev/holmesgpt config.example.yaml, the azuremonitorlogs toolset configuration shows "enabled: true" as an example of how to enable the toolset, not as a default setting. The toolset is disabled by default and requires explicit enablement in user configurations.
Applied to files:
holmes/plugins/toolsets/kubernetes.yaml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Pre-commit checks
- GitHub Check: llm_evals
- GitHub Check: Pre-commit checks
🔇 Additional comments (1)
holmes/plugins/toolsets/kubernetes.yaml (1)
24-30
: Addset -euo pipefail
to enforce safe-shell defaultsBoth scripts run multiple commands whose failures would otherwise be ignored (e.g.
grep
,echo "$temp_error"
).
Pre-pending the script bodies with strict bash options hard-fails on undefined vars, failed commands in a pipeline, and non-zero exits, preventing silent mis-behaviour.- output=$(kubectl get --show-labels -o wide {{ kind }} {{ name }}{% if namespace %} -n {{ namespace }}{% endif %} 2>&1) + set -euo pipefail + + output=$(kubectl get --show-labels -o wide {{ kind }} {{ name }}{% if namespace %} -n {{ namespace }}{% endif %} 2>&1)⛔ Skipped due to learnings
Learnt from: CR PR: robusta-dev/holmesgpt#0 File: CLAUDE.md:0-0 Timestamp: 2025-08-06T08:36:24.907Z Learning: Applies to holmes/plugins/toolsets/**/*.yaml : Toolsets must be located in holmes/plugins/toolsets/{name}.yaml or {name}/
Learnt from: vishiy PR: robusta-dev/holmesgpt#782 File: config.example.yaml:31-49 Timestamp: 2025-08-05T00:42:23.792Z Learning: In robusta-dev/holmesgpt config.example.yaml, the azuremonitorlogs toolset configuration shows "enabled: true" as an example of how to enable the toolset, not as a default setting. The toolset is disabled by default and requires explicit enablement in user configurations.
Learnt from: aantn PR: robusta-dev/holmesgpt#783 File: tests/llm/fixtures/test_ask_holmes/100_historical_logs/payment-api.yaml:49-70 Timestamp: 2025-08-05T06:14:39.523Z Learning: For evaluation test fixtures in the holmesgpt project, security contexts and security hardening are not priorities. The focus should be on functionality and test reliability rather than adding security configurations to Kubernetes manifests used in evals.
Learnt from: CR PR: robusta-dev/holmesgpt#0 File: CLAUDE.md:0-0 Timestamp: 2025-08-06T08:36:24.907Z Learning: Bash toolset validates commands for safety
Learnt from: nherment PR: robusta-dev/holmesgpt#408 File: holmes/plugins/toolsets/kubernetes_logs.py:90-97 Timestamp: 2025-05-15T05:13:43.169Z Learning: In the Kubernetes logs toolset for Holmes, both current and previous logs are intentionally fetched and combined for each pod, even though this requires more API calls. This design ensures all logs are captured even when pods restart but retain their name, providing complete diagnostic information.
# Apply filters if provided | ||
filtered_output="$output" | ||
|
||
{% if include_pattern %} | ||
# Apply include pattern (keep lines matching the pattern) | ||
filtered_output=$(echo "$filtered_output" | grep -E "{{ include_pattern }}" || echo "No matches found for include pattern: {{ include_pattern }}") | ||
{% endif %} | ||
|
||
{% if exclude_pattern %} | ||
# Apply exclude pattern (remove lines matching the pattern) | ||
filtered_output=$(echo "$filtered_output" | grep -vE "{{ exclude_pattern }}" || echo "$filtered_output") | ||
{% endif %} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unescaped user-supplied regex ⇒ command-injection vector
{{ include_pattern }}
/ {{ exclude_pattern }}
are inserted verbatim inside a double-quoted string that is shell-parsed by grep
.
A crafted value containing " ; malicious_cmd #
would prematurely close the quotes and execute arbitrary commands.
Mitigate by:
- Quoting the patterns with
printf %q
or similar after rendering, or - Passing the pattern via a variable and using
grep -E -- "$pattern"
.
Example patch (conceptual):
-{% if include_pattern %}
- filtered_output=$(echo "$filtered_output" | grep -E "{{ include_pattern }}" || echo "No matches found for include pattern: {{ include_pattern }}")
-{% endif %}
+{% if include_pattern %}
+ inc_pattern="{{ include_pattern }}"
+ filtered_output=$(echo "$filtered_output" | grep -E -- "$inc_pattern" || {
+ echo "No matches found for include pattern: $inc_pattern"; exit 0; })
+{% endif %}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
# Apply filters if provided | |
filtered_output="$output" | |
{% if include_pattern %} | |
# Apply include pattern (keep lines matching the pattern) | |
filtered_output=$(echo "$filtered_output" | grep -E "{{ include_pattern }}" || echo "No matches found for include pattern: {{ include_pattern }}") | |
{% endif %} | |
{% if exclude_pattern %} | |
# Apply exclude pattern (remove lines matching the pattern) | |
filtered_output=$(echo "$filtered_output" | grep -vE "{{ exclude_pattern }}" || echo "$filtered_output") | |
{% endif %} | |
# Apply filters if provided | |
filtered_output="$output" | |
{% if include_pattern %} | |
# Apply include pattern (keep lines matching the pattern) | |
inc_pattern="{{ include_pattern }}" | |
filtered_output=$(echo "$filtered_output" | grep -E -- "$inc_pattern" || { | |
echo "No matches found for include pattern: $inc_pattern"; exit 0; }) | |
{% endif %} | |
{% if exclude_pattern %} | |
# Apply exclude pattern (remove lines matching the pattern) | |
filtered_output=$(echo "$filtered_output" | grep -vE "{{ exclude_pattern }}" || echo "$filtered_output") | |
{% endif %} |
🤖 Prompt for AI Agents
In holmes/plugins/toolsets/kubernetes.yaml around lines 32 to 44, the
include_pattern and exclude_pattern are directly inserted into grep commands
inside double quotes, creating a command injection risk. To fix this, avoid
embedding the patterns directly in the command string; instead, assign the
rendered patterns to shell variables and pass them safely to grep using the
syntax grep -E -- "$pattern". This prevents shell interpretation of special
characters and mitigates injection vulnerabilities.
No description provided.