Skip to content

Commit

Permalink
chore(containers): make feature flag a safe guard
Browse files Browse the repository at this point in the history
- make default behavior (--containers) to enrich containers

Keep a safeguard measure (change cmdline flag to --no-containers):

- do not try to register runtime services
- do not try to register runtime sockets (with or without --crs)
  • Loading branch information
rafaeldtinoco committed Oct 25, 2023
1 parent d381dd8 commit cc21fe3
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 215 deletions.
3 changes: 0 additions & 3 deletions builder/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ TRACEE_EXE=${TRACEE_EXE:="/tracee/tracee"}

LIBBPFGO_OSRELEASE_FILE=${LIBBPFGO_OSRELEASE_FILE:="/etc/os-release-host"}

CONTAINERS_ENRICHMENT=${CONTAINERS_ENRICHMENT:="0"}

CAPABILITIES_BYPASS=${CAPABILITIES_BYPASS:="0"}
CAPABILITIES_ADD=${CAPABILITIES_ADD:=""}
CAPABILITIES_DROP=${CAPABILITIES_DROP:=""}
Expand All @@ -35,7 +33,6 @@ run_tracee() {
--output=option:parse-arguments \
--cache cache-type=mem \
--cache mem-cache-size=512 \
--containers=$CONTAINERS_ENRICHMENT \
--capabilities bypass=$CAPABILITIES_BYPASS \
--capabilities add=$CAPABILITIES_ADD \
--capabilities drop=$CAPABILITIES_DROP
Expand Down
4 changes: 2 additions & 2 deletions cmd/tracee-ebpf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func main() {
Value: ":3366",
},
&cli.BoolFlag{
Name: "containers",
Usage: "enable container info enrichment to events. this feature is experimental and may cause unexpected behavior in the pipeline",
Name: "no-containers",
Usage: "disable container info enrichment to events. safeguard option.",
},
&cli.StringSliceFlag{
Name: "log",
Expand Down
6 changes: 3 additions & 3 deletions cmd/tracee/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ func initCmd() error {
// Container flags

rootCmd.Flags().Bool(
"containers",
"no-containers",
false,
"\t\t\t\t\tEnable container info enrichment to events. This feature is experimental and may cause unexpected behavior in the pipeline",
"\t\t\t\t\tDisable container info enrichment to events. Safeguard option.",
)
err = viper.BindPFlag("containers", rootCmd.Flags().Lookup("containers"))
err = viper.BindPFlag("no-containers", rootCmd.Flags().Lookup("no-containers"))
if err != nil {
return errfmt.WrapError(err)
}
Expand Down
4 changes: 0 additions & 4 deletions docs/docs/data-sources/containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ The [container enrichment](../integrating/container-engines.md) feature gives Tr

The [data source](./overview.md) feature makes the information gathered from active containers accessible to signatures. When an event is captured and triggers a signature, that signature can retrieve information about the container using its container ID, which is bundled with the event being analyzed by the signature.

## Enabling the Feature

The data source does not need to be enabled, but requires that the `container enrichment` feature is. To enable the enrichment feature, execute trace with `--containers`. For more information you can read [container enrichment](../integrating/container-engines.md) page.

## Internal Data Organization

From the [data-sources documentation](../data-sources/overview.md), you'll see that searches use keys. It's a bit like looking up information with a specific tag (or a key=value storage).
Expand Down
9 changes: 4 additions & 5 deletions docs/docs/deep-dive/caching-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ The effects of this are the following:

## Use caching

Example using **1GB cache**, container **enrichment** in the pipeline, argument
**parsing** so arguments are formatted in a human consumable way:
Example using **1GB cache**:

```console
sudo ./dist/tracee \
--cache cache-type=mem \
--cache mem-cache-size=1024 \
--containers -o format:json \
-o format:json \
-o option:parse-arguments \
-trace container \
--crs docker:/var/run/docker.sock
Expand All @@ -54,5 +53,5 @@ sudo ./dist/tracee \
| jq -c '. | {cgroupid, processname, containername}'
```
You may cause latencies in **tracee** pipeline because the event json
processing from `jq` might not be as fast as how **tracee** is capable
of writing events to it.
processing from `jq` might not be as fast as how **tracee** is capable of
writing events to it.
48 changes: 9 additions & 39 deletions docs/docs/integrating/container-engines.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ Tracee is capable of **extracting information about running containers**. It
does that by tracking container namespaces creation kernel events and enriching
those events by communicating with the relevant container's runtime and SDK.

!!! Experimental Warning
This feature is experimental and should be explicitly enabled in
**tracee**, by using the `--container` flag OR, if running tracee
container image, setting the `CONTAINERS_ENRICHMENT` environment flag (see
example bellow).

1. Running **tracee** manually

If running tracee directly (not in a container), it will automatically
search for known supported runtimes in their socket's default locations.
You may track if tracee was able to find the container runtime socket by
running tracee with `--log debug` option. There will be a line to each known
runtime engine socket location and a message saying if tracee wass able to
find it or not.

2. Running **tracee** using a docker container

Expand All @@ -22,32 +20,28 @@ those events by communicating with the relevant container's runtime and SDK.

Using containerd as our runtime for example, this can be done by running
tracee like:

```console
docker run \
--name tracee --rm -it \
--pid=host --cgroupns=host --privileged \
-v /etc/os-release:/etc/os-release-host:ro \
-v /var/run/containerd:/var/run/containerd \
-e CONTAINERS_ENRICHMENT=1 \
aquasec/tracee:{{ git.tag }}
```

Most container runtimes have their sockets installed by default in
`/var/run`. If your system includes multiple container runtimes, tracee can
track them all, however one should mount either all their runtime sockets
or `/var/run` in it's entirety to do so.
track them all, however one should mount either all their runtime sockets or
`/var/run` in it's entirety to do so.

## Supported Container Runtime Engines

Currently, tracee will look in the following paths for auto-discovering the listed runtimes:

1. Docker: `/var/run/docker.sock`

2. Containerd: `/var/run/containerd/containerd.sock`

3. CRI-O: `/var/run/crio/crio.sock`

4. Podman: `/var/run/podman/podman.sock`

!!! Tip
Expand All @@ -56,30 +50,6 @@ Currently, tracee will look in the following paths for auto-discovering the list
nesting and so sockets must be appropriately mounted and set up for tracee
to enrich all containers correctly.

## Viewing enrichment output

As a user, when container enrichment is enabled the event output will include enriched fields in these cases:

1. Running **tracee** with a json format will include all container enriched fields

```console
docker run \
--name tracee --rm -it \
--pid=host --cgroupns=host --privileged \
-v /etc/os-release:/etc/os-release-host:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
aquasec/tracee:{{ git.tag }} \
--output json --containers
```

2. Running in container filtering mode and with enrichment enabled will add the image name to the table printer
## Enrichment output

```console
docker run \
--name tracee --rm -it \
--pid=host --cgroupns=host --privileged \
-v /etc/os-release:/etc/os-release-host:ro \
-v /var/run/containerd:/var/run/containerd \
aquasec/tracee:{{ git.tag }} \
--scope container --containers
```
Example of the output.
12 changes: 7 additions & 5 deletions pkg/cmd/cobra/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func GetTraceeRunner(c *cobra.Command, version string) (cmd.Runner, error) {
cfg := config.Config{
PerfBufferSize: viper.GetInt("perf-buffer-size"),
BlobPerfBufferSize: viper.GetInt("blob-perf-buffer-size"),
ContainersEnrich: viper.GetBool("containers"),
NoContainersEnrich: viper.GetBool("no-containers"),
}

// OS release information
Expand All @@ -84,11 +84,13 @@ func GetTraceeRunner(c *cobra.Command, version string) (cmd.Runner, error) {

// Container Runtime command line flags

sockets, err := flags.PrepareContainers(viper.GetStringSlice("crs"))
if err != nil {
return runner, err
if !cfg.NoContainersEnrich {
sockets, err := flags.PrepareContainers(viper.GetStringSlice("crs"))
if err != nil {
return runner, err
}
cfg.Sockets = sockets
}
cfg.Sockets = sockets

// Cache command line flags

Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/tracee.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ func GetContainerMode(cfg config.Config) config.ContainerMode {

for p := range cfg.Policies.Map() {
if p.ContainerFilterEnabled() {
// enable printer container print mode if container filters are set
containerMode = config.ContainerModeEnabled
if cfg.ContainersEnrich {
// further enable container enrich print mode if container enrichment is enabled
containerMode = config.ContainerModeEnriched
// Container Enrichment is enabled by default ...
containerMode = config.ContainerModeEnriched
if cfg.NoContainersEnrich {
// ... but might be disabled as a safeguard measure.
containerMode = config.ContainerModeEnabled
}

break
Expand Down
12 changes: 7 additions & 5 deletions pkg/cmd/urfave/urfave.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func GetTraceeRunner(c *cli.Context, version string) (cmd.Runner, error) {
cfg := config.Config{
PerfBufferSize: c.Int("perf-buffer-size"),
BlobPerfBufferSize: c.Int("blob-perf-buffer-size"),
ContainersEnrich: c.Bool("containers"),
NoContainersEnrich: c.Bool("no-containers"),
}

// Output command line flags
Expand Down Expand Up @@ -63,11 +63,13 @@ func GetTraceeRunner(c *cli.Context, version string) (cmd.Runner, error) {

// Container Runtime command line flags

sockets, err := flags.PrepareContainers(c.StringSlice("crs"))
if err != nil {
return runner, err
if !cfg.NoContainersEnrich {
sockets, err := flags.PrepareContainers(c.StringSlice("crs"))
if err != nil {
return runner, err
}
cfg.Sockets = sockets
}
cfg.Sockets = sockets

// Cache command line flags

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Config struct {
KernelConfig *helpers.KernelConfig
OSInfo *helpers.OSInfo
Sockets runtime.Sockets
ContainersEnrich bool
NoContainersEnrich bool
EngineConfig engine.Config
MetricsEnabled bool
}
Expand Down
Loading

0 comments on commit cc21fe3

Please sign in to comment.