Search code examples
ruby-on-railslinuxruby-on-rails-3encryptionpgp

Rails production is producing different results than the production console with GPGP encryption. How to fix?


I'm using a variety of the GPGR gem (https://github.com/HHRy/gpgr) to do pgp encryption, and when I run a function like installed_public_keys in a production console I get the email (in an array) that is attached to my PGP key. However if I have a button that logs the output of that function in a production gui it outputs an empty array.

I also have a script runner that I can call with a production env flag that runs fine, but when the exact same line is called from crontab as root it fails saying that there are no keys installed.

I'm assuming that this has more to do with each user having a keyring of keys than environment variables but everything production is using root and it is bugging the crap out of me.


Solution

  • The key to running pgp encryption with crontab (runners) is to specify the home directory with the --homedir switch. I.e. instead of using the keys at ~/.gnupg you can do:

    gpg --homedir /root/.gnupg -o file.txt.pgp -r [email protected] -e file.txt