Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypting or scrubbing Rails log files

We have a customer with very stringent security requirements. So we will encrypt the Rails database using one of Postgres's database encryption options. But that still leaves customer's data exposed in what the Rails logger logs when forms are submitted to create data.

I guess one option is not to encrypt the log file, but to suppress all the parameter values that get logged for POST requests by Rails. What is the best way of doing that?

Another option is to encrypt Rails log files as they are written to disk. Is that a better way to go, and what's a good way to do it?

like image 985
dan Avatar asked Apr 19 '12 01:04

dan


People also ask

Are rails sessions encrypted?

Rails uses encryption to securely prevent tampering with the session contents, however, users cannot revoke sessions because the contents are stored on the browser.

What is the log to check for errors in Rails?

Rails uses six different log levels: debug, info, warn, error, fatal, and unknown. Each level defines how much information your application will log: Debug: diagnostic information for developers and system administrators, including database calls or inspecting object attributes. This is the most verbose log level.

Where does Rails logger write to?

In a Rails app, logs are stored under the /log folder. In development mode, the development. log file is used & you see log output on the terminal you're running rails server on.

How do I use logger in Ruby on Rails?

To write in the current log use the logger. (debug|info|warn|error|fatal|unknown) method from within a controller, model, or mailer: logger. debug "Person attributes hash: #{@person.


2 Answers

one thing that you can do is in you config/application.rb file you can add fields that you want to omit from the logs like this

class Application < Rails::Application
  ...
  config.filter_parameters += [:password]
  config.filter_parameters += [:ssn]    
  ....
 end

I hope that this helps

like image 161
MZaragoza Avatar answered Oct 30 '22 09:10

MZaragoza


If you want something better than the filter_parameters for all params, You can write a custom logger. see: http://rubyjunky.com/cleaning-up-rails-4-production-logging.html and the gem someone extracted from it, https://github.com/gshaw/concise_logging

However, you're going to need to store the encryption key somewhere on the same machine as the logs, which potentially means it's un-encryptable too if someone has active access (but not if they just somehow get the logs later).

Some questions to think about:

  • Do you need the parameter logging at all? (do you even check the logs? how do you track errors?)
  • What sort of compliance are you trying to hit? PCI? HIPAA?
  • What is the attack vector you're trying to avoid? i.e. log access via shared hosting, physical attack (remove hard drive), remote access (grab all files off machine), ..

Your answers will define guidelines on how to attack this problem!

like image 24
court3nay Avatar answered Oct 30 '22 11:10

court3nay