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

Generate db_encrypted_fields_keyfile #205

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/puppet/functions/pulpcore/generate_fernet_key.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'securerandom'

Puppet::Functions.create_function(:'pulpcore::generate_fernet_key') do
# @return 32 byte url-safe base64-encoded (with padding) Fernet symmetric encryption key
dispatch :generate_fernet_key do
return_type 'Pattern[/\A([a-zA-Z]|\d|-|_){43}=\z/]'
end

def generate_fernet_key
SecureRandom.urlsafe_base64(32)+"="
end
end
10 changes: 10 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
mode => '0755',
}

file { $pulpcore::db_encrypted_fields_keyfile:
ensure => file,
content => $pulpcore::db_encrypted_fields_key,
owner => 'root',
group => $pulpcore::group,
mode => '0640',
show_diff => false,
require => File[$pulpcore::config_dir],
}

concat { 'pulpcore settings':
ensure => present,
path => $pulpcore::settings_file,
Expand Down
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
# @param django_secret_key
# SECRET_KEY for Django
#
# @param db_encrypted_fields_key
# String representing 32 byte secret key encoded in url-safe base64 alphabet, used to encrypt sensitive data in the DB.
#
# @param redis_db
# Redis DB number to use. By default, Redis supports a DB number of 0 through 15.
#
Expand Down Expand Up @@ -190,6 +193,7 @@
Optional[Stdlib::Absolutepath] $postgresql_db_ssl_key = undef,
Optional[Stdlib::Absolutepath] $postgresql_db_ssl_root_ca = undef,
String $django_secret_key = extlib::cache_data('pulpcore_cache_data', 'secret_key', extlib::random_password(50)),
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()),
Integer[0] $redis_db = 8,
Stdlib::Fqdn $servername = $facts['networking']['fqdn'],
Array[Stdlib::Absolutepath] $allowed_import_path = ['/var/lib/pulp/sync_imports'],
Expand All @@ -206,6 +210,7 @@
Hash[String[1], String[1]] $api_client_auth_cn_map = {},
) {
$settings_file = "${config_dir}/settings.py"
$db_encrypted_fields_keyfile = "${config_dir}/db_encrypted_fields_key"

contain pulpcore::install
contain pulpcore::database
Expand Down
8 changes: 8 additions & 0 deletions spec/acceptance/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class { 'pulpcore':
its(:body) { is_expected.to contain('artifacts_list') }
its(:exit_status) { is_expected.to eq 0 }
end

describe file('/etc/pulp/db_encrypted_fields_key') do
it { is_expected.to be_file }
it { is_expected.to be_mode 640 }
it { is_expected.to be_owned_by 'root' }
it { is_expected.to be_grouped_into 'pulp' }
its(:content) { is_expected.to match /\A([a-zA-Z]|\d|-|_){43}=\z/ }
end
end

describe 'reducing worker count' do
Expand Down