-
Notifications
You must be signed in to change notification settings - Fork 283
Update bash_enrichments.py - add sshexecutor #1887
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
This function allows to execute commands via SSH, usually when you have VMs or servers outside Kubernetes
WalkthroughA new function, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant generic_bash_enricher
participant subprocess
participant Event
User->>generic_bash_enricher: Trigger with event and params
generic_bash_enricher->>generic_bash_enricher: Validate params for bash_command
alt bash_command missing
generic_bash_enricher->>Event: Add warning enrichment
generic_bash_enricher-->>User: Return early
else bash_command present
generic_bash_enricher->>subprocess: Run bash_command
subprocess-->>generic_bash_enricher: Return stdout, stderr, returncode
generic_bash_enricher->>Event: Add enrichment with command results
generic_bash_enricher-->>User: Return
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ 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. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. 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
🧹 Nitpick comments (2)
playbooks/robusta_playbooks/bash_enrichments.py (2)
46-46: Add type annotation for theparamsparameter.Consider adding a type annotation for better code documentation and IDE support.
-def generic_bash_enricher(event: ExecutionBaseEvent, params): +def generic_bash_enricher(event: ExecutionBaseEvent, params: dict):
45-78: Security consideration: Arbitrary command execution capability.This function enables execution of arbitrary bash commands on the runner environment, including SSH to remote hosts as intended. While this provides powerful functionality for the use case described in the PR objectives, ensure that:
- Access to this enricher is properly restricted in production environments
- Users understand the security implications of running arbitrary commands
- Consider logging executed commands for audit purposes
The implementation correctly handles both string and list command formats, includes comprehensive error handling, and provides clear output formatting.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
playbooks/robusta_playbooks/bash_enrichments.py(2 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
playbooks/robusta_playbooks/bash_enrichments.py
46-46: Undefined name ExecutionBaseEvent
(F821)
🪛 Flake8 (7.2.0)
playbooks/robusta_playbooks/bash_enrichments.py
[error] 46-46: undefined name 'ExecutionBaseEvent'
(F821)
🔇 Additional comments (3)
playbooks/robusta_playbooks/bash_enrichments.py (3)
1-1: LGTM!The addition of
subprocessimport is necessary for the newgeneric_bash_enricherfunction and follows proper Python import conventions.
57-68: LGTM! Robust error handling and command execution.The error handling correctly:
- Differentiates between string commands (using
shell=True) and list commands- Captures both stdout and stderr with proper text handling
- Handles exceptions gracefully by setting appropriate error status
- Uses
capture_output=Trueandtext=Truefor clean output processing
70-78: LGTM! Comprehensive output formatting.The markdown formatting provides clear, structured output that includes all relevant information:
- Command executed
- Return code for success/failure indication
- Separated stdout and stderr in code blocks for readability
This function allows to execute commands via SSH, usually when you have VMs or servers outside Kubernetes !
How to use ?