process

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 42 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProcessInfoMissing = errors.New("failed process info missing")
)

Functions

func DumpProcessCache added in v1.2.1

func DumpProcessCache(opts *tetragon.DumpProcessCacheReqArgs) []*tetragon.ProcessInternal

func FreeCache

func FreeCache()

func GetCacheEntries added in v1.4.0

func GetCacheEntries() []*tetragon.ProcessInternal

This function returns the process cache entries (and not the copies of them as opposed to dump function). Thus any changes to the return value results in affecting the process cache entries. The exception is RefcntOps, which is a snapshot of the counters. This is mainly for tests where we want to check the values of the process cache.

func GetExecID

func GetExecID(proc *tetragonAPI.MsgProcess) string

func GetExecIDFromKey

func GetExecIDFromKey(key *tetragonAPI.MsgExecveKey) string

func GetParentProcessInternal

func GetParentProcessInternal(pid uint32, ktime uint64) (*ProcessInternal, *ProcessInternal)

func GetPodInfo

func GetPodInfo(containerID, bin, args string, nspid uint32) *tetragon.Pod

GetPodInfo constructs and returns the Kubernetes Pod information associated with an event.

func GetProcessID

func GetProcessID(pid uint32, ktime uint64) string

func InitCache

func InitCache(ctx context.Context, w watcher.PodAccessor, size int, GCInterval time.Duration) error

func RegisterMetrics added in v1.2.0

func RegisterMetrics(group metrics.Group)

func SetK8sWatcher added in v1.8.0

func SetK8sWatcher(w watcher.PodAccessor)

SetK8sWatcher sets the k8s watcher used to retrieve pod metadata for processes. This is independent of the process cache, so callers should invoke it even when the process cache is disabled (e.g. via --disable-process-cache) to ensure pod info is still attached to events.

func UpdateEventProcessTid added in v0.10.0

func UpdateEventProcessTid(process *tetragon.Process, tid *uint32)

UpdateEventProcessTID Updates the Process.Tid of the event on the fly.

From BPF side as we track processes by their TGID we do not cache TIDs, this is done on purpose since we only track clone and execve where TGID == TID, and also to simplify things. From user space perspective this works in general without any problem especially for execve events. A cached process (user space procCache) will always have its TGID == TID.

However for other events we want to be precise and report the right thread that triggered an event. For such cases call this helper to set the Process.Tid to the corresponding thread ID that was reported from BPF side.

There is no point on calling this helper on clone or execve events, however on all other events it is perfectly fine.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache(
	ctx context.Context,
	processCacheSize int,
	GCInterval time.Duration,
) (*Cache, error)

type ProcessInternal

type ProcessInternal struct {
	// contains filtered or unexported fields
}

ProcessInternal is the internal representation of a process. nolint:revive // This is an acceptable case of "stuttering" since the name "Internal" wouldn't make much sense by itself.

func AddCloneEvent

func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) (*ProcessInternal, error)

AddCloneEvent adds a new process into the cache from a CloneEvent

func AddExecEvent

func AddExecEvent(event *tetragonAPI.MsgExecveEventUnix) *ProcessInternal

AddExecEvent constructs a new ProcessInternal structure from an Execve event, adds it to the cache, and also returns it

func Get

func Get(execId string) (*ProcessInternal, error)

func GetAncestorProcessesInternal added in v1.4.0

func GetAncestorProcessesInternal(execId string) ([]*ProcessInternal, error)

GetAncestorProcessesInternal returns a slice, representing a continuous sequence of ancestors of the process up to init process (PID 1) or kthreadd (PID 2), including the immediate parent.

func (*ProcessInternal) AddPodInfo

func (pi *ProcessInternal) AddPodInfo(pod *tetragon.Pod)

func (*ProcessInternal) AnnotateProcess

func (pi *ProcessInternal) AnnotateProcess(cred, ns bool) error

func (*ProcessInternal) ClaimParentRefcntDecrease added in v1.8.0

func (pi *ProcessInternal) ClaimParentRefcntDecrease() bool

ClaimParentRefcntDecrease marks the parent reference of pi as released and reports whether this call is the one that released it. Callers must only decrease the parent reference count when it returns true.

func (*ProcessInternal) GetProcessCopy

func (pi *ProcessInternal) GetProcessCopy() *tetragon.Process

GetProcessCopy() duplicates tetragon.Process and returns it

func (*ProcessInternal) NeededAncestors added in v1.4.0

func (pi *ProcessInternal) NeededAncestors() bool

func (*ProcessInternal) RefDec

func (pi *ProcessInternal) RefDec(reason RefReason)

func (*ProcessInternal) RefGet

func (pi *ProcessInternal) RefGet() uint32

func (*ProcessInternal) RefInc

func (pi *ProcessInternal) RefInc(reason RefReason)

func (*ProcessInternal) UnsafeGetProcess

func (pi *ProcessInternal) UnsafeGetProcess() *tetragon.Process

func (*ProcessInternal) UpdateExecOutsideCache added in v1.0.0

func (pi *ProcessInternal) UpdateExecOutsideCache(cred bool) (*tetragon.Process, bool)

UpdateExecOutsideCache() checks if we must augment the ProcessExec.Process with more fields without propagating again those fields into the process cache. This means that those added fields will only show up for the returned ProcessExec.Process.

This is usually the case where we have the core information of the process that was handled directly or through some event cache retries, in all cases the ProcessInternal.process is properly set and referenced and can't disappear, so we don't take any locks here. It operates on the direct reference and if some fields have to be added then a deep copy will be performed.

Returns:

  1. The updated Process in case of new or updated fields, otherwise the old same Process reference.
  2. A boolean to indicate if a process information update was performed

Current rules to make a copy and add fields for Process part of ProcessExec event are:

  1. process_exec.process.binary_properties: a. if it is a setuid execution b. if it is a setgid execution c. if it is a filesystem capability execution d. Execution of an unlinked binary (shm, memfd, or deleted binaries)

    a b and c are subject to the --enable-process-cred flag

type RefReason added in v1.8.0

type RefReason uint32
const (
	RefProcess RefReason = iota
	RefParent
	RefAncestor
)

func NewRefReason added in v1.8.0

func NewRefReason(name string) RefReason

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL