Skip to content

Commit 14279c6

Browse files
committed
Generate db_encrypted_fields_keyfile
Pulpcore 3.15 will require a Fernet symmetric encryption key to encrypt certain sensitive database fields. This is expected to contain 32 pseudorandom bytes in url-safe base64-encoded format, with padding.
1 parent 137128e commit 14279c6

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'securerandom'
2+
3+
Puppet::Functions.create_function(:'pulpcore::generate_fernet_key') do
4+
# @return 32 byte url-safe base64-encoded (with padding) Fernet symmetric encryption key
5+
dispatch :generate_fernet_key do
6+
return_type 'Pattern[/\A([a-zA-Z]|\d|-|_){43}=\z/]'
7+
end
8+
9+
def generate_fernet_key
10+
SecureRandom.urlsafe_base64(32)+"="
11+
end
12+
end

manifests/config.pp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
mode => '0755',
99
}
1010

11+
file { $pulpcore::db_encrypted_fields_keyfile:
12+
ensure => file,
13+
content => $pulpcore::db_encrypted_fields_key,
14+
owner => 'root',
15+
group => $pulpcore::group,
16+
mode => '0640',
17+
show_diff => false,
18+
require => File[$pulpcore::config_dir],
19+
}
20+
1121
concat { 'pulpcore settings':
1222
ensure => present,
1323
path => $pulpcore::settings_file,

manifests/init.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@
109109
# @param django_secret_key
110110
# SECRET_KEY for Django
111111
#
112+
# @param db_encrypted_fields_key
113+
# String representing 32 byte secret key encoded in url-safe base64 alphabet, used to encrypt sensitive data in the DB.
114+
#
112115
# @param redis_db
113116
# Redis DB number to use. By default, Redis supports a DB number of 0 through 15.
114117
#
@@ -190,6 +193,7 @@
190193
Optional[Stdlib::Absolutepath] $postgresql_db_ssl_key = undef,
191194
Optional[Stdlib::Absolutepath] $postgresql_db_ssl_root_ca = undef,
192195
String $django_secret_key = extlib::cache_data('pulpcore_cache_data', 'secret_key', extlib::random_password(50)),
196+
Pattern[/\A([a-zA-Z]|\d|-|_){43}=\z/] $db_encrypted_fields_key = extlib::cache_data('pulpcore_cache_data', 'db_encrypted_fields_key', pulpcore::generate_fernet_key()),
193197
Integer[0] $redis_db = 8,
194198
Stdlib::Fqdn $servername = $facts['networking']['fqdn'],
195199
Array[Stdlib::Absolutepath] $allowed_import_path = ['/var/lib/pulp/sync_imports'],
@@ -206,6 +210,7 @@
206210
Hash[String[1], String[1]] $api_client_auth_cn_map = {},
207211
) {
208212
$settings_file = "${config_dir}/settings.py"
213+
$db_encrypted_fields_keyfile = "${config_dir}/db_encrypted_fields_key"
209214

210215
contain pulpcore::install
211216
contain pulpcore::database

spec/acceptance/basic_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class { 'pulpcore':
7373
its(:body) { is_expected.to contain('artifacts_list') }
7474
its(:exit_status) { is_expected.to eq 0 }
7575
end
76+
77+
describe file('/etc/pulp/db_encrypted_fields_key') do
78+
it { is_expected.to be_file }
79+
it { is_expected.to be_mode 640 }
80+
it { is_expected.to be_owned_by 'root' }
81+
it { is_expected.to be_grouped_into 'pulp' }
82+
its(:content) { is_expected.to match /\A([a-zA-Z]|\d|-|_){43}=\z/ }
83+
end
7684
end
7785

7886
describe 'reducing worker count' do

0 commit comments

Comments
 (0)