1
- # exectrace [ ![ Go Reference] ( https://pkg.go.dev/badge/cdr.dev/ exectrace.svg )] ( https://pkg.go.dev/cdr.dev /exectrace )
1
+ # exectrace [ ![ Go Reference] ( https://pkg.go.dev/badge/github.com/coder/ exectrace.svg )] ( https://pkg.go.dev/github.com/coder /exectrace )
2
2
3
- Simple [ eBPF] ( https://ebpf.io/ ) -based exec snooping on Linux, packaged as a Go
3
+ Simple [ eBPF] ( https://ebpf.io/ ) -based exec snooping on Linux packaged as a Go
4
4
library.
5
5
6
- exectrace loads a precompiled [ eBPF program] ( ./bpf/handler.c ) into the running
6
+ exectrace loads a pre-compiled [ eBPF program] ( ./bpf/handler.c ) into the running
7
7
kernel to receive details about the ` exec ` family of syscalls.
8
8
9
- ## Installation
9
+ ## Requirements
10
10
11
- exectrace only support Go 1.16+ and Linux kernel 5.8+ (due to use of
11
+ exectrace only supports Go 1.16+ and Linux kernel 5.8+ (due to the use of
12
12
` BPF_MAP_TYPE_RINGBUF ` ).
13
13
14
- ```
15
- $ go get -u cdr.dev/exectrace
14
+ ## Installation
15
+
16
+ ``` console
17
+ $ go get -u github.com/coder/exectrace
16
18
```
17
19
18
- ## Quick Start
20
+ ## Quickstart
19
21
20
- You will need root access, ` CAP_SYS_ADMIN ` or ` CAP_BPF ` to run eBPF programs on
22
+ You will need root access, ` CAP_SYS_ADMIN ` or ` CAP_BPF ` , to run eBPF programs on
21
23
your system.
22
24
23
- > tip: you can use ` go run -exec sudo ./cmd/program ` to compile a program and
25
+ > Use ` go run -exec sudo ./cmd/program ` to compile a program and
24
26
> start it with ` sudo `
25
27
26
- ```
27
- $ go install -u cdr.dev /exectrace/cmd/exectrace
28
+ ``` console
29
+ $ go install -u github.com/coder /exectrace/cmd/exectrace
28
30
$ exectrace --help
29
31
...
30
32
31
33
$ sudo exectrace
32
34
2021/12/01 16:42:02 Waiting for events..
33
- [1188921, comm="node"] /bin/sh -c 'which ps'
34
- [1188922, comm="sh"] which ps
35
+ [1188921, comm="node", uid=1002, gid=1003 ] /bin/sh -c 'which ps'
36
+ [1188922, comm="sh", uid=1002, gid=1003 ] which ps
35
37
```
36
38
37
39
## Usage
38
40
39
- You can look at the example program [ exectrace] ( ./cmd/exectrace/main.go ) for a
40
- comprehensive program using this library.
41
+ exectrace exposes a minimal API surface. Call ` exectrace.New(nil) ` and then
42
+ you can start reading events from the returned ` Tracer ` .
43
+
44
+ It is important that you close the tracer to avoid leaking kernel resources,
45
+ so we recommend implementing a simple signal handler like the one in this
46
+ example:
47
+
48
+ ``` go
49
+ package main
50
+
51
+ import (
52
+ " fmt"
53
+ " os"
54
+ " os/signal"
55
+ " syscall"
56
+
57
+ " github.com/coder/exectrace"
58
+ )
59
+
60
+ func main () {
61
+ tracer , err := exectrace.New (nil )
62
+ if err != nil {
63
+ panic (err)
64
+ }
65
+ defer tracer.Close ()
66
+
67
+ go func () {
68
+ sigs := make (chan os.Signal , 1 )
69
+ signal.Notify (sigs, syscall.SIGINT , syscall.SIGTERM )
70
+ <- sigs
71
+ tracer.Close ()
72
+ }()
73
+
74
+ for {
75
+ event , err := tracer.Read ()
76
+ if err != nil {
77
+ panic (err)
78
+ }
79
+
80
+ fmt.Printf (" %+v \n " , event)
81
+ }
82
+ }
83
+ ```
41
84
42
- ## Development
85
+ > For a full usage example, refer to this [ comprehensive program] ( ./cmd/exectrace/main.go )
86
+ > that uses the library.
43
87
44
- Since the eBPF program is packaged as a Go library, the program needs to be
45
- compiled and included in the repo. If you make changes to files under the ` bpf `
46
- directory, you should run ` make ` and include the ` .o ` files in that directory in
47
- your commit if they changed. CI will ensure that this is done correctly.
88
+ ## Development
48
89
49
- You will probably need the following tools :
90
+ You will need the following:
50
91
51
- - Docker (clang is run within a Docker container for reproducibility)
92
+ - Docker (the Makefile runs clang within a Docker container for reproducibility)
52
93
- ` golangci-lint `
53
94
- ` prettier `
54
95
- ` shellcheck `
55
96
56
- ## Status: In Development
97
+ Since the eBPF program is packaged as a Go library, you need to compile the
98
+ program and include it in the repo.
99
+
100
+ If you change the files in the ` bpf ` directory, run ` make ` and ensure that you
101
+ include the ` .o ` files you changed in your commit (CI will verify that you've
102
+ done this correctly).
103
+
104
+ ## Status: beta
57
105
58
- The library is currently under heavy development as we develop it out to suit
59
- the needs of Coder's enterprise [ product] ( https://coder.com ) .
106
+ This library is ready to use as-is, though it is under active development as we
107
+ modify it to suit the needs of Coder's [ enterprise product] ( https://coder.com ) .
60
108
61
- We plan on changing the API to add more features and fields that can be read
62
- from, and potentially adding easier methods for filtering events rather than
63
- implementing filtering yourself.
109
+ We plan on adding more features and fields that can be read from the API, as
110
+ well as easier-to-use methods for filtering events (currently, you must
111
+ implement additional filtering yourself) .
64
112
65
- ## See Also
113
+ ## See also
66
114
67
115
- [ ` canonical/etrace ` ] ( https://github.com/canonical/etrace ) - Go binary that
68
116
uses ptrace and tracks the processes that a command launches for debugging and
@@ -72,4 +120,4 @@ implementing filtering yourself.
72
120
73
121
---
74
122
75
- Dual licensed under the MIT and GPL- 2.0 licenses. See [ LICENSE] ( LICENSE ) .
123
+ Dual licensed under the MIT and GPL 2.0 licenses. See [ LICENSE] ( LICENSE ) .
0 commit comments