Skip to content

Commit

Permalink
use a smaller image for the tcpdump for a quicker cold start (pull) (#…
Browse files Browse the repository at this point in the history
…426)

Signed-off-by: Thomas Labarussias <[email protected]>
  • Loading branch information
Issif authored Sep 13, 2024
1 parent 7bd28bb commit b1d76ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
20 changes: 14 additions & 6 deletions actionners/kubernetes/tcpdump/tcpdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ var (
)

type Parameters struct {
Duration int `mapstructure:"duration" validate:"gte=0"`
Snaplen int `mapstructure:"snaplen" validate:"gte=0"`
Image string `mapstructure:"image"`
Duration int `mapstructure:"duration" validate:"gte=0"`
Snaplen int `mapstructure:"snaplen" validate:"gte=0"`
}

const (
baseName string = "falco-talon-tcpdump-"
defaultTTL int = 300
baseName string = "falco-talon-tcpdump-"
defaultImage string = "issif/tcpdump:latest"
defaultTTL int = 300
defaultDuration int = 5
)

type Actionner struct{}
Expand Down Expand Up @@ -108,6 +111,7 @@ func (a Actionner) Parameters() models.Parameters {
return Parameters{
Duration: 20,
Snaplen: 4096,
Image: "issif/tcpdump:latest",
}
}

Expand Down Expand Up @@ -135,7 +139,11 @@ func (a Actionner) Run(event *events.Event, action *rules.Action) (utils.LogLine
}

if parameters.Duration == 0 {
parameters.Duration = 5
parameters.Duration = defaultDuration
}

if parameters.Image == "" {
parameters.Image = defaultImage
}

client := k8s.GetClient()
Expand All @@ -153,7 +161,7 @@ func (a Actionner) Run(event *events.Event, action *rules.Action) (utils.LogLine

ephemeralContainerName := fmt.Sprintf("%v%v", baseName, uuid.NewString()[:5])

err = client.CreateEphemeralContainer(pod, containers[0], ephemeralContainerName, defaultTTL)
err = client.CreateEphemeralContainer(pod, containers[0], ephemeralContainerName, parameters.Image, defaultTTL)
if err != nil {
return utils.LogLine{
Objects: objects,
Expand Down
8 changes: 4 additions & 4 deletions cmd/actionners.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ var actionnersListCmd = &cobra.Command{
Run: func(_ *cobra.Command, _ []string) {
defaultActionners := actionners.ListDefaultActionners()
type actionner struct { // nolint:govet
Parameters map[string]any `yaml:"parameters"`
Name string `yaml:"name"`
Category string `yaml:"category"`
Description string `yaml:"description"`
Source string `yaml:"source"`
Permissions string `yaml:"permissions,omitempty"`
Example string `yaml:"example,omitempty"`
RequiredOutputFields []string `yaml:"required_output_fields"`
Continue bool `yaml:"continue"`
UseContext bool `yaml:"use_context"`
AllowOutput bool `yaml:"allow_output"`
RequireOutput bool `yaml:"require_output"`
RequiredOutputFields []string `yaml:"required_output_fields"`
Parameters map[string]any `yaml:"parameters"`
Permissions string `yaml:"permissions,omitempty"`
Example string `yaml:"example,omitempty"`
}

for _, i := range *defaultActionners {
Expand Down
6 changes: 3 additions & 3 deletions internal/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,12 @@ func GetHealthyReplicasPercent(replicaset *appsv1.ReplicaSet) (int64, error) {
return 100 * (healthyReplicas / totalReplicas), nil
}

func (client *Client) CreateEphemeralContainer(pod *corev1.Pod, container, name string, ttl int) error {
func (client *Client) CreateEphemeralContainer(pod *corev1.Pod, container, name, image string, ttl int) error {
ec := &corev1.EphemeralContainer{
EphemeralContainerCommon: corev1.EphemeralContainerCommon{
Name: name,
Image: "dockersec/tcpdump",
ImagePullPolicy: corev1.PullIfNotPresent,
Image: image,
ImagePullPolicy: corev1.PullAlways,
Command: []string{"sleep", fmt.Sprintf("%v", ttl)},
Stdin: true,
TTY: false,
Expand Down

0 comments on commit b1d76ec

Please sign in to comment.