views:

108

answers:

4

One of my Rails applications is going to depend on a secret key in memory, so all of its functions will only be available once administrator goes to a certain page and uploads the valid key.

The problem is that this key needs to be stored securely, so no other processes on the same machine should be able to access it (so memcached and filesystem are not suitable). One good idea would be just to store it in some configuration variable in the application, but newly spawned instances won't have access to that variable. Any thoughts how to implement this on RubyEE/Apache/mod_passenger?

A: 

Encrypt it heavily in the filesystem?

A: 

What about treating it like a regular password, and using a salted hash? Once the user authenticates, he has access to the functions of the website.

Todd Gardner
This key should be available during the whole application lifetime, as it will be used to encrypt/decrypt information.
Oleg Shaldybin
+1  A: 

I would use the filesystem, with read access only to the file owner, and ensure the ruby process is the only process owned by this user. (using chmod 400 file)

You can get more complex than that, but it all boils down to using the unix users and permissions.

yhager
+3  A: 

there is really no way to accomplish that goal. (this is the same problem all DRM systems have)

You can't keep things secret from the operating system. Your application has to have the key somewhere in memory and the operating system kernel can read any memory location it wants to.

You need to be able to trust the operating system, which means that you then can also trust the operating system to properly enforce file access permissions. This in turn means that can store the key in a file that only the rails-user-process can read.

Think of it this way: even if you had no key at all, what is to stop an attacker on the server from simply changing the application code itself to gain access to the disabled functionality?

levinalex
The fact that kernel can access the key is fine for me, I just don't want it to be accessible to other users' processes. If there was a shared memory area accessible to all of Rails instances, I would keep it there. But it seems to me that every instance only accesses its own copy of data.
Oleg Shaldybin