I have a central system(web application) which is supposed to connect to a set of nodes one by one (clients), to get a record set from database exposed through mysql views.
I am in a search of best possible implementation for this scenario. Currently I have this flow in my mind.
1. First Approach
Pseudo code
$dataFetched=array();
$clients= getListOfClients();
//
foreach($clients as $client){
// client={details:{id,name,etc....},
// ssh:{pem:'client.pem',localMysqlPort:3307 ,remoteMyqlPort:3306,
// sshUser:'demo@clientHost.com'},
// mysql:{user:'tunnelUser',password:'password'}
// }
//connect ssh connection
$ssh_connection=new Ssh_connect($client->ssh)
if($ssh_connection->status){
$dataFetched[$client->id]=array("status"=>'OK','data'=>fetchMysqlData($client->mysql))
}else{
$dataFetched[$client->id]=array("status"=>'NO_OK','data'=>array())
}
$ssh_connection->destroyTunnel();
unset($ssh_connection);
}
Some Concerns/questions with this approach
Is there a ssh lib/extension to provide me this kind of functionality ?
What is best secure way to store "pem" files for each client ?
Another approach ?
2. Second Approach
Write bash script to implement above pseudo-code
setup cron job to update database
Web application does not know about external clients. It will use table updated by cron-job to render data.
Some point:
Data size is very light
Both consumer and provider are web-applications
Applications does not know each other except SSH
It should be flexible to add new client node ( I don't known how I will do this in second approach)
Which one will be better from security wise Reverse Tunnel or Forward Tunnel ? As I know in case of reverse tunnel, echo client knows about server which desires to connect with it. So we need to setup a less privileged user to on each client node to give access to server, which seems more secure as I don't have to keep all pem files in one place at Central server. Correct me if I am getting it wrong.
Your suggestions are much appreciated