Skip to content

Commit 3cac5fe

Browse files
authored
Merge pull request rails#33928 from freeletics/fix-key-env
Fixed to RAILS_MASTER_KEY as a default env key for decrypting.
2 parents 2487a37 + b4b70ef commit 3cac5fe

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

railties/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
* Support environment specific credentials file.
22

33
For `production` environment look first for `config/credentials/production.yml.enc` file that can be decrypted by
4-
`ENV["RAILS_PRODUCTION_KEY"]` or `config/credentials/production.key` master key.
4+
`ENV["RAILS_MASTER_KEY"]` or `config/credentials/production.key` master key.
55
Edit given environment credentials file by command `rails credentials:edit --environment production`.
66
Default paths can be overwritten by setting `config.credentials.content_path` and `config.credentials.key_path`.
77

railties/lib/rails/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def secret_key_base
440440
# +config/master.key+.
441441
# If specific credentials file exists for current environment, it takes precedence, thus for +production+
442442
# environment look first for +config/credentials/production.yml.enc+ with master key taken
443-
# from <tt>ENV["RAILS_PRODUCTION_KEY"]</tt> or from loading +config/credentials/production.key+.
443+
# from <tt>ENV["RAILS_MASTER_KEY"]</tt> or from loading +config/credentials/production.key+.
444444
# Default behavior can be overwritten by setting +config.credentials.content_path+ and +config.credentials.key_path+.
445445
def credentials
446446
@credentials ||= encrypted(config.credentials.content_path, key_path: config.credentials.key_path)

railties/lib/rails/commands/credentials/USAGE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ from leaking.
4343

4444
It is possible to have credentials for each environment. If the file for current environment exists it will take
4545
precedence over `config/credentials.yml.enc`, thus for `production` environment first look for
46-
`config/credentials/production.yml.enc` that can be decrypted using master key taken from `ENV["RAILS_PRODUCTION_KEY"]`
46+
`config/credentials/production.yml.enc` that can be decrypted using master key taken from `ENV["RAILS_MASTER_KEY"]`
4747
or stored in `config/credentials/production.key`.
4848
To edit given file use command `rails credentials:edit --environment production`
4949
Default paths can be overwritten by setting `config.credentials.content_path` and `config.credentials.key_path`.

railties/lib/rails/commands/credentials/credentials_command.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ def edit
2424

2525
ensure_editor_available(command: "bin/rails credentials:edit") || (return)
2626

27-
encrypted = Rails.application.encrypted(content_path, key_path: key_path, env_key: env_key)
27+
encrypted = Rails.application.encrypted(content_path, key_path: key_path)
2828

2929
ensure_encryption_key_has_been_added(key_path) if encrypted.key.nil?
3030
ensure_encrypted_file_has_been_added(content_path, key_path)
3131

3232
catch_editing_exceptions do
33-
change_encrypted_file_in_system_editor(content_path, key_path, env_key)
33+
change_encrypted_file_in_system_editor(content_path, key_path)
3434
end
3535

3636
say "File encrypted and saved."
@@ -41,7 +41,7 @@ def edit
4141
def show
4242
require_application_and_environment!
4343

44-
encrypted = Rails.application.encrypted(content_path, key_path: key_path, env_key: env_key)
44+
encrypted = Rails.application.encrypted(content_path, key_path: key_path)
4545

4646
say encrypted.read.presence || missing_encrypted_message(key: encrypted.key, key_path: key_path, file_path: content_path)
4747
end
@@ -55,10 +55,6 @@ def key_path
5555
options[:environment] ? "config/credentials/#{options[:environment]}.key" : "config/master.key"
5656
end
5757

58-
def env_key
59-
options[:environment] ? "RAILS_#{options[:environment].upcase}_KEY" : "RAILS_MASTER_KEY"
60-
end
61-
6258

6359
def ensure_encryption_key_has_been_added(key_path)
6460
encryption_key_file_generator.add_key_file(key_path)
@@ -69,8 +65,8 @@ def ensure_encrypted_file_has_been_added(file_path, key_path)
6965
encrypted_file_generator.add_encrypted_file_silently(file_path, key_path)
7066
end
7167

72-
def change_encrypted_file_in_system_editor(file_path, key_path, env_key)
73-
Rails.application.encrypted(file_path, key_path: key_path, env_key: env_key).change do |tmp_path|
68+
def change_encrypted_file_in_system_editor(file_path, key_path)
69+
Rails.application.encrypted(file_path, key_path: key_path).change do |tmp_path|
7470
system("#{ENV["EDITOR"]} #{tmp_path}")
7571
end
7672
end

0 commit comments

Comments
 (0)