From 3f6536425c6b29d216c14081d2dd5e304445e5ac Mon Sep 17 00:00:00 2001 From: Andy Zaugg Date: Thu, 29 Oct 2020 10:36:01 -0700 Subject: [PATCH 1/2] Allow for more fine tune provisioning options Allow a user to better control what WAAgent provisions during a Provisioning event. Allow the user to control if, useraccounts, hostname and custom data be set. --- README.md | 16 ++++++++++++++++ azurelinuxagent/common/conf.py | 10 ++++++++++ azurelinuxagent/pa/provision/default.py | 15 +++++++++------ config/alpine/waagent.conf | 6 ++++++ config/arch/waagent.conf | 6 ++++++ config/clearlinux/waagent.conf | 6 ++++++ config/coreos/waagent.conf | 6 ++++++ config/debian/waagent.conf | 6 ++++++ config/gaia/waagent.conf | 6 ++++++ config/iosxe/waagent.conf | 6 ++++++ config/nsbsd/waagent.conf | 6 ++++++ config/openbsd/waagent.conf | 6 ++++++ config/suse/waagent.conf | 6 ++++++ config/ubuntu/waagent.conf | 6 ++++++ 14 files changed, 101 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 24ec457d7..b56251adc 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,8 @@ Provisioning.DecodeCustomData=n Provisioning.ExecuteCustomData=n Provisioning.PasswordCryptId=6 Provisioning.PasswordCryptSaltLength=10 +Provisioning.SetHostName=True +Provisioning.UserAccounts=True ResourceDisk.Format=y ResourceDisk.Filesystem=ext4 ResourceDisk.MountPoint=/mnt/resource @@ -410,6 +412,20 @@ _Default: 10_ Length of random salt used when generating password hash. +#### __Provisioning.SetHostName__ + +_Type: Boolean_ +_Default: y_ + +Control if WAAgent should attempt to set the VMs hostname + +#### __Provisioning.UserAccounts + +_Type: Boolean_ +_Default: y_ + +Control if WAAgent should configure user accounts + #### __ResourceDisk.Format__ _Type: Boolean_ diff --git a/azurelinuxagent/common/conf.py b/azurelinuxagent/common/conf.py index 102c3c7db..9f6129820 100644 --- a/azurelinuxagent/common/conf.py +++ b/azurelinuxagent/common/conf.py @@ -105,6 +105,8 @@ def load_conf_from_file(conf_file_path, conf=__conf__): "Provisioning.DecodeCustomData": False, "Provisioning.ExecuteCustomData": False, "Provisioning.MonitorHostName": False, + "Provisioning.SetHostName": True, + "Provisioning.UserAccounts": True, "DetectScvmmEnv": False, "ResourceDisk.Format": False, "ResourceDisk.EnableSwap": False, @@ -389,6 +391,14 @@ def get_monitor_hostname_period(conf=__conf__): return conf.get_int("Provisioning.MonitorHostNamePeriod", 30) +def get_provisioning_hostname_set(conf=__conf__): + return conf.get_switch("Provisioning.SetHostName", True) + + +def get_provisioning_user_account_set(conf=__conf__): + return conf.get_switch("Provisioning.UserAccounts", True) + + def get_httpproxy_host(conf=__conf__): return conf.get("HttpProxy.Host", None) diff --git a/azurelinuxagent/pa/provision/default.py b/azurelinuxagent/pa/provision/default.py index 9eb4eba82..1b36a521e 100644 --- a/azurelinuxagent/pa/provision/default.py +++ b/azurelinuxagent/pa/provision/default.py @@ -229,13 +229,16 @@ def handle_provision_guest_agent(self, provision_guest_agent): def provision(self, ovfenv): logger.info("Handle ovf-env.xml.") try: - logger.info("Set hostname [{0}]".format(ovfenv.hostname)) - self.osutil.set_hostname(ovfenv.hostname) - logger.info("Publish hostname [{0}]".format(ovfenv.hostname)) - self.osutil.publish_hostname(ovfenv.hostname) + if conf.get_provisioning_hostname_set(): + logger.info("Set hostname [{0}]".format(ovfenv.hostname)) + self.osutil.set_hostname(ovfenv.hostname) - self.config_user_account(ovfenv) + logger.info("Publish hostname [{0}]".format(ovfenv.hostname)) + self.osutil.publish_hostname(ovfenv.hostname) + + if conf.get_provisioning_user_account_set(): + self.config_user_account(ovfenv) self.save_customdata(ovfenv) @@ -256,7 +259,7 @@ def config_user_account(self, ovfenv): self.osutil.chpasswd(ovfenv.username, ovfenv.user_password, crypt_id=crypt_id, salt_len=salt_len) - logger.info("Configure sudoer") + logger.info("Configure sudoers") self.osutil.conf_sudoer(ovfenv.username, nopasswd=ovfenv.user_password is None) diff --git a/config/alpine/waagent.conf b/config/alpine/waagent.conf index 4ab283632..cbe0eb2b9 100644 --- a/config/alpine/waagent.conf +++ b/config/alpine/waagent.conf @@ -29,6 +29,12 @@ Provisioning.DecodeCustomData=y # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=y +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Format if unformatted. If 'n', resource disk will not be mounted. ResourceDisk.Format=y diff --git a/config/arch/waagent.conf b/config/arch/waagent.conf index ef914e9f8..37d0ebb2f 100644 --- a/config/arch/waagent.conf +++ b/config/arch/waagent.conf @@ -25,6 +25,12 @@ Provisioning.DecodeCustomData=n # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=n +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Algorithm used by crypt when generating password hash. #Provisioning.PasswordCryptId=6 diff --git a/config/clearlinux/waagent.conf b/config/clearlinux/waagent.conf index 0b70d2621..939f1e842 100644 --- a/config/clearlinux/waagent.conf +++ b/config/clearlinux/waagent.conf @@ -36,6 +36,12 @@ Provisioning.DecodeCustomData=y # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=n +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Allow reset password of sys user Provisioning.AllowResetSysUser=n diff --git a/config/coreos/waagent.conf b/config/coreos/waagent.conf index 1965b8018..3d67570de 100644 --- a/config/coreos/waagent.conf +++ b/config/coreos/waagent.conf @@ -29,6 +29,12 @@ Provisioning.DecodeCustomData=n # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=n +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Algorithm used by crypt when generating password hash. #Provisioning.PasswordCryptId=6 diff --git a/config/debian/waagent.conf b/config/debian/waagent.conf index 30647d50a..a70cb163c 100644 --- a/config/debian/waagent.conf +++ b/config/debian/waagent.conf @@ -29,6 +29,12 @@ Provisioning.DecodeCustomData=n # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=n +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Algorithm used by crypt when generating password hash. #Provisioning.PasswordCryptId=6 diff --git a/config/gaia/waagent.conf b/config/gaia/waagent.conf index 0e171d28b..26e008e76 100644 --- a/config/gaia/waagent.conf +++ b/config/gaia/waagent.conf @@ -29,6 +29,12 @@ Provisioning.DecodeCustomData=y # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=n +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Algorithm used by crypt when generating password hash. Provisioning.PasswordCryptId=1 diff --git a/config/iosxe/waagent.conf b/config/iosxe/waagent.conf index 764058986..15457e8e6 100644 --- a/config/iosxe/waagent.conf +++ b/config/iosxe/waagent.conf @@ -25,6 +25,12 @@ Provisioning.DecodeCustomData=n # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=n +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Algorithm used by crypt when generating password hash. #Provisioning.PasswordCryptId=6 diff --git a/config/nsbsd/waagent.conf b/config/nsbsd/waagent.conf index 9d0ce74d8..2026766ea 100644 --- a/config/nsbsd/waagent.conf +++ b/config/nsbsd/waagent.conf @@ -25,6 +25,12 @@ Provisioning.DecodeCustomData=n # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=n +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Algorithm used by crypt when generating password hash. #Provisioning.PasswordCryptId=6 diff --git a/config/openbsd/waagent.conf b/config/openbsd/waagent.conf index a644d5d69..9081cd49c 100644 --- a/config/openbsd/waagent.conf +++ b/config/openbsd/waagent.conf @@ -25,6 +25,12 @@ Provisioning.DecodeCustomData=n # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=n +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Algorithm used by crypt when generating password hash. #Provisioning.PasswordCryptId=6 diff --git a/config/suse/waagent.conf b/config/suse/waagent.conf index 85fd2a3e9..0807db8a0 100644 --- a/config/suse/waagent.conf +++ b/config/suse/waagent.conf @@ -29,6 +29,12 @@ Provisioning.DecodeCustomData=n # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=n +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Algorithm used by crypt when generating password hash. #Provisioning.PasswordCryptId=6 diff --git a/config/ubuntu/waagent.conf b/config/ubuntu/waagent.conf index 22d48a8ef..b9ac2229f 100644 --- a/config/ubuntu/waagent.conf +++ b/config/ubuntu/waagent.conf @@ -29,6 +29,12 @@ Provisioning.DecodeCustomData=n # Execute CustomData after provisioning. Provisioning.ExecuteCustomData=n +# Set hostname of host by WAAgent on host provisioning. +Provisioning.SetHostName=y + +# Allow WAAgent to provision useraccounts. +Provisioning.UserAccounts=y + # Algorithm used by crypt when generating password hash. #Provisioning.PasswordCryptId=6 From 1b83ad0f662539dc3ed6933b2595da23e79bc8a0 Mon Sep 17 00:00:00 2001 From: Andy Zaugg Date: Thu, 29 Oct 2020 10:36:01 -0700 Subject: [PATCH 2/2] Allow for more fine tune provisioning options Allow a user to better control what WAAgent provisions during a Provisioning event. Allow the user to control if, useraccounts, hostname and custom data be set. --- tests/test_agent.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_agent.py b/tests/test_agent.py index ad7f6a631..e412e1d89 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -71,6 +71,8 @@ Provisioning.PasswordCryptSaltLength = 10 Provisioning.RegenerateSshHostKeyPair = True Provisioning.SshHostKeyPairType = rsa +Provisioning.SetHostName = True +Provisioning.UserAccounts = True ResourceDisk.EnableSwap = False ResourceDisk.EnableSwapEncryption = False ResourceDisk.Filesystem = ext4