carafe
carafe copied to clipboard
Safely connecting as hidden node
I would love to see this feature, to make introspecting a node simple. It makes sense to have this in onartsipac:
- we already know how to connect to a node via ssh
- even though we do not maintain the erlang cookie, it is easy to obtain (1)
- same for the node name as seen by epmd on the host (2)
- the hidden node runs locally (so :observer is usually available), having
run_locallymakes this simple
Footnotes: (1)
cookie = capture "bin/#{script}", "eval 'erlang:get_cookie().'"
cookie = cookie[%r{\A'(.*)'\z}, 1].gsub("\'", "'")
(2)
node_name = capture "bin/#{script}", "rpcterms Elixir.Node self"
node_name = node_name[%r{\A'(.*)'\z}, 1].gsub("\'", "'")
Though coupling a bit to how sshkit does things, this is how we can set up a forwarding:
with_ssh do |ssh| #yields a Net::SSH::Connection::Session
ssh.forward.local(4369, "localhost", 4369)
# ...
Forwarding the detected node port leaves us with two alternatives:
- forward the exact same port from locally to the server. This implies that the server can never be the same as the local one, in particular, we cannot test the feature.
- run a fake epmd and set
ERL_EPMD_PORT - implement an epmd module, see https://www.erlang-solutions.com/blog/erlang-and-elixir-distribution-without-epmd.html
Both (2) and (3) look too complicated for the start.