diff --git a/playbooks/robusta_playbooks/bash_enrichments.py b/playbooks/robusta_playbooks/bash_enrichments.py index 17ed42ff2..2b6aa2d18 100644 --- a/playbooks/robusta_playbooks/bash_enrichments.py +++ b/playbooks/robusta_playbooks/bash_enrichments.py @@ -1,7 +1,16 @@ import logging from typing import List -from robusta.api import BaseBlock, BashParams, MarkdownBlock, NodeEvent, PodEvent, RobustaPod, action +from robusta.api import ( + BaseBlock, + BashParams, + ExecutionBaseEvent, + MarkdownBlock, + NodeEvent, + PodEvent, + RobustaPod, + action, +) @action @@ -35,7 +44,33 @@ def node_bash_enricher(event: NodeEvent, params: BashParams): block_list: List[BaseBlock] = [] exec_result = RobustaPod.exec_in_debugger_pod( - "node-bash-pod", node.metadata.name, params.bash_command, custom_annotations=params.custom_annotations + "node-bash-pod", + node.metadata.name, + params.bash_command, + custom_annotations=params.custom_annotations, + custom_volume_mounts=params.custom_volume_mounts, + custom_volumes=params.custom_volumes, + ) + block_list.append(MarkdownBlock(f"Command results for *{params.bash_command}:*")) + block_list.append(MarkdownBlock(exec_result)) + event.add_enrichment(block_list) + + +@action +def bash_enricher(event: ExecutionBaseEvent, params: BashParams): + """ + Execute the specified bash command in a new bash pod instead of **pod_bash_enricher** which runs on a target pod + Enrich the finding with the command results. + """ + + block_list: List[BaseBlock] = [] + exec_result = RobustaPod.exec_in_debugger_pod( + "bash-pod", + None, + params.bash_command, + custom_annotations=params.custom_annotations, + custom_volume_mounts=params.custom_volume_mounts, + custom_volumes=params.custom_volumes, ) block_list.append(MarkdownBlock(f"Command results for *{params.bash_command}:*")) block_list.append(MarkdownBlock(exec_result)) diff --git a/src/robusta/core/model/base_params.py b/src/robusta/core/model/base_params.py index f0ebd1688..4bb17a7c7 100644 --- a/src/robusta/core/model/base_params.py +++ b/src/robusta/core/model/base_params.py @@ -2,6 +2,7 @@ from enum import Enum, auto from typing import Any, Dict, List, Optional, Union +from hikaru.model.rel_1_26 import Volume, VolumeMount from pydantic import BaseModel, SecretStr, validator from robusta.integrations import openshift @@ -81,7 +82,6 @@ class ResourceInfo(BaseModel): class HolmesParams(ActionParams): - holmes_url: Optional[str] @validator("holmes_url", allow_reuse=True) @@ -250,6 +250,8 @@ class PodRunningParams(ActionParams): """ custom_annotations: Optional[Dict[str, str]] = None + custom_volume_mounts: Optional[List[VolumeMount]] + custom_volumes: Optional[List[Volume]] class VideoEnricherParams(ActionParams): diff --git a/src/robusta/integrations/kubernetes/custom_models.py b/src/robusta/integrations/kubernetes/custom_models.py index 67b0bf144..64c436f9f 100644 --- a/src/robusta/integrations/kubernetes/custom_models.py +++ b/src/robusta/integrations/kubernetes/custom_models.py @@ -238,6 +238,8 @@ def create_debugger_pod( env: Optional[List[EnvVar]] = None, mount_host_root: bool = False, custom_annotations: Optional[Dict[str, str]] = None, + custom_volume_mounts: Optional[List[VolumeMount]] = None, + custom_volumes: Optional[List[Volume]] = None, ) -> "RobustaPod": """ Creates a debugging pod with high privileges @@ -249,6 +251,9 @@ def create_debugger_pod( volume_mounts = [VolumeMount(name="host-root", mountPath="/host")] volumes = [Volume(name="host-root", hostPath=HostPathVolumeSource(path="/", type="Directory"))] + volume_mounts = (volume_mounts or []) + (custom_volume_mounts or []) + volumes = (volumes or []) + (custom_volumes or []) + debugger = RobustaPod( apiVersion="v1", kind="Pod", @@ -321,9 +326,16 @@ def exec_in_debugger_pod( cmd, debug_image=PYTHON_DEBUGGER_IMAGE, custom_annotations: Optional[Dict[str, str]] = None, + custom_volume_mounts: Optional[List[VolumeMount]] = None, + custom_volumes: Optional[List[Volume]] = None, ) -> str: debugger = RobustaPod.create_debugger_pod( - pod_name, node_name, debug_image, custom_annotations=custom_annotations + pod_name, + node_name, + debug_image, + custom_annotations=custom_annotations, + custom_volume_mounts=custom_volume_mounts, + custom_volumes=custom_volumes, ) try: return debugger.exec(cmd)