drawbridge icon indicating copy to clipboard operation
drawbridge copied to clipboard

Request: Add authentication for client side

Open PabloReszczynski opened this issue 6 years ago • 12 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

PabloReszczynski avatar Nov 29 '18 16:11 PabloReszczynski

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.

bbatsov avatar Nov 29 '18 17:11 bbatsov

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.

mallt avatar Nov 29 '18 17:11 mallt

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)]} 
             {}))
  ...)

PabloReszczynski avatar Nov 29 '18 18:11 PabloReszczynski

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

lein repl :connect https://username:[email protected]/repl

or

(nrepl/url-connect "https://username:[email protected]/repl")

This might work already without any changes to the code.

mallt avatar Nov 29 '18 20:11 mallt

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

mallt avatar Dec 03 '18 19:12 mallt

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

PabloReszczynski avatar Dec 03 '18 21:12 PabloReszczynski

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?

mallt avatar Dec 03 '18 21:12 mallt

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

PabloReszczynski avatar Dec 03 '18 23:12 PabloReszczynski

Which version of leiningen are you using?

mallt avatar Dec 04 '18 06:12 mallt

2.8.1 but the problem persist when using CIDER

PabloReszczynski avatar Dec 06 '18 18:12 PabloReszczynski

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?

mallt avatar Dec 31 '18 14:12 mallt

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.

Vinai avatar Jun 03 '19 13:06 Vinai