Fix exe path finding

This commit is contained in:
M. Mert Yildiran 2022-05-30 23:27:19 +03:00
parent fcb7663b99
commit efc81b9baf
No known key found for this signature in database
GPG Key ID: D42ADB236521BF7A
8 changed files with 17 additions and 23 deletions

View File

@ -90,7 +90,6 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mertyildiran/gqlparser/v2 v2.4.6 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect

View File

@ -509,8 +509,6 @@ github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceT
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=

View File

@ -8,7 +8,6 @@ require (
github.com/go-errors/errors v1.4.2
github.com/google/gopacket v1.1.19
github.com/hashicorp/golang-lru v0.5.4
github.com/mitchellh/go-ps v1.0.0
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/struCoder/pidusage v0.2.1
github.com/up9inc/mizu/logger v0.0.0

View File

@ -93,8 +93,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

View File

@ -287,7 +287,7 @@ func startTlsTapper(extension *api.Extension, outputItems chan *api.OutputChanne
// A quick way to instrument Go `crypto/tls` without PID filtering - used for debuging and troubleshooting
//
if os.Getenv("MIZU_GLOBAL_GOLANG_PID") != "" {
if err := tls.GlobalGolangTap(os.Getenv("MIZU_GLOBAL_GOLANG_PID")); err != nil {
if err := tls.GlobalGolangTap(*procfs, os.Getenv("MIZU_GLOBAL_GOLANG_PID")); err != nil {
tlstapper.LogError(err)
return nil
}

View File

@ -81,6 +81,8 @@ func (p *tlsPoller) init(bpfObjects *tlsTapperObjects, bufferSize int) error {
return errors.Wrap(err, 0)
}
p.golangReadWriteMap = orderedmap.New()
return nil
}

View File

@ -32,7 +32,7 @@ func UpdateTapTargets(tls *TlsTapper, pods *[]v1.Pod, procfs string) error {
LogError(err)
}
if err := tls.AddGolangPid(pid, pod.Namespace); err != nil {
if err := tls.AddGolangPid(procfs, pid, pod.Namespace); err != nil {
LogError(err)
}
}

View File

@ -1,12 +1,13 @@
package tlstapper
import (
"fmt"
"os"
"strconv"
"sync"
"github.com/cilium/ebpf/rlimit"
"github.com/go-errors/errors"
ps "github.com/mitchellh/go-ps"
"github.com/up9inc/mizu/logger"
"github.com/up9inc/mizu/tap/api"
)
@ -72,18 +73,17 @@ func (t *TlsTapper) GlobalSsllibTap(sslLibrary string) error {
return t.tapSsllibPid(GLOABL_TAP_PID, sslLibrary, api.UNKNOWN_NAMESPACE)
}
func (t *TlsTapper) GlobalGolangTap(_pid string) error {
pid, err := strconv.Atoi(_pid)
func (t *TlsTapper) GlobalGolangTap(procfs string, pid string) error {
_pid, err := strconv.Atoi(pid)
if err != nil {
return err
}
p, err := ps.FindProcess(pid)
if err != nil {
return err
}
return t.tapGolangPid(uint32(pid), p.Executable(), api.UNKNOWN_NAMESPACE)
return t.tapGolangPid(procfs, uint32(_pid), api.UNKNOWN_NAMESPACE)
}
func (t *TlsTapper) AddSsllibPid(procfs string, pid uint32, namespace string) error {
@ -97,15 +97,8 @@ func (t *TlsTapper) AddSsllibPid(procfs string, pid uint32, namespace string) er
return t.tapSsllibPid(pid, sslLibrary, namespace)
}
func (t *TlsTapper) AddGolangPid(pid uint32, namespace string) error {
p, err := ps.FindProcess(int(pid))
if err != nil {
logger.Log.Infof("PID skipped not found (pid: %d) %v", pid, err)
return nil
}
return t.tapGolangPid(pid, p.Executable(), namespace)
func (t *TlsTapper) AddGolangPid(procfs string, pid uint32, namespace string) error {
return t.tapGolangPid(procfs, pid, namespace)
}
func (t *TlsTapper) RemovePid(pid uint32) error {
@ -198,7 +191,12 @@ func (t *TlsTapper) tapSsllibPid(pid uint32, sslLibrary string, namespace string
return nil
}
func (t *TlsTapper) tapGolangPid(pid uint32, exePath string, namespace string) error {
func (t *TlsTapper) tapGolangPid(procfs string, pid uint32, namespace string) error {
exePath, err := os.Readlink(fmt.Sprintf("%s/%d/exe", procfs, pid))
if err != nil {
return err
}
hooks := golangHooks{}
if err := hooks.installUprobes(&t.bpfObjects, exePath); err != nil {