stacker.news: Unable to connect CLN node using clnrest for withdrawal over Tor
Note: this template is meant to help you report the bug so that we can fix it faster, ie not all of these sections are required
Description I’ve tried to hook up my node using the built-in clnrest plugin for autowithdrawal over Tor. Haven’t been able to get this to work yet. I’ve verified that it works accessing the node’s Swagger page on that port over Tor and simulated the request parameters I’ve found in in the code so I think my node is fine. StackerNews logs give the following:
20m [cln] ERROR failed to attach wallet
1m [cln] ERROR could not connect to CLN: request to https://[redacted].onion:3010/v1/invoice failed, reason: getaddrinfo ENOTFOUND [redacted].onion
1m [cln] ERROR failed to attach wallet
My guess is that hostname resolution over Tor isn’t working quite right.
Steps to Reproduce Try to connect a CLN node over Tor using the built-in clnrest plugin.
Expected behavior Wallet would connect and issue invoice for autowithdraw.
Screenshots Prefer not to provide screenshots at this time – let me know if necessary.
Logs Provided with descrtiption.
Environment: If you only experience the issue on certain devices or browsers, provide that info.
- Device: [e.g. iPhone6]
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
I don’t feel this is applicable right now.
Additional context Add any other context about the problem here.
I can add more information if necessary. I’ve taken a quick look at the code and currently wondering how createInvoice detects Tor traffic and routes accordingly. I can keep looking at it or provide more information, but short on time ATM and wanted to write up an issue in case something obvious is being overlooked.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 26 (17 by maintainers)
You were right - I wasn’t setting the certificate 😕 After digging around in the CLN documentation and trying to
base64encode all of the various certificates it generates, I finally got to the point where I’m getting this error using the value fromopenssl base64 -in ca.pemand reformatting it for the input field:The cert isn’t valid for the Tor hostname. Obviously this doesn’t seem to be an issue with your SN implementation. I probably need to educate myself further from the CLN docs / code and refine my familiarity with SSL to make sure using the CA is expected here – but so far it was the only one that didn’t fail the SSL check outright with:
Out of time for today and will have to look later. Let me know if you have any pointers. Thanks!
I switch back to SSL for clnrest and SN connected to my node perfectly. Works as discussed. Thanks 😄
Hey, we did a release today which includes to no longer validate certificates on Tor in production (#1165). You should be able to use HTTPS over Tor now.
Going to close this since CLNRest over Tor seems to work now. Feel free to reopen if there is still something missing!
That’s very useful information, thanks! So this means the proxy works and we can reach your node now but the TLS connection now fails.[^1]
But I have encountered your error before while implementing #1042 since CLN was running inside docker. I forgot that this will be an issue for stackers, too.
Fortunately, CLN is aware of this and they provided this documentation which helped me. It’s listed under the gRPC documentation but it also applies to the TLS certificates for the REST API.
Therefore, can you try this:
server.pemandserver-key.peminto lightning directory and restart node:After that, you provide the same
ca.pemas before. You don’t need to change anything in the SN CLN autowithdrawal config. This might also be a source of confusion if you’re unfamiliar with TLS.We can also consider disabling verifying TLS signatures for Tor connections. I am still not sure if or how much TLS over Tor makes sense.
For (our) reference, Alby apparently connects to Tor nodes via a companion app written in Rust. They seem to ignore invalid certificates for Tor.
[^1]: And yes, you need to provide the certificate authority so
ca.pemis indeed what you need to provide. Sorry, simply saying “certificate” is very confusing in the context of TLS since basically everything is a certificate, lol.I’ll probably deploy it tomorrow. We are behind the times and prefer to manually deploy.
Oh, if you ever get curious which revision we’re at you can click on the hash in the footer.
Since
HTTP CONNECTalso works for HTTPS, I think we can indeed simply use such a custom agent that checks if an onion address is used. In that case, it proxies the request through our Tor proxy with a custom agent sincenode-fetchdoes not support proxies natively and HTTPS or HTTP doesn’t seem to matter. I’ll studyproxy-agentsfor this since it implements various proxy agents.We might not even need the env var
http_proxythen if we use this agent for all our backend fetches. We can proxy all Tor stuff via this custom agent.Thanks for the tip @s373nZ!
Would it be possible to conditionally set a custom agent in the
fetchcall using a class like this?Or are you saying the environment variable setup would override this approach?