Skip to content

Commit 2ccc599

Browse files
committed
flag(stores): new flag format
1 parent 1fa65a8 commit 2ccc599

File tree

18 files changed

+566
-457
lines changed

18 files changed

+566
-457
lines changed

cmd/tracee/cmd/root.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -218,27 +218,14 @@ func initCmd() error {
218218
return errfmt.WrapError(err)
219219
}
220220

221-
// Process Tree flags
222-
223-
rootCmd.Flags().StringArrayP(
224-
"proctree",
225-
"t",
226-
[]string{"source=none"},
227-
"[source=[events|signals|both]...]\tControl process tree options",
228-
)
229-
err = viper.BindPFlag("proctree", rootCmd.Flags().Lookup("proctree"))
230-
if err != nil {
231-
return errfmt.WrapError(err)
232-
}
233-
234-
// DNS Cache flags
221+
// Stores flags
235222

236223
rootCmd.Flags().StringArray(
237-
"dnscache",
238-
[]string{"none"},
239-
"\t\t\t\t\tEnable DNS Cache",
224+
flags.StoresFlag,
225+
[]string{},
226+
"\t\t\t\t\tStores configurations",
240227
)
241-
err = viper.BindPFlag("dnscache", rootCmd.Flags().Lookup("dnscache"))
228+
err = viper.BindPFlag(flags.StoresFlag, rootCmd.Flags().Lookup(flags.StoresFlag))
242229
if err != nil {
243230
return errfmt.WrapError(err)
244231
}

docs/docs/advanced/data-sources/builtin/dns.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,20 @@ These relations can be queried in signatures through a data source.
88
To switch on the `DNS Cache` feature, run the command:
99

1010
```bash
11-
sudo tracee --output option:sort-events --output json --output option:parse-arguments --dnscache enable --events <event_type>
11+
sudo tracee --output option:sort-events --output json --output option:parse-arguments --stores dns.enabled --events <event_type>
1212
```
1313

1414
The underlying structure is populated using the core [net_packet_dns](../../../events/builtin/man/network/net_packet_dns.md) event and its payload.
1515

1616
## Command Line Option
1717

1818
```bash
19-
$ tracee --dnscache help
20-
Select different options for the DNS cache.
21-
2219
Example:
23-
--dnscache enable | enable with default values (see below).
24-
--dnscache size=X | will cache up to X dns query trees - further queries may be cached regardless (default: 5000).
20+
--stores dns.enabled | enable the DNS cache.
21+
--stores dns.size=X | will cache up to X dns query trees - further queries may be cached regardless (default: 5000).
2522

26-
Use comma OR use the flag multiple times to choose multiple options:
27-
--dnscache size=A
28-
--dnscache enable
23+
Use the flag multiple times to choose multiple options:
24+
--stores dns.enabled --stores dns.size=5000
2925
```
3026

3127
Consider for your usecase, how many query trees would you like to store? If you will frequently check only a few addresses, consider lowering the size.

docs/docs/advanced/data-sources/builtin/process-tree.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The `Process Tree` feature offers a structured view of processes and threads act
77
To switch on the `Process Tree` feature, run the command:
88

99
```bash
10-
sudo tracee --output option:sort-events --output json --output option:parse-arguments --proctree source=both --events <event_type>
10+
sudo tracee --output option:sort-events --output json --output option:parse-arguments --stores process.enabled --stores process.source=both --events <event_type>
1111
```
1212

1313
The underlying structure is populated using the core `sched_process_fork`, `sched_process_exec`, and `sched_process_exit` events and their data. There's also an option to bootstrap the process tree through a secondary route using internal signal events.
@@ -27,19 +27,18 @@ The process tree query the procfs upon initialization and during runtime to fill
2727

2828
```bash
2929
Example:
30-
--proctree source=[none|events|signals|both]
31-
none | process tree is disabled (default).
30+
--stores process.enabled | enable the process tree.
31+
--stores process.source=[none|events|signals|both]
32+
none | process tree source is disabled (default).
3233
events | process tree is built from events.
3334
signals | process tree is built from signals.
3435
both | process tree is built from both events and signals.
35-
--proctree process-cache=8192 | will cache up to 8192 processes in the tree (LRU cache).
36-
--proctree thread-cache=16384 | will cache up to 16384 threads in the tree (LRU cache).
37-
--proctree disable-procfs | will disable procfs entirely.
38-
--proctree disable-procfs-query | will disable procfs quering during runtime.
39-
40-
Use comma OR use the flag multiple times to choose multiple options:
41-
--proctree source=A,process-cache=B,thread-cache=C
42-
--proctree process-cache=X --proctree thread-cache=Y
36+
--stores process.processes=8192 | will cache up to 8192 processes in the tree (LRU cache).
37+
--stores process.threads=16384 | will cache up to 16384 threads in the tree (LRU cache).
38+
--stores process.use-procfs | will enable procfs initialization and querying.
39+
40+
Use the flag multiple times to choose multiple options:
41+
--stores process.enabled --stores process.source=both --stores process.processes=8192
4342
```
4443

4544
## Internal Data Organization

docs/docs/install/config/index.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,21 @@ A complete config file with all available options can be found [here](https://gi
5050
pyroscope: true
5151
```
5252

53-
### Process Tree
53+
### Stores (Process Tree and DNS Cache)
5454

55-
- **`--proctree` (`-t`)**: Controls process tree options.
55+
- **`--stores`**: Controls process tree and DNS cache options.
5656

5757

58-
__NOTE__: You can view more in the [Process Tree section](../../advanced/data-sources/builtin/process-tree.md).
58+
__NOTE__: You can view more in the [Process Tree section](../../advanced/data-sources/builtin/process-tree.md) and [DNS Cache section](../../advanced/data-sources/builtin/dns.md).
5959

6060
YAML:
6161
```yaml
62-
proctree:
63-
- process
62+
stores:
63+
process:
64+
enabled: true
65+
source: both
66+
dns:
67+
enabled: true
6468
```
6569

6670
### Install Path
@@ -109,17 +113,6 @@ A complete config file with all available options can be found [here](https://gi
109113
socket: /var/run/docker.sock
110114
```
111115

112-
### DNS Cache
113-
114-
- **`--dnscache`**: Enables DNS caching in Tracee.
115-
116-
__NOTE__: You can view more in the [DNS Cache section](../../advanced/data-sources/builtin/dns.md).
117-
118-
YAML:
119-
```yaml
120-
dnscache: enable
121-
```
122-
123116
### Capabilities
124117

125118
- **`--capabilities` (`-C`)**: Define specific capabilities for Tracee to run with. This allows you to either bypass, add, or drop certain capabilities based on your security and operational needs.

docs/docs/policies/usage/cli.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ signatures-dir: ""
6767

6868
capabilities:
6969
bypass: false
70-
proctree:
71-
source: both
72-
cache:
73-
process: 8192
74-
thread: 8192
70+
stores:
71+
process:
72+
enabled: true
73+
source: both
74+
processes: 8192
75+
threads: 8192
76+
dns:
77+
enabled: false
7578

7679
# logging
7780

examples/config/global_config.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
"cache": [
44
"none"
55
],
6-
"proctree": [
7-
"none"
8-
],
6+
"stores": {
7+
"process": {
8+
"enabled": false,
9+
"source": "none"
10+
},
11+
"dns": {
12+
"enabled": false
13+
}
14+
},
915
"capabilities": [],
1016
"containers": [],
1117
"healthz": false,

examples/config/global_config.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ policy:
1212
- /path/to/policy.yaml
1313
#- /path/to/policy-directory
1414

15-
proctree:
16-
source: none
17-
# cache:
18-
# process: 8192
19-
# thread: 4096
15+
stores:
16+
process:
17+
enabled: false
18+
source: none
19+
# processes: 8192
20+
# threads: 4096
21+
dns:
22+
enabled: false
23+
# size: 5000
2024

2125
capabilities:
2226
bypass: false
@@ -35,7 +39,6 @@ server:
3539
healthz: true
3640
pprof: true
3741
pyroscope: true
38-
dnscache: enable
3942

4043
containers:
4144
enrich: false

pkg/cmd/cobra/cobra.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,19 @@ func GetTraceeRunner(c *cobra.Command, version string) (cmd.Runner, error) {
141141
cfg.CgroupFSPath = res.CgroupfsPath
142142
cfg.CgroupFSForce = res.CgroupfsForce
143143

144-
// Process Tree command line flags
145-
146-
procTreeFlags, err := flags.GetFlagsFromViper("proctree")
147-
if err != nil {
148-
return runner, err
149-
}
150-
151-
procTree, err := flags.PrepareProcTree(procTreeFlags)
152-
if err != nil {
153-
return runner, err
154-
}
155-
cfg.ProcTree = procTree
156-
157-
// DNS Cache command line flags
158-
159-
dnsCacheFlags, err := flags.GetFlagsFromViper("dnscache")
144+
// Stores command line flags
145+
storesFlags, err := flags.GetFlagsFromViper(flags.StoresFlag)
160146
if err != nil {
161147
return runner, err
162148
}
163149

164-
dnsCache, err := flags.PrepareDnsCache(dnsCacheFlags)
150+
stores, err := flags.PrepareStores(storesFlags)
165151
if err != nil {
166152
return runner, err
167153
}
168154

169-
cfg.DNSCacheConfig = dnsCache
155+
cfg.ProcTree = stores.GetProcTreeConfig()
156+
cfg.DNSCacheConfig = stores.GetDNSCacheConfig()
170157

171158
// Capture command line flags - via cobra flag
172159

pkg/cmd/flags/config.go

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ func GetFlagsFromViper(key string) ([]string, error) {
2424
switch key {
2525
case serverflag.ServerFlag:
2626
flagger = &ServerConfig{}
27-
case "proctree":
28-
flagger = &ProcTreeConfig{}
2927
case "capabilities":
3028
flagger = &CapabilitiesConfig{}
3129
case "containers":
@@ -34,8 +32,8 @@ func GetFlagsFromViper(key string) ([]string, error) {
3432
flagger = &LogConfig{}
3533
case "output":
3634
flagger = &OutputConfig{}
37-
case "dnscache":
38-
flagger = &DnsCacheConfig{}
35+
case "stores":
36+
flagger = &StoresConfig{}
3937
default:
4038
return nil, errfmt.Errorf("unrecognized key: %s", key)
4139
}
@@ -160,64 +158,6 @@ func (c *SocketConfig) flags() []string {
160158
return flags
161159
}
162160

163-
//
164-
// proctree flag
165-
//
166-
167-
type ProcTreeConfig struct {
168-
Source string `mapstructure:"source"`
169-
Cache ProcTreeCacheConfig `mapstructure:"cache"`
170-
}
171-
172-
type ProcTreeCacheConfig struct {
173-
Process int `mapstructure:"process"`
174-
Thread int `mapstructure:"thread"`
175-
}
176-
177-
func (c *ProcTreeConfig) flags() []string {
178-
flags := make([]string, 0)
179-
180-
if c.Source != "" {
181-
if c.Source == "none" {
182-
flags = append(flags, "none")
183-
} else {
184-
flags = append(flags, fmt.Sprintf("source=%s", c.Source))
185-
}
186-
}
187-
if c.Cache.Process != 0 {
188-
flags = append(flags, fmt.Sprintf("process-cache=%d", c.Cache.Process))
189-
}
190-
if c.Cache.Thread != 0 {
191-
flags = append(flags, fmt.Sprintf("thread-cache=%d", c.Cache.Thread))
192-
}
193-
194-
return flags
195-
}
196-
197-
//
198-
// dnscache flag
199-
//
200-
201-
type DnsCacheConfig struct {
202-
Enable bool `mapstructure:"enable"`
203-
Size int `mapstructure:"size"`
204-
}
205-
206-
func (c *DnsCacheConfig) flags() []string {
207-
flags := make([]string, 0)
208-
209-
if !c.Enable {
210-
flags = append(flags, "none")
211-
return flags
212-
}
213-
214-
if c.Size != 0 {
215-
flags = append(flags, fmt.Sprintf("size=%d", c.Size))
216-
}
217-
218-
return flags
219-
}
220-
221161
//
222162
// capabilities flag
223163
//

0 commit comments

Comments
 (0)