Attach to a process running as root on local machine
Answered
So there are plenty of posts about how to run a process as root from Goland. But I have a use case where my process is already running as root on local system (built with debug symbols and everything) and I can't attach it from Goland. What are my options?
Please sign in to leave a comment.
Hello,
Could you please provide a bit more details? How do you build your application and run it? Is your process recognized as a Go process using gops tool?
Please see: https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html#step-3-attach-to-the-running-process
Yes my process is recognized via `gops` - as long as I run gops as root.
Basically - I want to debug kubelet running via `./hack/local-cluster-up.sh` - https://github.com/kubernetes/kubernetes/tree/master/cmd/kubelet
I can build kubelet with debug info and everything and usually debug just fine using dlv from command line, as long as I am running dlv as root too. However I would love to have convenience of debugging from Goland and it looks like since Goland runs `gops` as non-root, it can't see kubelet and I can't attach to a running kubelet.
Running kubelet on its own from Goland is although possible but tedious. It is much simpler to attach to a running kubelet.
As for building kubelet. This is how I build it:
make CGO_ENABLED=0 GOGCFLAGS="all=-N -l" GOLDFLAGS="" WHAT=cmd/kubelet
But as I said, I can debug it just fine from CLI and dlv.
I think you can consider the following process (described in https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html#attach-to-a-process-on-a-remote-machine for a remote machine, but works fine for a local one):
I've tried it with a simple application and it works fine. Could you please try it out?
Thank you for the response. Yes, when I read the remote debugging procedure, I suspected it could be made to work for local-debugging with root. But it may be easier if we can do this directly from goland, so please consider it as feature request if you will.
Could you please elaborate a bit? GoLand can run processes with sudo (with enabled Run with sudo option). So, you can directly run and debug Go processes from GoLand. However, it is not the case if you build and run a process outside GoLand. I'm not sure that I understand a feature request precisely. How should GoLand recognize when gops have to run with sudo privileges?
> Could you please elaborate a bit? GoLand can run processes with sudo (with enabled Run with sudo option). So, you can directly run and debug Go processes from GoLand. However, it is not the case if you build and run a process outside GoLand.
It is sometimes not feasible to run a program from GoLand because it has dependencies which are hard to satisfy at launch time like in case I mentioned above.
> I'm not sure that I understand a feature request precisely. How should GoLand recognize when gops have to run with sudo privileges?
There could be a checkbox when I attach to a process from GoLand that I want to attach to process as root. Seems simple enough?
Thanks for the follow-up.
I've filled a new request on our tracker. Feel free to follow GO-12507.