Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions cmd/tracee/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@
"[file|dir]\t\t\t\tPath to a policy or directory with policies",
)

// Runtime flags

rootCmd.Flags().StringArrayP(
flags.RuntimeFlag,
"r",
[]string{"workdir=" + flags.WorkdirDefault},
fmt.Sprintf("[workdir=%s]\t\tControl runtime configurations", flags.WorkdirDefault),
)
err := viper.BindPFlag(flags.RuntimeFlag, rootCmd.Flags().Lookup(flags.RuntimeFlag))
if err != nil {
return errfmt.WrapError(err)
}

Check warning on line 129 in cmd/tracee/cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/tracee/cmd/root.go#L118-L129

Added lines #L118 - L129 were not covered by tests

// Output flags

rootCmd.Flags().StringArrayP(
Expand All @@ -123,7 +136,7 @@
[]string{"table"},
"[json|none|webhook...]\t\tControl how and where output is printed",
)
err := viper.BindPFlag("output", rootCmd.Flags().Lookup("output"))
err = viper.BindPFlag("output", rootCmd.Flags().Lookup("output"))

Check warning on line 139 in cmd/tracee/cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/tracee/cmd/root.go#L139

Added line #L139 was not covered by tests
if err != nil {
return errfmt.WrapError(err)
}
Expand Down Expand Up @@ -268,16 +281,6 @@
return errfmt.WrapError(err)
}

rootCmd.Flags().String(
"install-path",
"/tmp/tracee",
"<dir>\t\t\t\tPath where tracee will install or lookup it's resources",
)
err = viper.BindPFlag("install-path", rootCmd.Flags().Lookup("install-path"))
if err != nil {
return errfmt.WrapError(err)
}

rootCmd.Flags().StringArrayP(
"log",
"l",
Expand Down
5 changes: 3 additions & 2 deletions deploy/helm/tracee/templates/tracee-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ data:
pprof: {{ .Values.config.pprof }}
pyroscope: {{ .Values.config.pyroscope }}
listen-addr: {{ .Values.config.listenAddr }}
{{- if .Values.config.installPath }}
install-path: {{ .Values.config.installPath }}
{{- if .Values.config.workdir }}
runtime:
- workdir={{ .Values.config.workdir }}
{{- end }}
{{- if .Values.config.signaturesDir }}
signatures-dir: {{ .Values.config.signaturesDir }}
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/tracee/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ config:
pprof: false
pyroscope: false
listenAddr: :3366
installPath: ""
workdir: ""
signaturesDir: ""
log:
level: info
Expand Down
46 changes: 46 additions & 0 deletions docs/docs/flags/runtime.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: TRACEE-RUNTIME
section: 1
header: Tracee Runtime Flag Manual
date: 2025/11
...

## NAME

tracee **\-\-runtime** - Control runtime configurations

## SYNOPSIS

tracee **\-\-runtime** [workdir=*path*] [**\-\-runtime** ...]

## DESCRIPTION

The **\-\-runtime** flag allows you to control runtime configurations for Tracee.

### Options

- **workdir**=*path*
Set the path where Tracee will install or lookup its resources. The default value is `/tmp/tracee`.

Example:
```console
--runtime workdir=/tmp/tracee
```

## EXAMPLES

1. Use the default working directory:
```console
--runtime workdir=/tmp/tracee
```

2. Set a custom working directory:
```console
--runtime workdir=/var/lib/tracee
```

3. Using the short form:
```console
-r workdir=/opt/tracee
```

15 changes: 11 additions & 4 deletions docs/docs/install/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,23 @@ A complete config file with all available options can be found [here](https://gi
- process
```

### Install Path
### Runtime

- **`--install-path`**: Specifies the directory where Tracee will install or look for its resources. If not specified, the default installation directory is `/tmp/tracee`.
- **`--runtime` (`-r`)**: Controls runtime configurations for Tracee.

CLI Examples:
```bash
# Set working directory
tracee --runtime workdir=/opt/tracee
```

YAML:
```yaml
install-path: /opt/tracee
runtime:
- workdir=/opt/tracee
```

__NOTE__: This option is useful when running Tracee in environments where `/tmp` is not suitable or secure.
__NOTE__: The workdir is the path where Tracee will install or lookup its resources. The default is `/tmp/tracee`. This option is useful when running Tracee in environments where `/tmp` is not suitable or secure.

### Log

Expand Down
3 changes: 2 additions & 1 deletion docs/docs/policies/usage/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ tracee --config ./config.yaml --policy ./policy.yaml && cat /tmp/debug.json
### config.yaml (example)

```yaml
install-path: /tmp/tracee
runtime:
- workdir=/tmp/tracee

# server configuration

Expand Down
49 changes: 49 additions & 0 deletions docs/man/runtime.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.\" Automatically generated by Pandoc 3.2
.\"
.TH "TRACEE\-RUNTIME" "1" "2025/11" "" "Tracee Runtime Flag Manual"
.SS NAME
tracee \f[B]\-\-runtime\f[R] \- Control runtime configurations
.SS SYNOPSIS
tracee \f[B]\-\-runtime\f[R] [workdir=\f[I]path\f[R]]
[\f[B]\-\-runtime\f[R] \&...]
.SS DESCRIPTION
The \f[B]\-\-runtime\f[R] flag allows you to control runtime
configurations for Tracee.
.SS Options
.IP \[bu] 2
\f[B]workdir\f[R]=\f[I]path\f[R] Set the path where Tracee will install
or lookup its resources.
The default value is \f[CR]/tmp/tracee\f[R].
.RS 2
.PP
Example:
.IP
.EX
\-\-runtime workdir=/tmp/tracee
.EE
.RE
.SS EXAMPLES
.IP "1." 3
Use the default working directory:
.RS 4
.IP
.EX
\-\-runtime workdir=/tmp/tracee
.EE
.RE
.IP "2." 3
Set a custom working directory:
.RS 4
.IP
.EX
\-\-runtime workdir=/var/lib/tracee
.EE
.RE
.IP "3." 3
Using the short form:
.RS 4
.IP
.EX
\-r workdir=/opt/tracee
.EE
.RE
4 changes: 3 additions & 1 deletion examples/config/global_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"capabilities": [],
"containers": [],
"healthz": false,
"install-path": "/tmp/tracee",
"runtime": [
"workdir=/tmp/tracee"
],
"listen-addr": ":3366",
"log": [
"info"
Expand Down
3 changes: 2 additions & 1 deletion examples/config/global_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ events:

healthz: false

install-path: /tmp/tracee
runtime:
- workdir=/tmp/tracee

listen-addr: :3366

Expand Down
13 changes: 10 additions & 3 deletions pkg/cmd/cobra/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,16 @@
}

// Decide BTF & BPF files to use (based in the kconfig, release & environment info)
runtimeFlags, err := flags.GetFlagsFromViper(flags.RuntimeFlag)
if err != nil {
return runner, err
}
runtimeConfig, err := flags.PrepareRuntime(runtimeFlags)
if err != nil {
return runner, err
}

Check warning on line 326 in pkg/cmd/cobra/cobra.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cobra/cobra.go#L319-L326

Added lines #L319 - L326 were not covered by tests

traceeInstallPath := viper.GetString("install-path")
err = initialize.BpfObject(&cfg, kernelConfig, osInfo, traceeInstallPath, version)
err = initialize.BpfObject(&cfg, kernelConfig, osInfo, runtimeConfig.Workdir, version)

Check warning on line 328 in pkg/cmd/cobra/cobra.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cobra/cobra.go#L328

Added line #L328 was not covered by tests
if err != nil {
return runner, errfmt.Errorf("failed preparing BPF object: %v", err)
}
Expand All @@ -340,7 +347,7 @@
cfg.HealthzEnabled = runner.HTTP.HealthzEnabled()
runner.TraceeConfig = cfg
runner.Printer = p
runner.InstallPath = traceeInstallPath
runner.Workdir = runtimeConfig.Workdir

Check warning on line 350 in pkg/cmd/cobra/cobra.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cobra/cobra.go#L350

Added line #L350 was not covered by tests

noSignaturesMode := viper.GetBool("no-signatures")
if noSignaturesMode {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/flags/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func GetFlagsFromViper(key string) ([]string, error) {
flagger = &OutputConfig{}
case "dnscache":
flagger = &DnsCacheConfig{}
case "runtime":
flagger = &RuntimeConfig{}
default:
return nil, errfmt.Errorf("unrecognized key: %s", key)
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/cmd/flags/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,28 @@ server:
"pyroscope",
},
},
{
name: "Test runtime configuration (cli flags)",
yamlContent: `
runtime:
- workdir=/tmp/tracee
`,
key: "runtime",
expectedFlags: []string{
"workdir=/tmp/tracee",
},
},
{
name: "Test runtime configuration (structured flags)",
yamlContent: `
runtime:
workdir: /opt/tracee
`,
key: "runtime",
expectedFlags: []string{
"workdir=/opt/tracee",
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -1022,6 +1044,7 @@ func TestOutputConfigFlags(t *testing.T) {
})
}
}

func TestServerConfigFlags(t *testing.T) {
t.Parallel()

Expand Down
58 changes: 58 additions & 0 deletions pkg/cmd/flags/runtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package flags

import (
"fmt"
"strings"

"github.com/aquasecurity/tracee/common/errfmt"
)

const (
RuntimeFlag = "runtime"
WorkdirDefault = "/tmp/tracee"

workdirFlag = "workdir"
runtimeInvalidFlag = "invalid runtime flag: %s, use 'trace man runtime' for more info"
)

// RuntimeConfig represents the configuration for the runtime.
type RuntimeConfig struct {
Workdir string `mapstructure:"workdir"`
}

// flags returns the flags for the runtime configuration.
func (c *RuntimeConfig) flags() []string {
return []string{fmt.Sprintf("workdir=%s", c.Workdir)}
}

// PrepareRuntime prepares the runtime configuration from the command line flags.
func PrepareRuntime(runtimeSlice []string) (RuntimeConfig, error) {
runtimeConfig := RuntimeConfig{
Workdir: WorkdirDefault,
}
for _, flag := range runtimeSlice {
parts := strings.SplitN(flag, "=", 2)

if len(parts) != 2 {
return runtimeConfig, errfmt.Errorf(runtimeInvalidFlag, flag)
}

flagName := parts[0]
flagValue := parts[1]

switch flagName {
case workdirFlag:
workdir := strings.TrimSpace(flagValue)
if workdir == "" {
return runtimeConfig, errfmt.Errorf("invalid runtime flag: %s value can't be empty, use 'trace man runtime' for more info", flagName)
}

runtimeConfig.Workdir = workdir

default:
return runtimeConfig, errfmt.Errorf(runtimeInvalidFlag, flag)
}
}

return runtimeConfig, nil
}
Loading