From e0a7a04543a390b8cba7c71b2d799bc08dd30128 Mon Sep 17 00:00:00 2001 From: "M. Mert Yildiran" Date: Mon, 30 May 2022 22:32:14 +0300 Subject: [PATCH] Add an environment variable to test Golang locally --- tap/passive_tapper.go | 17 +++++++++++++---- tap/tlstapper/tls_tapper.go | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/tap/passive_tapper.go b/tap/passive_tapper.go index 20d15a8a8..9b6e1e47b 100644 --- a/tap/passive_tapper.go +++ b/tap/passive_tapper.go @@ -14,9 +14,9 @@ import ( "fmt" "os" "runtime" + "strconv" "strings" "time" - "strconv" "github.com/shirou/gopsutil/cpu" "github.com/struCoder/pidusage" @@ -59,8 +59,8 @@ var tls = flag.Bool("tls", false, "Enable TLS tapper") var memprofile = flag.String("memprofile", "", "Write memory profile") type TapOpts struct { - HostMode bool - IgnoredPorts []uint16 + HostMode bool + IgnoredPorts []uint16 } var extensions []*api.Extension // global @@ -278,7 +278,16 @@ func startTlsTapper(extension *api.Extension, outputItems chan *api.OutputChanne // A quick way to instrument libssl.so without PID filtering - used for debuging and troubleshooting // if os.Getenv("MIZU_GLOBAL_SSL_LIBRARY") != "" { - if err := tls.GlobalTap(os.Getenv("MIZU_GLOBAL_SSL_LIBRARY")); err != nil { + if err := tls.GlobalSsllibTap(os.Getenv("MIZU_GLOBAL_SSL_LIBRARY")); err != nil { + tlstapper.LogError(err) + return nil + } + } + + // 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 { tlstapper.LogError(err) return nil } diff --git a/tap/tlstapper/tls_tapper.go b/tap/tlstapper/tls_tapper.go index 2f185eb9a..5b1b713f7 100644 --- a/tap/tlstapper/tls_tapper.go +++ b/tap/tlstapper/tls_tapper.go @@ -1,6 +1,7 @@ package tlstapper import ( + "strconv" "sync" "github.com/cilium/ebpf/rlimit" @@ -67,10 +68,24 @@ func (t *TlsTapper) PollForLogging() { t.bpfLogger.poll() } -func (t *TlsTapper) GlobalTap(sslLibrary string) error { +func (t *TlsTapper) GlobalSsllibTap(sslLibrary string) error { return t.tapLibsslPid(GLOABL_TAP_PID, sslLibrary, api.UNKNOWN_NAMESPACE) } +func (t *TlsTapper) GlobalGolangTap(_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) +} + func (t *TlsTapper) AddSsllibPid(procfs string, pid uint32, namespace string) error { sslLibrary, err := findSsllib(procfs, pid)