From 4e8d760a12f8caf124c1cea75ff319c548fb885d Mon Sep 17 00:00:00 2001 From: "M. Mert Yildiran" Date: Wed, 1 Jun 2022 17:30:29 +0300 Subject: [PATCH] Add `MIZU_GLOBAL_GOLANG_PATH` environment variable --- tap/passive_tapper.go | 9 +++++++++ tap/tlstapper/tls_tapper.go | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/tap/passive_tapper.go b/tap/passive_tapper.go index 3c7dd8ee4..3fa88ff33 100644 --- a/tap/passive_tapper.go +++ b/tap/passive_tapper.go @@ -293,6 +293,15 @@ func startTlsTapper(extension *api.Extension, outputItems chan *api.OutputChanne } } + // A quick way to instrument Go `crypto/tls` using executable path - used for debuging and troubleshooting + // + if os.Getenv("MIZU_GLOBAL_GOLANG_PATH") != "" { + if err := tls.GlobalGolangTapPath(os.Getenv("MIZU_GLOBAL_GOLANG_PATH")); err != nil { + tlstapper.LogError(err) + return nil + } + } + var emitter api.Emitter = &api.Emitting{ AppStats: &diagnose.AppStats, OutputChannel: outputItems, diff --git a/tap/tlstapper/tls_tapper.go b/tap/tlstapper/tls_tapper.go index 29fcd3e0b..c898d5dd9 100644 --- a/tap/tlstapper/tls_tapper.go +++ b/tap/tlstapper/tls_tapper.go @@ -86,6 +86,10 @@ func (t *TlsTapper) GlobalGolangTap(procfs string, pid string) error { return t.tapGolangPid(procfs, uint32(_pid), api.UNKNOWN_NAMESPACE) } +func (t *TlsTapper) GlobalGolangTapPath(exePath string) error { + return t.tapGolangPath(exePath) +} + func (t *TlsTapper) AddSsllibPid(procfs string, pid uint32, namespace string) error { sslLibrary, err := findSsllib(procfs, pid) @@ -219,6 +223,18 @@ func (t *TlsTapper) tapGolangPid(procfs string, pid uint32, namespace string) er return nil } +func (t *TlsTapper) tapGolangPath(exePath string) error { + hooks := golangHooks{} + + if err := hooks.installUprobes(&t.bpfObjects, exePath); err != nil { + return err + } + + t.golangHooksStructs = append(t.golangHooksStructs, hooks) + + return nil +} + func LogError(err error) { var e *errors.Error if errors.As(err, &e) {