Link to home
Start Free TrialLog in
Avatar of Frosty555
Frosty555Flag for Canada

asked on

Protecting data on ubuntu server, access via PHP

I have an ubuntu server which is running Apache and a special PHP webpage I wrote.

The PHP page allows a user to authenticate and access a special secret "document" that belongs only to them. Each user has their own secret document, and I have a back-end system for configuring the access control lists, user accounts etc. The server uses a properly signed SSL certificate, and the PHP itself is well written.

On the back-end, the documents themselves are stored in a folder on my server which is not web accessible, e.g. in /usr/share/secretstuff/[accountid]/somefile.txt. PHP currently gains access to the file via file_get_contents() and displays it to the user.

My concern is that the files are just sitting on the hard drive in plain text. I've set the chmod and chown accordingly so only www-data has access, but I'm acutely aware that ANY script running on my apache server can access these files if they know where to look.

I'm also concerned that if the server were compromised (either physically or over the network), the files are totally open.

What are some ways I can protect these files and make it so the files are accessible ONLY through authenticated access from my PHP page?

Ideally, how can I protect the server so that a knowledegable person who knows the system inside and out who has somehow gained root access to the machine, or gained physical access to the machine (e.g. removed the hard drive), still cannot access the files?
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Frosty555

ASKER

I should include also, that it is important that any backups that get made of the server are just as well protected as the server itself....

I was thinking encryption would be the ideal way to do this. Each user logs in using a password that only they know so I imagine I could use that password, hash it / digest it somehow, and use that as the encryption key?

The problem is that some users have access to more than one document, and an administrator needs access to all of them, so the encryption becomes a bit messy. I don't know how to do encryption with multiple keys. I know that public/private encryption is designed to help with this situation but I don't understand it well enough to get a clear picture of what a proper implementation of it would look like (nevermind the actual coding of that implementation in PHP)

This feels like the sort of problem that has already been solved by the technology used in SSL.
SSL is used to encrypt transmissions over the network, not files on a server.  You might want that also.  Security always makes things more difficult, it is supposed to!  You need strong encryption and a plan.  Do a search for "Linux file encryption" http://www.google.com/search?q=Linux+file+encryption , there are a lot of resources available.
Okay, so what would be the right way to do this then? If I encrypt the files with a passphrase, that passphrase has to exist somewhere on the server, which defeats the purpose of the original encryption? Is there a better way to protect the encryption key?
No, the passphrase will be encrypted into the file in such a way that the encryption software will know how to handle it.  On my web sites with logins, the passwords are not found anywhere in plain text and you are welcome to spend the years it will take to break the MD5 hash to get in.  There is no reason to think that the people who wrote the encryption software did not think of this.

There is no Perfect answer.  Encryption and security is always a matter of how difficult do you want to make it.  Generally the answer is, more difficult than the people want to deal with that would otherwise steal the info.  The average computer user won't try very hard.  If some government with super-computers wants to break in, they may have the resources to do it.

Don't over think this.  People smarter than you and me have already solved this problem many times.  Make a list of your needs and find some software that will provide them.