trace_rename
The trace_rename gadget emits an event each time a process successfully renames a file or directory with rename, renameat or renameat2.
Requirements
- Minimum Kernel Version: 5.4
- The
--pathsflag relies on thesecurity_path_renameLSM hook, so it needs a kernel built withCONFIG_SECURITY_PATH=y. Without--pathsthe gadget only uses syscall tracepoints.CONFIG_SECURITY_PATHis selected by AppArmor, TOMOYO and Landlock but not by SELinux, so kernels that enable only SELinux may not have it. On those kernels--pathsis not available and only the names as passed to the syscall are reported, which may be relative.
Getting started
Running the gadget:
- kubectl gadget
- ig
$ kubectl gadget run ghcr.io/inspektor-gadget/gadget/trace_rename:latest [flags]
$ sudo ig run ghcr.io/inspektor-gadget/gadget/trace_rename:latest [flags]
Flags
--paths
Show absolute old and new paths (requires CONFIG_SECURITY_PATH)
Default value: "false"
Guide
Each event includes:
oldnameandnewname: the names exactly as passed to the syscall. They can be relative to the current directory or to a directory file descriptor.oldpathandnewpath: the absolute paths, only with--paths. These columns are hidden by default.flags: therenameat2flags (RENAME_NOREPLACE,RENAME_EXCHANGE,RENAME_WHITEOUT).
Failed renames don't produce events.
First, we need to run an application that generates some events.
- kubectl gadget
- ig
$ kubectl run --restart=Never --image=busybox rename-demo -- \
sh -c 'while true; do touch /tmp/a; mv /tmp/a /tmp/b; rm -f /tmp/b; sleep 2; done'
pod/rename-demo created
$ docker run --name test-trace-rename -d --rm busybox /bin/sh -c 'while true; do touch /tmp/a; mv /tmp/a /tmp/b; rm -f /tmp/b; sleep 2; done'
Then, let's run the gadget:
- kubectl gadget
- ig
$ kubectl gadget run trace_rename:latest --podname rename-demo
$ sudo ig run trace_rename:latest --containername test-trace-rename
Example output:
RUNTIME.CONTAINERNAME COMM PID TID FLAGS OLDNAME NEWNAME
test-trace-rename mv 2457670 2457670 /tmp/a /tmp/b
test-trace-rename mv 2457687 2457687 /tmp/a /tmp/b
test-trace-rename mv 2457711 2457711 /tmp/a /tmp/b
test-trace-rename mv 2457727 2457727 /tmp/a /tmp/b
Use --paths together with --fields to see the absolute paths:
$ sudo ig run trace_rename:latest --containername test-trace-rename --paths --fields comm,oldname,newname,oldpath,newpath
Finally, clean the system:
- kubectl gadget
- ig
$ kubectl delete pod rename-demo
$ docker rm -f test-trace-rename
Limitations
- Renames done through io_uring (
IORING_OP_RENAMEAT) don't go through the rename syscalls, so this gadget doesn't see them. - Names and paths longer than 511 bytes are truncated. This applies to real paths too, which can be up to 4095 bytes (
PATH_MAX).