File tree 13 files changed +79
-8
lines changed 13 files changed +79
-8
lines changed Original file line number Diff line number Diff line change 1
- # use `rails secret` to generate this for production
1
+ # you can use `rails secret` to generate this for production
2
2
SECRET_KEY_BASE = dev_secret
3
+
4
+ # you can use `rails db:encryption:init` to generate these for production
5
+ ENCRYPTION_PRIMARY_KEY = dev_primary_key
6
+ ENCRYPTION_DETERMINISTIC_KEY = dev_deterministic_key
7
+ ENCRYPTION_KEY_DERIVATION_SALT = dev_derivation_salt
Original file line number Diff line number Diff line change 1
- # use `rails secret` to generate this for production
1
+ # you can use `rails secret` to generate this for production
2
2
SECRET_KEY_BASE = test_secret
3
+
4
+ # you can use `rails db:encryption:init` to generate these for production
5
+ ENCRYPTION_PRIMARY_KEY = test_primary_key
6
+ ENCRYPTION_DETERMINISTIC_KEY = test_deterministic_key
7
+ ENCRYPTION_KEY_DERIVATION_SALT = test_derivation_salt
Original file line number Diff line number Diff line change 16
16
"description" : " Secret key used by rails for encryption" ,
17
17
"generator" : " secret"
18
18
},
19
+ "ENCRYPTION_PRIMARY_KEY" : {
20
+ "description" : " Secret key used by rails for encryption" ,
21
+ "generator" : " secret"
22
+ },
23
+ "ENCRYPTION_DETERMINISTIC_KEY" : {
24
+ "description" : " Secret key used by rails for encryption" ,
25
+ "generator" : " secret"
26
+ },
27
+ "ENCRYPTION_KEY_DERIVATION_SALT" : {
28
+ "description" : " Secret key used by rails for encryption" ,
29
+ "generator" : " secret"
30
+ },
19
31
"LOCALE" : {
20
32
"description" : " Specify the translation locale you wish to use" ,
21
33
"value" : " en"
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ class User < ApplicationRecord
6
6
has_secure_password
7
7
has_secure_token :api_key
8
8
9
+ encrypts :api_key , deterministic : true
10
+
9
11
has_many :feeds , dependent : :delete_all
10
12
has_many :groups , dependent : :delete_all
11
13
Original file line number Diff line number Diff line change @@ -39,5 +39,12 @@ class Application < Rails::Application
39
39
config . generators . system_tests = nil
40
40
41
41
config . active_record . belongs_to_required_by_default = false
42
+
43
+ config . active_record . encryption . primary_key =
44
+ ENV . fetch ( "ENCRYPTION_PRIMARY_KEY" )
45
+ config . active_record . encryption . deterministic_key =
46
+ ENV . fetch ( "ENCRYPTION_DETERMINISTIC_KEY" )
47
+ config . active_record . encryption . key_derivation_salt =
48
+ ENV . fetch ( "ENCRYPTION_KEY_DERIVATION_SALT" )
42
49
end
43
50
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
- Dotenv . require_keys ( "SECRET_KEY_BASE" )
3
+ Dotenv . require_keys (
4
+ "SECRET_KEY_BASE" ,
5
+ "ENCRYPTION_PRIMARY_KEY" ,
6
+ "ENCRYPTION_DETERMINISTIC_KEY" ,
7
+ "ENCRYPTION_KEY_DERIVATION_SALT"
8
+ )
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ class EncryptAPIKey < ActiveRecord ::Migration [ 7.0 ]
4
+ def change
5
+ ActiveRecord ::Encryption . config . support_unencrypted_data = true
6
+
7
+ User . find_each do |user |
8
+ user . regenerate_api_key if user . api_key . blank?
9
+ user . encrypt
10
+ end
11
+
12
+ ActiveRecord ::Encryption . config . support_unencrypted_data = false
13
+
14
+ change_column_null :users , :api_key , false
15
+ add_index :users , :api_key , unique : true
16
+ end
17
+ end
Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ services:
19
19
ports :
20
20
- 80:8080
21
21
environment :
22
- - SECRET_KEY_BASE=YOUR_SECRET_KEY_BASE
22
+ - SECRET_KEY_BASE=<your configuration>
23
+ - ENCRYPTION_PRIMARY_KEY<your configuration>
24
+ - ENCRYPTION_DETERMINISTIC_KEY=<your configuration>
25
+ - ENCRYPTION_KEY_DERIVATION_SALT=<your configuration>
23
26
- PORT=8080
24
27
- DATABASE_URL=postgres://db_user:super_secret_password@postgres:5432/stringer
Original file line number Diff line number Diff line change 2
2
git clone
[email protected] :stringer-rss/stringer.git
3
3
cd stringer
4
4
heroku create
5
+
6
+ heroku config:set SECRET_KEY_BASE=` openssl rand -hex 64`
7
+ heroku config:set ENCRYPTION_PRIMARY_KEY=` openssl rand -hex 64`
8
+ heroku config:set ENCRYPTION_DETERMINISTIC_KEY=` openssl rand -hex 64`
9
+ heroku config:set ENCRYPTION_KEY_DERIVATION_SALT=` openssl rand -hex 64`
10
+
5
11
git push heroku main
6
12
7
13
heroku config:set APP_URL=` heroku apps:info --shell | grep web_url | cut -d= -f2`
8
- heroku config:set SECRET_KEY_BASE=` openssl rand -hex 64`
9
14
10
15
heroku run rake db:migrate
11
16
heroku restart
Original file line number Diff line number Diff line change @@ -32,10 +32,13 @@ Deploying into OpenShift
32
32
chmod +x .openshift/action_hooks/deploy
33
33
```
34
34
35
- 5 . Set the SECRET_KEY_BASE as a rhc environment variable by generating it with the command below.
35
+ 5 . Set the environment variables by generating them with the commands below.
36
36
37
37
``` sh
38
38
rhc env set SECRET_KEY_BASE=" ` openssl rand -hex 64` "
39
+ rhc env set ENCRYPTION_PRIMARY_KEY=" ` openssl rand -hex 64` "
40
+ rhc env set ENCRYPTION_DETERMINISTIC_KEY=" ` openssl rand -hex 64` "
41
+ rhc env set ENCRYPTION_KEY_DERIVATION_SALT=" ` openssl rand -hex 64` "
39
42
```
40
43
41
44
6 . Configuration of the database server is next. Open the file config/database.yml and add in the configuration for Production as shown below. OpenShift is able to use environment variables to push the information into the application.
Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ Stringer uses environment variables to configure the application. Edit these val
93
93
echo 'export RACK_ENV="production"' >> $HOME/.bash_profile
94
94
echo 'export RAILS_ENV="production"' >> $HOME/.bash_profile
95
95
echo "export SECRET_KEY_BASE=`openssl rand -hex 64`" >> $HOME/.bash_profile
96
+ echo "export ENCRYPTION_PRIMARY_KEY=`openssl rand -hex 64`" >> $HOME/.bash_profile
97
+ echo "export ENCRYPTION_DETERMINISTIC_KEY=`openssl rand -hex 64`" >> $HOME/.bash_profile
98
+ echo "export ENCRYPTION_KEY_DERIVATION_SALT=`openssl rand -hex 64`" >> $HOME/.bash_profile
96
99
source ~/.bash_profile
97
100
98
101
Tell stringer to run the database in production mode, using the ` postgres ` database you created earlier.
Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ docker run --detach \
37
37
-e PORT=8080 \
38
38
-e DATABASE_URL=postgres://postgres:myPassword@stringer-postgres/stringer \
39
39
-e SECRET_KEY_BASE=$( openssl rand -hex 64) \
40
+ -e ENCRYPTION_PRIMARY_KEY=$( openssl rand -hex 64) \
41
+ -e ENCRYPTION_DETERMINISTIC_KEY=$( openssl rand -hex 64) \
42
+ -e ENCRYPTION_KEY_DERIVATION_SALT=$( openssl rand -hex 64) \
40
43
-e FETCH_FEEDS_CRON=" */5 * * * *" \ # optional
41
44
-e CLEANUP_CRON=" 0 0 * * *" \ # optional
42
45
-p 127.0.0.1:8080:8080 \
You can’t perform that action at this time.
0 commit comments