Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[1LP][RFR] Update password gem name #9772

Merged
merged 1 commit into from
Dec 18, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cfme/tests/automate/test_common_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class TestDropdownView(InfraVmSummaryView):

@pytest.mark.tier(3)
@pytest.mark.meta(automates=[1720432])
def test_miq_password_decrypt(klass):
def test_miq_password_decrypt(appliance, klass):
"""
Polarion:
assignee: ghubale
Expand All @@ -142,9 +142,9 @@ def test_miq_password_decrypt(klass):
# Ruby script for decrypting password
script = (
'require "manageiq-password"\n'
'root_password = MiqPassword.encrypt("abc")\n'
f'root_password = {appliance.password_gem}.encrypt("abc")\n'
'$evm.log("info", "Root Password is #{root_password}")\n'
'root_password_decrypted = MiqPassword.decrypt(root_password)\n'
f'root_password_decrypted = {appliance.password_gem}.decrypt(root_password)\n'
'$evm.log("info", "Decrypted password is #{root_password_decrypted}")'
)

Expand Down
10 changes: 9 additions & 1 deletion cfme/utils/appliance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,20 @@ def seal_for_templatizing(self):
ssh_client.run_command('echo "vm.swappiness = 1" >> /etc/sysctl.conf',
ensure_host=True)

@cached_property
def password_gem(self):
return VersionPicker({
Version.lowest(): 'MiqPassword',
'5.11': 'ManageIQ::Password'
}).pick(self.version)

def _encrypt_string(self, string):
try:
# Let's not log passwords
logging.disable(logging.CRITICAL)
result = self.ssh_client.run_rails_command(
"\"puts MiqPassword.encrypt('{}')\"".format(string))
f'"puts {self.password_gem}.encrypt(\'{string}\')"'
)
return result.output.strip()
finally:
logging.disable(logging.NOTSET)
Expand Down
3 changes: 3 additions & 0 deletions scripts/harden_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def generate_key(address):
def update_db_yaml(address):
with SSHClient(hostname=address, **ssh_creds) as client:
client.run_command('cd /var/www/miq/vmdb')
# TODO Issue 8595, MiqPassword alias/gem will go away
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks for this.

# IPAppliance.password_gem property version picks the gem name
# We only have an address here, will have to look for the gem.
result = client.run_rails_command(
'\'puts MiqPassword.encrypt("smartvm");\'')
if result.failed:
Expand Down