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

Always configure database.yml and encryption key #38

Merged
merged 3 commits into from
May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 20 additions & 15 deletions bin/appliance_console
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ CLOUD_INIT_DISABLE_NETWORK_CONFIG = "network: {config: disabled}\n".freeze

module ManageIQ
module ApplianceConsole
def ensure_key_configured
key_config = ManageIQ::ApplianceConsole::KeyConfiguration.new
unless key_config.key_exist?
say "No encryption key found.\n"
say "For migrations, copy encryption key from a hardened appliance."
say "For worker and multi-region setups, copy key from another appliance.\n"
say "If this is your first appliance, just generate one now.\n\n"

if key_config.ask_question_loop
say("\nEncryption key now configured.\n\n")
else
say("\nEncryption key not configured.")
press_any_key
raise MiqSignalError
end
end
end

eth0 = LinuxAdmin::NetworkInterface.new(NETWORK_INTERFACE)
# Because it takes a few seconds, get the region once in the outside loop
region = ManageIQ::ApplianceConsole::DatabaseConfiguration.region
Expand Down Expand Up @@ -457,21 +475,7 @@ Static Network Configuration
when I18n.t("advanced_settings.db_config")
say("#{selection}\n\n")

key_config = ManageIQ::ApplianceConsole::KeyConfiguration.new
unless key_config.key_exist?
say "No encryption key found.\n"
say "For migrations, copy encryption key from a hardened appliance."
say "For worker and multi-region setups, copy key from another appliance.\n"
say "If this is your first appliance, just generate one now.\n\n"

if key_config.ask_question_loop
say("\nEncryption key now configured.\n\n")
else
say("\nEncryption key not configured.")
press_any_key
raise MiqSignalError
end
end
ensure_key_configured

options = {
"Create Internal Database" => "create_internal",
Expand Down Expand Up @@ -524,6 +528,7 @@ Static Network Configuration
when "standby"
db_replication = ManageIQ::ApplianceConsole::DatabaseReplicationStandby.new
logger.info("Configuring Server as Standby")
ensure_key_configured
end

if db_replication.ask_questions && db_replication.activate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def activate
stop_repmgrd
initialize_postgresql_disk if disk
PostgresAdmin.prep_data_directory if disk || resync_data
save_database_yml
generate_cluster_name &&
create_config_file(standby_host) &&
clone_standby_server &&
Expand Down Expand Up @@ -143,6 +144,10 @@ def node_number_valid?

private

def save_database_yml
InternalDatabaseConfiguration.new(:password => database_password).save
end

def record_for_node_number
c = PG::Connection.new(primary_connection_hash)
c.exec_params(<<-SQL, [node_number]).map_types!(PG::BasicTypeMapForResults.new(c)).first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def activate
end
initialize_postgresql_disk if disk
initialize_postgresql
return super if run_as_evm_server
run_as_evm_server ? (return super) : save
true
end

Expand Down
11 changes: 11 additions & 0 deletions spec/database_replication_standby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
before do
expect(subject).to receive(:stop_postgres)
expect(subject).to receive(:stop_repmgrd)
expect(subject).to receive(:save_database_yml)
expect(subject).to receive(:generate_cluster_name).and_return(true)
expect(subject).to receive(:create_config_file).and_return(true)
expect(subject).to receive(:clone_standby_server).and_return(true)
Expand Down Expand Up @@ -335,6 +336,16 @@
expect(subject.node_number_valid?).to be_falsey
end
end

context "#save_database_yml (private)" do
it "passes the configured password" do
subject.database_password = "supersecret"
conf = double("InternalDatabaseConfiguration")
expect(ManageIQ::ApplianceConsole::InternalDatabaseConfiguration).to receive(:new).with(:password => "supersecret").and_return(conf)
expect(conf).to receive(:save)
subject.send(:save_database_yml)
end
end
end

def with_empty_data_directory
Expand Down