3

Me and a colleague are developing an web application to control a computer cluster. This computer cluster lacks an API so we need to be able use the Linux shell to control and add "jobs" via bash scripts. Each user has a specific amount of time to run applications on the cluster so we need to be able to SSH onto the system using the users credentials so their users account gets used to submit the job.

The web app is written using Spring. We have done some research into executing commands via SSH using Java and found the Jcsh module. However our question is if there is a Spring module to do this. We where quite surprised that we could not find one since the SFTP module is already there and (correct me if i'm wrong) uses the same protocol.

Did we misread the documentation or is there no module to do this?

Many thanks!

1

2 Answers 2

3

I really don't think calling SSH directly by Spring is a good idea.

Since if you want to call the SSH directly, you'll need either store host's password into your application, or store the private key in your application(maybe this is better, since you can use Java's keystore to protect your private key)

Either way, you'll get the application able to do anything the host allowed(and since you can control the host's application by running command, I assume this use has lots of power).

This could be quite dangerous for the computer cluster.

If you indeed need to call the functions by SSH, I suggest you write a small native application(using python or Java, anything you like), and set the permission for your application can only execute this application, this is much safer.

So, it is sane to have SFTP support in Spring, for this is a very useful transport for data, but it is very very very dangerous to let your application can run SSH directly, even at home, believe me.

2
  • Thank you for your reply. Security is one of the main issues for us because indeed running a computer cluster from the web raises some issues. That is why we don't store passwords and/or keys and we ask the user for their credentials every time they want to use the cluster. The cluster runs by submitting a bash script so I really see no other way than an ssh connection to do this. EDIT: The ssh connection is not open constantly but we make a new connection using each users credentials when a command needs to be run. Mar 15, 2016 at 7:44
  • So, I suggest you to create a small python(bash or what ever application, and provide the api), For example, cluster add_user death_pool -u root -p the_password cluster grant_user death_pool sucker -u root -p the_password Then you can use your Java Application call this application by Java Process other than use SSH directly. This is much better(you can pool your SSH connections in the application if you want), and in some ways, will faster than use the SSH connection. For the purpose of integration, Spring will support any data endpoints, SSH is not data endpoint.
    – guitarpoet
    Mar 15, 2016 at 11:02
1

Jsch is indeed the best Java SSH implementation out there.

Sadly, Spring does not provide any integration with it. I personnally had to write custom plumbing to make use of it. It is a low level API but the project is well documentation with great exemples.

For a previous project, I wrote a template like API wrapper for the Jsch. Sadly I couldn't open source it.

1
  • Thanks for your answer! Shame it isn't available I guess we have to write our own :( Mar 14, 2016 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.