Skip to content

Commit

Permalink
tetragon: library policy module load audit
Browse files Browse the repository at this point in the history
Signed-off-by: John Fastabend <[email protected]>
  • Loading branch information
jrfastab committed Nov 1, 2023
1 parent 5304510 commit ca9fcf1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
13 changes: 11 additions & 2 deletions docs/content/en/docs/policy-library/observability/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ Understanding exactly what kernel modules are running in the cluster is crucial
### Example jq Filter

```shell-session
jq 'select(.process_kprobe != null) | select(.process_kprobe.function_name | test("security_kernel_module_request")) | "\(.time) \(.process_kprobe.process.binary) \(.process_kprobe.process.arguments) module:\(.process_kprobe.args[0].string_arg)"'
```

### Example Output

```shell-session
"2023-11-01T04:11:38.390880528Z /sbin/iptables -A OUTPUT -m cgroup --cgroup 1 -j LOG module:ipt_LOG"
```

## Shared Library Loading {#library}
Expand Down Expand Up @@ -159,7 +160,6 @@ jq 'select(.process_exec != null) | select(.process_exec.process.binary | contai
"2023-10-31T19:03:35.273111185Z null /usr/bin/sudo -i"
```


## SSHd connection monitoring {#ssh-network}

### Description
Expand All @@ -176,7 +176,14 @@ It is best practice to audit remote connections into a shell server.

### Example jq Filter

```shell-session
jq 'select(.process_kprobe != null) | select(.process_kprobe.function_name | test("tcp_close")) | "\(.time) \(.process_kprobe.process.binary) \(.process_kprobe.process.arguments) \(.process_kprobe.args[0].sock_arg.family) \(.process_kprobe.args[0].sock_arg.type) \(.process_kprobe.args[0].sock_arg.protocol) \(.process_kprobe.args[0].sock_arg.saddr):\(.process_kprobe.args[0].sock_arg.sport)"'
```

### Example Output
```shell-session
"2023-11-01T04:51:20.109146920Z /usr/sbin/sshd default/xwing AF_INET SOCK_STREAM IPPROTO_TCP 127.0.0.1:22"
```

## Outbound connections {#egress-connections}

Expand All @@ -191,6 +198,8 @@ into any unexpected or malicious reverse shells.

### Policy

[egress.yaml](https://raw.githubusercontent.com/cilium/tetragon/main/examples/policylibrary/egress.yaml)

### Example jq Filter

### Example Output
37 changes: 37 additions & 0 deletions examples/policylibrary/modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This tracing policy monitors kernel modules operations.
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: "monitor-kernel-modules"
#annotations:
#description: "Monitor kernel modules operations"
spec:
kprobes:
- call: "security_kernel_module_request"
# Automatic module loading detection
syscall: false
return: true
args:
- index: 0
type: "string"
returnArg:
index: 0
type: "int"
- call: "security_kernel_read_file"
# Explicit module loading using file descriptor finit_module() to print module full path
syscall: false
return: true
args:
- index: 0
type: "file"
- index: 1
type: "int"
returnArg:
index: 0
type: "int"
selectors:
- matchArgs:
- index: 1
operator: "Equal"
values:
- "2" # READING_MODULE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ kind: TracingPolicy
metadata:
name: "accept"
spec:
options:
- name: "disable-kprobe-multi"
value: "1"
kprobes:
- call: "sk_alloc"
syscall: false
Expand All @@ -24,7 +27,7 @@ spec:
matchBinaries:
- operator: "In"
values:
- "/usr/bin/sshd"
- "/usr/sbin/sshd"
- "/usr/sbin/tcpserver"
- call: "sk_free"
syscall: false
Expand All @@ -37,14 +40,14 @@ spec:
operator: "Family"
values:
- "AF_INET"
matchActions:
- action: UntrackSock
argSock: 0
matchBinaries:
- operator: "In"
values:
- "/usr/bin/sshd"
- "/usr/sbin/sshd"
- "/usr/sbin/tcpserver"
matchActions:
- action: UntrackSock
argSock: 0
- call: "tcp_set_state"
syscall: false
args:
Expand All @@ -66,7 +69,7 @@ spec:
matchBinaries:
- operator: "In"
values:
- "/usr/bin/sshd"
- "/usr/sbin/sshd"
- "/usr/sbin/tcpserver"
- call: "tcp_close"
syscall: false
Expand All @@ -87,5 +90,5 @@ spec:
- matchBinaries:
- operator: "In"
values:
- "/usr/bin/sshd"
- "/usr/sbin/sshd"
- "/usr/sbin/tcpserver"

0 comments on commit ca9fcf1

Please sign in to comment.