Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-environment usage #87

Closed
ThisIsMissEm opened this issue Nov 11, 2017 · 4 comments
Closed

Multi-environment usage #87

ThisIsMissEm opened this issue Nov 11, 2017 · 4 comments

Comments

@ThisIsMissEm
Copy link

Currently we configuring symmetric-encryption, you can specify each of the environments that you have (e.g., say if you have a demo or staging environment). This works well, but there's an issue: The default way to determine which "environment" symmetric-encryption should use is to look at Rails.env

However, Heroku recommends against multiple "environments" (details), so in order to work nicely with heroku Rails.env has to be just "production"

It seems that it'd be possible to read from something else, given the contents of railties

I'd like to field interest in setting up an ENCRYPTION_ENV variable as an alternative to use Rails.env (i.e., env = ENV['ENCRYPTION_ENV'] || Rails.env).

This way I could still have multiple encryption environments and still play nicely with heroku.

@ThisIsMissEm ThisIsMissEm changed the title Multi-environement usage Multi-environment usage Nov 11, 2017
@reidmorrison
Copy link
Owner

Symmetric Encryption supports both environment variables and Heroku directly. Look for the Heroku option when generating the configuration file:
https://rocketjob.github.io/symmetric-encryption/configuration.html

@ThisIsMissEm
Copy link
Author

ThisIsMissEm commented Nov 13, 2017

The problem is with --envs ENVIRONMENTS, say I have a heroku pipeline setup with production and release apps, in order to instruct symmetric-encryption which keys to use for which app, I need to pass RAILS_ENV=production or RAILS_ENV=release, this is problematic because heroku thinks that release isn't a production-like environment. Additionally anything that does optimisations for Rails.env.production? will consequently not be optimised in release but will be optimised in production

Hence wanting a way to have RAILS_ENV=production in both apps, but use different symmetric-encryption keys. As proposed, having a environment variable specifically for symmetric-encryption to use to understand it's environment.

*edit: * for clarity, I did use the heroku keystore option when I setup my app with symmetric-encryption. The issue is in this: (don't worry, those keys aren't in actual use)

test-symmetric-encryption $ symmetric-encryption --generate --keystore heroku --app-name my_app --environments "test,development,release,production"

********************************************************************************
Add the environment key to Heroku:

  heroku config:add MY_APP_RELEASE_V1=Zgw02KnfY7+ONkLuZNYd+ddjt/jGlYzmFA4mJUujwlo14023FzH9w07IY1s4/ASG

Or, if using environment variables on another system set the environment variable as follows:

  export MY_APP_RELEASE_V1="Zgw02KnfY7+ONkLuZNYd+ddjt/jGlYzmFA4mJUujwlo14023FzH9w07IY1s4/ASG"

********************************************************************************


********************************************************************************
Add the environment key to Heroku:

  heroku config:add MY_APP_PRODUCTION_V1=JKShE9m/IzoguX4I0HYr6/oU3VGjPtz1dis5+aJB0o1gAxogXB5oX2cCnP7R1sKN

Or, if using environment variables on another system set the environment variable as follows:

  export MY_APP_PRODUCTION_V1="JKShE9m/IzoguX4I0HYr6/oU3VGjPtz1dis5+aJB0o1gAxogXB5oX2cCnP7R1sKN"

********************************************************************************
New configuration file created at: test-symmetric-encryption/config/symmetric-encryption.yml

In order to know if symmetric-encryption is meant to use MY_APP_PRODUCTION_V1 or MY_APP_RELEASE_V1, it defers to Rails.env, as far as I can tell: https://github.com/rocketjob/symmetric-encryption/blob/master/lib/symmetric_encryption/railtie.rb#L38

@ThisIsMissEm
Copy link
Author

It's where the env at the end of this line comes from which is the problem: https://github.com/rocketjob/symmetric-encryption/blob/6668880e659672a5c724fd2db63c01cfb05590b7/lib/symmetric_encryption/config.rb#L76

whatcould added a commit to whatcould/symmetric-encryption that referenced this issue Apr 16, 2018
Allows using "production" RACK_ENV/RAILS_ENV but specifying separate env for config

[addresses reidmorrison#87]
whatcould added a commit to whatcould/symmetric-encryption that referenced this issue Apr 17, 2018
Allows using "production" RACK_ENV/RAILS_ENV but specifying separate env for config

[addresses reidmorrison#87]
@reidmorrison
Copy link
Owner

@ThisIsMissEm The above PR has been merged, does it sufficiently address the requirements above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants