- 
                Notifications
    You must be signed in to change notification settings 
- Fork 183
ROB-2085: bash enabled by default, replaces most yaml toolsets #962
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
          
     Open
      
      
            nherment
  wants to merge
  23
  commits into
  master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
ROB-2085_bash_tool_enabled_by_default
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +101,922
        
        
          −936
        
        
          
        
      
    
  
  
     Open
                    Changes from 20 commits
      Commits
    
    
            Show all changes
          
          
            23 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      43bd886
              
                feat: ensure all necessary bash commands are supported, bash by defau…
              
              
                nherment 85c3ab6
              
                feat: ensure all necessary bash commands are supported, bash by defau…
              
              
                nherment f601e8a
              
                Merge branch 'master' into ROB-2085_bash_tool_enabled_by_default
              
              
                nherment c9ce45f
              
                feat: add support for kubectl cluster-info
              
              
                nherment 6cbb456
              
                feat: finalize bash toolset enabled by default
              
              
                nherment a6150d7
              
                Merge branch 'master' into ROB-2085_bash_tool_enabled_by_default
              
              
                nherment 2796bc4
              
                Merge branch 'master' into ROB-2085_bash_tool_enabled_by_default
              
              
                nherment ac90fd5
              
                chore: linting
              
              
                nherment 7a0b46f
              
                chore: fix tests
              
              
                nherment 247b1c1
              
                fix: add toolset docs urls + remove prints
              
              
                nherment 6984a87
              
                Merge branch 'master' into ROB-2085_bash_tool_enabled_by_default
              
              
                nherment d88fb45
              
                chore: address PR comments
              
              
                nherment 19c2969
              
                Merge branch 'master' into ROB-2085_bash_tool_enabled_by_default
              
              
                nherment 3a63eb9
              
                Merge branch 'master' into ROB-2085_bash_tool_enabled_by_default
              
              
                moshemorad 0446f87
              
                Merge branch 'master' into ROB-2085_bash_tool_enabled_by_default
              
              
                nherment 389756a
              
                fix: some toolsets should be enabled by default
              
              
                nherment fb687be
              
                Merge branch 'master' into ROB-2085_bash_tool_enabled_by_default
              
              
                nherment f56a80a
              
                mock files
              
              
                nherment 0fed363
              
                refresh mock files
              
              
                nherment 7923c00
              
                mock files
              
              
                nherment 9463cf0
              
                Merge branch 'master' into ROB-2085_bash_tool_enabled_by_default
              
              
                nherment 4d48942
              
                Merge branch 'master' into ROB-2085_bash_tool_enabled_by_default
              
              
                nherment cababff
              
                rm merge files
              
              
                nherment File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            225 changes: 225 additions & 0 deletions
          
          225 
        
  docs/data-sources/builtin-toolsets/kubectl-run-image.md
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| # Kubectl Run Image Toolset | ||
|  | ||
| The kubectl run image toolset provides secure execution of temporary containers in Kubernetes clusters for diagnostic and troubleshooting purposes. It creates temporary debug pods that are automatically cleaned up after execution. | ||
|  | ||
| **⚠️ Security Note**: This toolset can create pods in your Kubernetes cluster. It requires careful configuration with whitelisted images and command patterns to ensure security. | ||
|  | ||
| ## Overview | ||
|  | ||
| This toolset uses `kubectl run` to create temporary containers that: | ||
|  | ||
| - Execute diagnostic commands in specified container images | ||
| - Automatically clean up pods after execution (using `--rm` flag) | ||
| - Support custom namespaces and timeouts | ||
| - Provide isolated environments for network debugging, DNS resolution, and environment inspection | ||
|  | ||
| ## Use Cases | ||
|  | ||
| - **Network Debugging**: Test connectivity between services using network utilities | ||
| - **DNS Resolution**: Verify DNS configuration and resolution from within the cluster | ||
| - **Environment Inspection**: Check environment variables, file systems, and configuration | ||
| - **Service Testing**: Test HTTP endpoints, database connections, or API calls | ||
| - **Resource Analysis**: Examine cluster resources from a pod's perspective | ||
|  | ||
| ## Configuration | ||
|  | ||
| The toolset requires explicit configuration of allowed images and command patterns for security: | ||
|  | ||
| === "YAML" | ||
|  | ||
| ```yaml | ||
| toolsets: | ||
| kubectl_run_image: | ||
| enabled: true | ||
| config: | ||
| allowed_images: | ||
| - image: "busybox" | ||
| allowed_commands: | ||
| - "nslookup .*" | ||
| - "cat /etc/resolv.conf" | ||
| - "echo .*" | ||
| - image: "curlimages/curl" | ||
| allowed_commands: | ||
| - "curl -s http://.*" | ||
| - "curl -I .*" | ||
| - image: "registry.k8s.io/e2e-test-images/jessie-dnsutils:1.3" | ||
| allowed_commands: | ||
| - "nslookup .*" | ||
| - "dig .*" | ||
| - "host .*" | ||
| ``` | ||
|  | ||
| === "Python" | ||
|  | ||
| ```python | ||
| from holmes import Config | ||
|  | ||
| config = Config( | ||
| toolsets={ | ||
| "kubectl_run_image": { | ||
| "enabled": True, | ||
| "config": { | ||
| "allowed_images": [ | ||
| { | ||
| "image": "busybox", | ||
| "allowed_commands": [ | ||
| "nslookup .*", | ||
| "cat /etc/resolv.conf", | ||
| "echo .*" | ||
| ] | ||
| }, | ||
| { | ||
| "image": "curlimages/curl", | ||
| "allowed_commands": [ | ||
| "curl -s http://.*", | ||
| "curl -I .*" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ) | ||
| ``` | ||
|  | ||
| ## Configuration Options | ||
|  | ||
| ### `allowed_images` | ||
| List of image configurations that define which container images can be used. | ||
|  | ||
| **Required**: Yes | ||
|  | ||
| ### Image Configuration | ||
|  | ||
| Each image entry supports: | ||
|  | ||
| - **`image`** (string, required): The container image name | ||
| - **`allowed_commands`** (list, required): Regular expression patterns for allowed commands | ||
|  | ||
| ### Command Pattern Matching | ||
|  | ||
| Commands are validated against regex patterns: | ||
|  | ||
| - `"echo .*"` - Allows any echo command | ||
| - `"curl -s http://.*"` - Allows curl with -s flag to HTTP URLs | ||
| - `"nslookup [a-zA-Z0-9.-]+"` - Allows nslookup with domain names | ||
| - `"cat /etc/resolv.conf"` - Allows reading the DNS resolver configuration | ||
|  | ||
| ## Tool Parameters | ||
|  | ||
| ### `kubectl_run_image` | ||
|  | ||
| Creates and runs a temporary pod with the specified image and command. | ||
|  | ||
| **Parameters:** | ||
|  | ||
| - **`image`** (string, required): Container image to run (must be in allowed list) | ||
| - **`command`** (string, required): Command to execute (must match allowed patterns) | ||
| - **`namespace`** (string, optional): Kubernetes namespace (defaults to "default") | ||
| - **`timeout`** (integer, optional): Command timeout in seconds (defaults to 60) | ||
|  | ||
| ## Example Usage | ||
|  | ||
| ### Network Connectivity Test | ||
|  | ||
| ```bash | ||
| # Test connectivity to a service | ||
| kubectl_run_image( | ||
| image="curlimages/curl", | ||
| command="curl -s http://my-service:8080/health", | ||
| namespace="production" | ||
| ) | ||
| ``` | ||
|  | ||
| ### DNS Resolution Check | ||
|  | ||
| ```bash | ||
| # Check DNS resolution | ||
| kubectl_run_image( | ||
| image="busybox", | ||
| command="nslookup my-service.production.svc.cluster.local", | ||
| namespace="production" | ||
| ) | ||
| ``` | ||
|  | ||
| ### Environment Inspection | ||
|  | ||
| ```bash | ||
| # Check environment variables | ||
| kubectl_run_image( | ||
| image="busybox", | ||
| command="echo $KUBERNETES_SERVICE_HOST", | ||
| namespace="default" | ||
| ) | ||
| ``` | ||
|  | ||
| ## Security Considerations | ||
|  | ||
| ### Image Whitelisting | ||
|  | ||
| - Only pre-approved container images can be used | ||
| - Images should be from trusted registries | ||
| - Consider using specific image tags rather than `latest` | ||
|  | ||
| ### Command Validation | ||
|  | ||
| - All commands are validated against regex patterns | ||
| - Dangerous commands (file writes, network changes) should not be allowed | ||
| - Use restrictive patterns that only allow necessary operations | ||
|  | ||
| ### Namespace Restrictions | ||
|  | ||
| - The toolset validates namespace names for safety | ||
| - Namespaces must match safe naming patterns | ||
| - Consider restricting to specific namespaces in production | ||
|  | ||
| ### Resource Management | ||
|  | ||
| - Pods are automatically cleaned up using `--rm` flag | ||
| - Set appropriate timeouts to prevent hanging pods | ||
| - Monitor resource usage and set limits if needed | ||
|  | ||
| ## Common Image Recommendations | ||
|  | ||
| ### Network Debugging | ||
| - `busybox` - Basic utilities including nslookup, ping, telnet | ||
| - `curlimages/curl` - HTTP testing and API calls | ||
| - `registry.k8s.io/e2e-test-images/jessie-dnsutils:1.3` - DNS utilities | ||
|  | ||
| ### Database Testing | ||
| - `postgres:alpine` - PostgreSQL client tools | ||
| - `mysql:8.0` - MySQL client tools | ||
| - `redis:alpine` - Redis client tools | ||
|  | ||
| ### Security Scanning | ||
| - `aquasec/trivy` - Vulnerability scanning | ||
| - `clair-scanner` - Container security scanning | ||
|  | ||
| ## Troubleshooting | ||
|  | ||
| ### Permission Issues | ||
|  | ||
| Ensure the Holmes service account has the necessary RBAC permissions: | ||
|  | ||
| ```yaml | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: holmes-kubectl-run | ||
| rules: | ||
| - apiGroups: [""] | ||
| resources: ["pods"] | ||
| verbs: ["create", "get", "list", "delete"] | ||
| ``` | ||
|  | ||
| ### Image Pull Errors | ||
|  | ||
| - Verify images exist and are accessible from the cluster | ||
| - Check image registry authentication if using private images | ||
| - Ensure image names include full registry paths when needed | ||
|  | ||
| ### Command Validation Failures | ||
|  | ||
| - Check that commands match the configured regex patterns exactly | ||
| - Test regex patterns separately to ensure they work as expected | ||
| - Remember that patterns are matched against the entire command string | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.