nrepl / drawbridge

An HTTP/HTTPS nREPL transport, implemented as a Ring handler.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request: Add authentication for client side

PabloReszczynski opened this issue · comments

First of all, thanks for this awesome project!

I'm currently developing a debugging feature (nrepl-in instead of ssh-in) for a project I'm working in.
For obvious security reasons, I'm setting authentication for nrepl on the server side (using ring-basic-authentication), but currently the drawbridge client doesn't contain authentication options.

With some guidance I could implement this myself.

Thanks in advance

Hey there!

That'd be great to have, but the problem is that I can't provide you much guidance as I'm not super familiar with the codebase myself (I did very little work on it, since I became nREPL and related project's maintainer). There's not a lot of code, though, so I assume that if you're determined enough you'll figure things out pretty quickly.

For basic authentication you would have to add a :basic-auth key to the http call as described in the clj-http library. The :basic-auth key can be added here in the ring-client-transport function.

I'm not sure what would be the preferred way to pass the user and password however. One way could be to pass them as environment variables using the environ library for example.

I imagine something like this could be done:

(defn ring-client-transport [url & [options]]
 ...
  (merge {:as :stream
          :cookies @session-cookies}
         (if (:auth options) 
             {:basic-auth [(-> options :auth :user) (-> options :auth :pass)]} 
             {}))
  ...)

Could you perhaps try to pass the username and password in the connection url? F.ex.

lein repl :connect https://username:password@example.com/repl

or

(nrepl/url-connect "https://username:password@example.com/repl")

This might work already without any changes to the code.

@PabloReszczynski Did you get a chance to check passing the username and password in the url? Thanks!

I'm having some issues.
A quick try in my terminal gives this error:

lein repl :connect http://user:pass@localhost:8080/repl

java.io.FileNotFoundException: Could not locate cemerick/drawbridge/client__init.class or cemerick/drawbridge/client.clj on classpath.

I know this is the old version of drawbridge, but I don't know how to tell leiningen to use the newest one

I don't think nrepl/drawbridge is supported yet in the current version of leiningen.

Can you try to add com.cemerick/drawbridge "0.0.7" to your :plugins and retry the lein repl :connect command?

This is the error now:

java.lang.IllegalArgumentException: No nREPL support known for scheme http, url http://
user:pass@localhost:8080/repl

This is with both lein and requiring nrepl 0.5.0

Which version of leiningen are you using?

2.8.1 but the problem persist when using CIDER

I've retested this, and with leiningen 2.8.1 [com.cemerick/drawbridge "0.0.7"] should be added to the plugins. With leiningen 2.8.3 [nrepl/drawbridge "0.1.5"] is needed in the plugins.

I'm not sure where the No nREPL support known for scheme http error would come from if the plugin is present.

Can you perhaps retest with lein 2.8.3 and the [nrepl/drawbridge "0.1.5"] plugin?

In case someone else stumbles over this issue:
we are using nrepl/drawbridge 0.2.0 and changing the plugin to [nrepl/drawbridge "0.2.0"] fixed the Could not locate cemerick/drawbridge/client__init.class or cemerick/drawbridge/client.clj on classpath error.