Elkeid icon indicating copy to clipboard operation
Elkeid copied to clipboard

fix: os.Stat returns ENOENT when checking the symlink file's stat of …

Open z0brk opened this issue 2 years ago • 0 comments

fixed os.Stat returns ENOENT when checking the symlink file's stat of a container using /proc/*/root.

Summary

This PR fixes/implements the following bugs/features

  • [ ] Bug os.Stat returns ENOENT when checking the symlink file's stat of a container using /proc/*/root

Test plan (required)

  1. run mysql:5.7.31 image on host with collector running
docker run -e MYSQL_ROOT_PASSWORD=abc12345 mysql@sha256:b3dc8d10307ab7b9ca1a7981b1601a67e176408be618fc4216d137be37dae10b
  1. Collector's AppRule of mysql checking file /etc/mysql/my.cnf symlinked to /etc/alternatives/my.cnf
root@601d2bfcb7e3:~# stat /etc/mysql/my.cnf
  File: /etc/mysql/my.cnf -> /etc/alternatives/my.cnf
  Size: 24              Blocks: 0          IO Block: 4096   symbolic link
Device: 40h/64d Inode: 4748407     Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-10-13 08:03:29.000000000 +0000
Modify: 2020-10-13 08:03:29.000000000 +0000
Change: 2023-06-15 08:19:26.938384681 +0000
 Birth: -
root@601d2bfcb7e3:~# 

  1. check file's stat using os.Stat will return ENOENT, should be use os.Lstat to check symlink file in container, because file /etc/alternatives/my.cnf not available on host, see https://pkg.go.dev/os#Lstat for more infos.

z0brk avatar Jun 15 '23 10:06 z0brk