On Linux each process has various associated user, group IDs, capabilities,
secure management flags, keyring, LSM security that are used part of the
security checks upon acting on other objects. These are called the task
privileges or
process credentials.
Changing the process credentials is a standard operation to perform privileged
actions or to execute commands as another user. The obvious example is
sudo that allows to gain high privileges and run commands
as root or another user. An other example is services or containers that can
gain high privileges during execution to perform restricted operations.
Composition of Linux process credentials
Traditional UNIX credentials
Real User ID
Real Group ID
Effective, Saved and FS User ID
Effective, Saved and FS Group ID
Supplementary groups
Linux Capabilities
Set of permitted capabilities: a limiting superset for the effective
capabilities.
Set of inheritable capabilities: the set that may get passed across
execve(2).
Set of effective capabilities: the set of capabilities a task is actually
allowed to make use of itself.
Set of bounding capabilities: limits the capabilities that may be inherited
across execve(2), especially when a binary is executed that will execute as
UID 0.
Secure management flags (securebits).
These govern the way the UIDs/GIDs and capabilities are manipulated and
inherited over certain operations such as execve(2).
Linux Security Module (LSM)
The LSM framework
provides a mechanism for various security checks to be hooked by new kernel
extensions. Tasks can have extra controls part of LSM on what operations they
are allowed to perform.
Tetragon Process Credentials monitoring
Monitoring Linux process credentials is a good practice to idenfity programs
running with high privileges. Tetragon allows retrieving Linux process credentials
as a process_credentials object.
1 - Monitor Process Credentials changes at the System Call layer
Monitor system calls that change Process Credentials
Tetragon can hook at the system calls that directly manipulate the credentials.
This allows us to determine which process is trying to change its credentials
and the new credentials that could be applied by the kernel.
This answers the questions:
Which process or container is trying to change its UIDs/GIDs in my cluster?
Which process or container is trying to change its capabilities in my
cluster?
Before going forward, verify that all pods are up and running, ensure you
deploy our Demo Application to explore the Security Observability Events:
In addition to the Kubernetes Identity and process metadata from exec events,
ProcessKprobe
events contain the arguments of the observed system call. In the above case
they are:
function_name: the system call, __x64_sys_setuid or
__x64_sys_setgid
int_arg: the uid or gid to use, in our case it’s 0 which corresponds to
the root user.
2 - Monitor Process Credentials changes at the Kernel layer
Monitor Process Credentials changes at the kernel layer
Monitoring Process Credentials changes at the kernel layer is also possible.
This allows to capture the new process_credentials that should be applied.
In addition to the Kubernetes Identity and process metadata from exec events, ProcessKprobe events contain the arguments of the observed system call. In the above case they are:
function_name: the kernel commit_creds() function to install new credentials.
process_credentials_arg: the new process_credentials to be installed
on the current process. It includes the UIDs/GIDs, the capabilities and the target user namespace.
Here we can clearly see that the suid binary is being executed by a user ID 11 in order to elevate its privileges to user ID 0 including capabilities.