1

I want to implement Basic Http Authentication in Selenium Grid how do I do that? For eg: I want to send request to grid but not without authentication in the URL. I need to create something like this http://username:password@mygrid.com:4444/wd/hub in our internal Selenium grid. How do I do that?

Damien-Amen
  • 7,232
  • 12
  • 46
  • 75
  • Possible duplicate of [Python Selenium Alert -- Prompt username and password is not working](https://stackoverflow.com/questions/45328654/python-selenium-alert-prompt-username-and-password-is-not-working) – undetected Selenium Nov 27 '17 at 15:55
  • 1
    Not a duplicate. That question is totally different from my question. That question is about automating a site which has BASIC Auth. But this one is about implementing Basic Auth for Selenium grid. – Damien-Amen Nov 27 '17 at 16:04
  • I think the answer is no, here is the dup https://stackoverflow.com/questions/14593670/can-selenium-grid-be-configured-to-require-authentication – nilesh Nov 27 '17 at 20:18
  • Actually this looks promising for what you are looking for https://github.com/seleniumkit/gridrouter – nilesh Nov 27 '17 at 20:24
  • @nilesh: I saw grid router. But I can only use stock grid and not customized grid. – Damien-Amen Nov 27 '17 at 20:58
  • You could write a simple proxy that just authenticates, if its successful route it to the grid behind else throw validation error. – nilesh Nov 27 '17 at 22:22
  • @nilesh - Can you pls point me to an example? – Damien-Amen Nov 27 '17 at 23:47
  • @Damien-Amen Did you got any solution for this? – Maher Nov 19 '20 at 16:34

1 Answers1

4

Ok. I was able to achieve what I needed. I installed nginx and added the selenium grid endpoint to it. Then added

auth_basic           “Grid’s Area”;
auth_basic_user_file /etc/apache2/.htpasswd; 

in the nginx.conf. That's it.

Please remember grid has multiple URI and does not have any root (In nginx terms) URI. So when you proxy let's say /grid to http://localhost:4444/grid/console all the static content cannot be served. In this case we need to proxy / to http://localhost:4001. This is because the static content is served from a different URI. In our case it's being served from /grid/resources/org/openqa/grid/images/ which is different from /grid/console.

As far as getting SSL working I follow this guide and it's super easy.

Damien-Amen
  • 7,232
  • 12
  • 46
  • 75
  • 1
    Short n sweet :) Awesome! – Krishnan Mahadevan Nov 28 '17 at 05:57
  • 1
    +1 Awesome, I was going in that direction but unnecessarily complicating things by introducing proxy, glad that its resolved. – nilesh Nov 29 '17 at 21:02
  • Ok. With all that I got the redirect working fine. But the `js` and `css` and `jpg` basically `static` content is lost if I'm behind a `nginx`. `Selenium Grid` has static objects in a folder inside the `jar`. But `nginx` does not understand that path. I tried many things but couldn't get it working. Any thoughts? @KrishnanMahadevan @nilesh ? – Damien-Amen Dec 02 '17 at 00:23
  • @Damien-Amen - No I dont think there's any work around – Krishnan Mahadevan Dec 05 '17 at 02:51
  • @KrishnanMahadevan: Sorry didn't update. I was able to fix the issue. In fact I was even able to setup a `load balancer` in front of the `grids`. Also got the `SSL` working. Thanks a lot! – Damien-Amen Dec 05 '17 at 15:30
  • Can you share that information on what all you did here ? That way others also will be benefitted by reading this thread. – Krishnan Mahadevan Dec 05 '17 at 16:08
  • @Damien-Amen Indeed, I was hoping to see what you did to get it working. – Ed Brannin May 07 '18 at 16:17