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

Define SMTP settings in secrets file #3695

Merged
merged 7 commits into from
Nov 12, 2019
Merged

Define SMTP settings in secrets file #3695

merged 7 commits into from
Nov 12, 2019

Conversation

javierm
Copy link
Member

@javierm javierm commented Sep 11, 2019

References

Background

Currently, the CONSUL installer replaces the existing production.rb environment file with its own file. This way secrets like SMTP credentials are not included in the repository. However, it's hard to keep both files up to date, and so changes we did to the production environment file when we upgraded to Rails 5 haven't been included in the installer.

Objectives

Avoid differences between the production.rb and delayed_job_config.rb files included in version control and the ones included in the CONSUL installer.

Release notes

SMTP, SSL and delayed job activation settings are now configured in the config/secrets.yml file. If, as we strongly recommend, you use capistrano to deploy your code, your current settings will be copied to the config/secrets.yml file automatically so you won't have to worry about this change 😉. If for some reason you don't use capistrano, either have a look at the task in lib/tasks/secrets.rake or edit your config/secrets.yml file manually.

If you've installed CONSUL using the CONSUL installer and you've activated delayed jobs and you've changed your delayed job (that is, Delayed::Worker) configuration, you might want to edit the config/initializers/delayed_job_config.rb file and adjust your settings.

@javierm javierm added this to Reviewing in Roadmap via automation Sep 11, 2019
@javierm javierm moved this from Reviewing to Doing in Roadmap Sep 11, 2019
@javierm javierm force-pushed the smtp_secrets branch 2 times, most recently from 68310b3 to 2e46378 Compare October 12, 2019 23:11
@javierm javierm self-assigned this Oct 12, 2019
lib/tasks/secrets.rake Outdated Show resolved Hide resolved
lib/tasks/secrets.rake Outdated Show resolved Hide resolved
@javierm javierm changed the title [WIP] Define SMTP settings in secrets file Define SMTP settings in secrets file Nov 1, 2019
@javierm javierm moved this from Doing to Reviewing in Roadmap Nov 1, 2019
lib/tasks/secrets.rake Outdated Show resolved Hide resolved
lib/tasks/secrets.rake Outdated Show resolved Hide resolved
@javierm javierm force-pushed the smtp_secrets branch 2 times, most recently from a718672 to 7a2e967 Compare November 1, 2019 11:57
@javierm javierm moved this from Reviewing to Doing in Roadmap Nov 1, 2019
@javierm javierm changed the title Define SMTP settings in secrets file [WIP] Define SMTP settings in secrets file Nov 1, 2019
@javierm javierm changed the title Define SMTP settings in secrets file [WIP] Define SMTP settings in secrets file Nov 2, 2019
@javierm javierm moved this from Reviewing to Doing in Roadmap Nov 2, 2019
child.is_a?(Psych::Nodes::Scalar) && child.value == Rails.env
end

nodes.children[environment_index + 1].children.push(*Psych.parse(settings_to_add.to_yaml).children.first.children)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [118/110] (https://rubystyle.guide#80-character-limits)

@javierm javierm moved this from Doing to Reviewing in Roadmap Nov 2, 2019
@javierm javierm changed the title [WIP] Define SMTP settings in secrets file Define SMTP settings in secrets file Nov 2, 2019
@javierm javierm force-pushed the smtp_secrets branch 2 times, most recently from 997fc0a to b80154c Compare November 2, 2019 21:19
Since SMTP passwords should not be in a file under version control, and
they're usually configured in the production.rb file (which is under
version control), the natural place to configure it is the secrets.yml
file.

Until now we were using the capistrano shared folder, but that's a bit
inconvenient since changes we've done to the production.rb file (like
changing eager_load_paths when we upgraded to Rails 5) won't take effect
after a deployment.
Roadmap automation moved this from Reviewing to Testing Nov 12, 2019
javierm and others added 2 commits November 12, 2019 14:47
Existing installations having their configuration settings in the
capistrano shared folder needed this migration.

Note we can't just use `YAML.load` because we'd lose the anchors defined
in the file. So we have to parse the file the hard way.
this is usually configured in the production.rb file (which is under
version control), the natural place to configure it is the secrets.yml
file.

Until now we were using the capistrano shared folder, but that's a bit
inconvenient since changes we've done to the production.rb file (like
changing eager_load_paths when we upgraded to Rails 5) won't take effect
after a deployment.
microweb10 and others added 4 commits November 12, 2019 14:58
Existing installations having their configuration settings in the
capistrano shared folder needed this migration.
We were copying the current SMTP and SSL settings to the secrets file
after overwriting them, but we need to copy them before overwriting
them.

The workaround I've found is to copy the tasks to the folder of the
previous release and execute them there.
While this is not a secret and in theory should be in a file under
version control, currently the CONSUL installer disables delayed jobs by
default, meaning we were keeping two versions of the delayed jobs
configuration file, and some existing configurations have their settings
defined in a file in capistrano's `shared` folder.

So we're moving existing settings to the secrets file.
Old versions of the installer created this file as root, making it
impossible to change it as a regular user.

So for old installations we need to make sure we've got write access to
this file.

We're using `sudo` because in these applications the installer gives
`sudo` access to the deploy user, so everything works fine with the
default configuration.
@javierm javierm merged commit e9b9512 into master Nov 12, 2019
Roadmap automation moved this from Testing to Release 1.1.0 Nov 12, 2019
@javierm javierm deleted the smtp_secrets branch November 12, 2019 19:22
smarques pushed a commit to venetochevogliamo/consul that referenced this pull request Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Roadmap
  
Release 1.1.0
Development

Successfully merging this pull request may close these issues.

Capistrano doesn't always take into account the environment for its tasks
4 participants