This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Enforcement

Documentation for Tetragon enforcement system

Tetragon allows enforcing events in the kernel inline with the operation itself. This document describes the types of enforcement provided by Tetragon and concerns policy implementors must be aware of.

There are two ways that Tetragon performs enforcement: overriding the return value of a function and sending a signal (e.g., SIGKILL) to the process.

Override return value

Override the return value of a call means that the function will never be executed and, instead, a value (typically an error) will be returned to the caller. Generally speaking, only system calls and security check functions allow to change their return value in this manner. Details about how users can configure tracing policies to override the return value can be found in the Override action documentation.

Signals

Another type of enforcement is signals. For example, users can write a TracingPolicy (details can be found in the Signal action documentation) that sends a SIGKILL to a process matching certain criteria and thus terminate it.

In contrast with overriding the return value, sending a SIGKILL signal does not always stop the operation being performed by the process that triggered the operation. For example, a SIGKILL sent in a write() system call does not guarantee that the data will not be written to the file. However, it does ensure that the process is terminated synchronously (and any threads will be stopped). In some cases it may be sufficient to ensure the process is stopped and the process does not handle the return of the call. To ensure the operation is not completed, though, the Signal action should be combined with the Override action.

1 - Persistent enforcement

How to configure persistent enforcement

This page shows you how to configure persistent enforcement.

Concept

The idea of persistent enforcement is to allow the enforcement policy to continue running even when its tetragon process is gone.

This is configured with the --keep-sensors-on-exit option.

When the tetragon process exits, the policy stays active because it’s pinned in sysfs bpf tree under /sys/fs/bpf/tetragon directory.

When a new tetragon process is started, it performs the following actions:

  • checks if there’s existing /sys/fs/bpf/tetragon and moves it to /sys/fs/bpf/tetragon_old directory;
  • sets up configured policy;
  • removes /sys/fs/bpf/tetragon_old directory.

Example

This example shows how the persistent enforcement works on simple tracing policy.

  1. Consider the following enforcement tracing policy that kills any process that touches /tmp/tetragon file.

    apiVersion: cilium.io/v1alpha1
    kind: TracingPolicy
    metadata:
     name: "enforcement"
    spec:
     kprobes:
     - call: "fd_install"
       syscall: false
       args:
       - index: 0
         type: int
       - index: 1
         type: "file"
       selectors:
       - matchArgs:
         - index: 1
           operator: "Equal"
           values:
           - "/tmp/tetragon"
         matchActions:
         - action: Sigkill
    
  2. Spawn tetragon with the above policy and --keep-sensors-on-exit option.

    tetragon --bpf-lib bpf/objs/ --keep-sensors-on-exit --tracing-policy enforcement.yaml
    
  3. Verify that the enforcement policy is in place.

    cat /tmp/tetragon
    

    The output should be similar to

    Killed
    
  4. Kill tetragon with CTRL+C.

    time="2024-07-26T14:47:45Z" level=info msg="Perf ring buffer size (bytes)" percpu=68K total=272K
    time="2024-07-26T14:47:45Z" level=info msg="Perf ring buffer events queue size (events)" size=63K
    time="2024-07-26T14:47:45Z" level=info msg="Listening for events..."
    ^C
    time="2024-07-26T14:50:50Z" level=info msg="Received signal interrupt, shutting down..."
    time="2024-07-26T14:50:50Z" level=info msg="Listening for events completed." error="context canceled"
    
  5. Verify that the enforcement policy is STILL in place.

    cat /tmp/tetragon
    

    The output should be still similar to

    Killed
    

Limitations

At the moment we are not able to receive any events during the tetragon down time, only the the enforcement is in place.