sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init 10 months ago
Clone
ea00c4
From bcbd6be99d8317793aff905c4222c351a1bf5c46 Mon Sep 17 00:00:00 2001
ea00c4
From: Eduardo Otubo <otubo@redhat.com>
ea00c4
Date: Thu, 21 Jan 2021 10:08:49 +0100
ea00c4
Subject: [PATCH 1/2] DataSourceAzure: update password for defuser if exists
ea00c4
 (#671)
ea00c4
ea00c4
RH-Author: Eduardo Terrell Ferrari Otubo (eterrell)
ea00c4
RH-MergeRequest: 37: DataSourceAzure: update password for defuser if exists (#671)
ea00c4
RH-Commit: [1/1] 264092a68a3771cc4ed99dad5b93f7a1433e143a (eterrell/cloud-init)
ea00c4
RH-Bugzilla: 1900892
ea00c4
ea00c4
commit eea754492f074e00b601cf77aa278e3623857c5a
ea00c4
Author: Anh Vo <anhvo@microsoft.com>
ea00c4
Date:   Thu Nov 19 00:35:46 2020 -0500
ea00c4
ea00c4
    DataSourceAzure: update password for defuser if exists (#671)
ea00c4
ea00c4
    cc_set_password will only update the password for the default user if
ea00c4
    cfg['password'] is set. The existing code of datasource Azure will fail
ea00c4
    to update the default user's password because it does not set that
ea00c4
    metadata. If the default user doesn't exist in the image, the current
ea00c4
    code works fine because the password is set during user create and
ea00c4
    not in cc_set_password
ea00c4
ea00c4
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
ea00c4
---
ea00c4
 cloudinit/sources/DataSourceAzure.py          | 2 +-
ea00c4
 tests/unittests/test_datasource/test_azure.py | 3 +++
ea00c4
 2 files changed, 4 insertions(+), 1 deletion(-)
ea00c4
ea00c4
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
ea00c4
index 1c214db9..d4a2d60f 100755
ea00c4
--- a/cloudinit/sources/DataSourceAzure.py
ea00c4
+++ b/cloudinit/sources/DataSourceAzure.py
ea00c4
@@ -1231,7 +1231,7 @@ def read_azure_ovf(contents):
ea00c4
     if password:
ea00c4
         defuser['lock_passwd'] = False
ea00c4
         if DEF_PASSWD_REDACTION != password:
ea00c4
-            defuser['passwd'] = encrypt_pass(password)
ea00c4
+            defuser['passwd'] = cfg['password'] = encrypt_pass(password)
ea00c4
 
ea00c4
     if defuser:
ea00c4
         cfg['system_info'] = {'default_user': defuser}
ea00c4
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
ea00c4
index 47e03bd1..2059990a 100644
ea00c4
--- a/tests/unittests/test_datasource/test_azure.py
ea00c4
+++ b/tests/unittests/test_datasource/test_azure.py
ea00c4
@@ -919,6 +919,9 @@ scbus-1 on xpt0 bus 0
ea00c4
                          crypt.crypt(odata['UserPassword'],
ea00c4
                                      defuser['passwd'][0:pos]))
ea00c4
 
ea00c4
+        # the same hashed value should also be present in cfg['password']
ea00c4
+        self.assertEqual(defuser['passwd'], dsrc.cfg['password'])
ea00c4
+
ea00c4
     def test_user_not_locked_if_password_redacted(self):
ea00c4
         odata = {'HostName': "myhost", 'UserName': "myuser",
ea00c4
                  'UserPassword': dsaz.DEF_PASSWD_REDACTION}
ea00c4
-- 
ea00c4
2.18.4
ea00c4