Re: Sending Storable strings over http
by jhourcle (Prior) on Dec 03, 2005 at 18:26 UTC
|
In a situation like this, I have a couple of questions, which would affect my recommendations --
- Are you the user of this, or are the users reasonably technical savvy and trustworthy?
- Is there a single specific client system that is connecting, or multiple client systems?
- What is the security required by the information being passed, and the security already in the database?
- Who controls DHCP?
- Is the current UI web based?
If I were going to be the only user, or the users were people that I trusted to follow directions, I'd probably use an SSH tunnel, and place a wrapper around the connection to start the tunnel. You could also use a VPN, or requiring port knocking before the server allows access
If there needed to be multiple clients that needed to connect, I might place a system on the network that had the necessary permissions to connect to the database, but acted as a gateway / bastion host.
If you know the folks who are controlling DHCP, I'd look into setting up a smaller IP pool for the systems that need to connect.
If the security requirements are really low, I probably wouldn't worry about things too much, and just open up the network to the subnet.
If the plan for the UI is web based, it doesn't seem like it's a signfiicant stretch to send updates via HTTP, but if it's not, you may be introducing extra unnecessay complexity. (and opening up unnecessary ports if the server doesn't already have an HTTP service exposed)
But, to answer your questions directly:
Is this insane?
I think it's probably more effort than it's worth, however, you can also use the proxy to perform extra error checking and/or access control, if you needed to.
One of my db elements is a blob generated by mod Storable. Can I send this data directly via http POST or GET without getting involved in all kinds of MIME complications?
So long as it's all properly escaped, you should be fine. If you're doing queries, you can use GET, but for any sort of request that modifies data, you should use POST, which should not be re-executed by a client without prompting, and won't be cached.
I personally wouldn't use CGI to pass my data, but would be more likely to use SOAP, which was basically made for these sorts of operations.
| [reply] |
|
|
Many thanks to everybody who replied to this thread, especially jhourcle who pointed out that I should be using SOAP for this. The public nameserver idea was a good one, but alas my ISP required an IP address for external hosts.
So I used SOAP to take the db record on the client side, stick it into a data structure, send that over to ther server, recollect the data structure on the server side, then put it into MySQL over there. It works great. Here is the code that does the job, in case anyone else can use it. In both cases it assumes that you supply a sub that converts the database record to/from a data structure and returns it to the client/server. Keep yer stick on the ice...Steve
Client:
#!/usr/bin/perl -w
use strict;
use SOAP::Transport::HTTP;
sub sendthread {
my $id = shift;
my $reply;
my $servermsg;
my $data = getfromdb($id);
my $server = SOAP::Lite
+
-> uri('http://www.soaplite.com/Storeit')
+
-> proxy('http://your.ip.net/cgi-bin/soapserver.cgi', timeout =>
+ 30);
eval { $servermsg = $server->store($id,$data); };
if ($@) { # eval error
$reply = $@;
}
elsif ($servermsg->fault) { # server fault
$reply = join ', ', $servermsg->faultcode, $servermsg->faultstr
+ing, $servermsg->faultdetail;
}
else { # everything OK
$reply = $servermsg->result();
}
return $reply;
}
soapserver.cgi#!/usr/bin/perl -w
use strict;
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
-> dispatch_to('Storeit')
-> handle;
package Storeit;
sub store {
my ($class,$id,$data) = @_;
my $response = storetodb($id,$data);
return $response;
}
| [reply] [d/l] [select] |
Re: Sending Storable strings over http
by davidrw (Prior) on Dec 03, 2005 at 17:18 UTC
|
Would it be acceptable to make a looser permit for host access? e.g. allow XXX.YYY.ZZZ.* to connect (i assume the client IP is changing w/in some given range) .. you still have the protection on top of that of a username/password to provide access to the db, right?
quick idea off the top of my head -- you could install http://www.phpmyadmin.net or http://www.phpmyedit.org and then hit them with WWW::Mechanize to submit changes .. essentially the same model you just proposed but a lot more powerful and you don't have to deal with the lower db stuff..
Another way would be to use http://www.dyndns.com (or similiar) service to give the client a static hostname (even though the IP is dynamic) .. then you can either restrict mysql host access by name (not sure offhand if it works that way or requires IP; if requires IP then you can setup a cronjob on the server to check for IP changes for that hostname and update the mysql host access setting)
Update: i'll second jhourcle's SSH tunnel suggestion as another possibility (i've actually done that several times to connect to a remote db--shoulda mentioned it myself) | [reply] |
Re: Sending Storable strings over http
by superfrink (Curate) on Dec 03, 2005 at 20:18 UTC
|
I would use OpenBSD's AuthPF if I could. The idea is you have to SSH to a port on some IP. You don't have to run commands, just connect. So long as your SSH connection is open OpenBSD will allow traffic from your IP through to certain IPs/ports.
This means your will have to loosen the host settings in mysql (mentioned above). Instead you will have to trust the OpenBSD firewall instead of the mysql host settings.
If AuthPF is out of the question then I would setup phpmyadmin (mentioned above) because is is pre-built. I would set it up on a HTTPS site. You can setup a self-signed SSL certificate since you are not expecting random people on the internet to trust the certificate. | [reply] |
Re: Sending Storable strings over http
by gaal (Parson) on Dec 04, 2005 at 06:14 UTC
|
Regarding Storable specifically, make sure you use network order.
That means nstore_fd instead of store_fd. You may get away not doing this if the clients are always the same architechture, but this is good practice and when you next have to port, e.g., to a Mac, you will have one less thing to puzzle about.
(Despite the name "network order", this advice is also applicable to applications that serialize data to disk. Sometimes you want to move a store to another machine too.) | [reply] [d/l] [select] |
|
|
| [reply] |
|
|
| [reply] |
|
|
|
|
Re: Sending Storable strings over http
by garrison (Scribe) on Dec 03, 2005 at 23:50 UTC
|
I find Dynamic DNS works well for a number of applications, I also use a perl script to automatically update config files that require IP addresses. | [reply] |
Re: Sending Storable strings over http
by Anonymous Monk on Dec 03, 2005 at 21:08 UTC
|
I use ods.org for dynamic IP name assignment and think it's fantastic! -Adam | [reply] |
Re: Sending Storable strings over http
by mattr (Curate) on Dec 06, 2005 at 07:08 UTC
|
You could ssh into a shell on the machine and run from that account. If you have higher security requirements you can use a vpn maybe but for what it sounds like you are doing, if everything is always patched up to date it sounds fine, especially if it is only opened at certain times. Presumably if you limit to your dsl provider's block you can reduce risk. Dyndns sounds okay too though of course you have no idea about what it would take to get into their system. As for the blob, I have used a module I wrote called Quickcrypt which includes a sub called websafepack/websafeunpack to store serialized structures in html forms. The websafe part comes from using a web-safe alphabet ("charset") like that used by CGI::EncryptForm, and the serialized data is IIRC gpg encyrypted before applying that. I am not sure a bare MIME64 will do enough.. try it a little it seems there was a problem with just the base64-quotable. On the other hand if you can upload a file via post you can upload a structure serialized into a text file, so the extra alphabet is only for embedding into an HTML form field. Why not try serializing your structure to disk for safekeeping, then upload that file to the server? Straight uploading could be done by sftp, with files grabbed by a running daemon, or you can do what you were going to do and POST it up there or use some other protocol and have the receiving program do the processing for you. | [reply] |