Skip to content

Commit

Permalink
Port NSBSD system to the latest version of waagent (#2828)
Browse files Browse the repository at this point in the history
* nsbsd: adapt to recent dns.resolver

* osutil: Provide a get_root_username function for systems where its not 'root' (like in nsbsd)

* nsbsd: tune the configuration filepath

* nsbsd: fix lib installation path

---------

Co-authored-by: Norberto Arrieta <[email protected]>
  • Loading branch information
sebastienb-stormshield and narrieta authored Jun 15, 2023
1 parent f86c003 commit 01bc320
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion azurelinuxagent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, verbose, conf_file_path=None):
if os.path.isfile(ext_log_dir):
raise Exception("{0} is a file".format(ext_log_dir))
if not os.path.isdir(ext_log_dir):
fileutil.mkdir(ext_log_dir, mode=0o755, owner="root")
fileutil.mkdir(ext_log_dir, mode=0o755, owner=self.osutil.get_root_username())
except Exception as e:
logger.error(
"Exception occurred while creating extension "
Expand Down
3 changes: 3 additions & 0 deletions azurelinuxagent/common/osutil/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ def get_userentry(username):
except KeyError:
return None

def get_root_username(self):
return "root"

def is_sys_user(self, username):
"""
Check whether use is a system user.
Expand Down
7 changes: 6 additions & 1 deletion azurelinuxagent/common/osutil/nsbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class NSBSDOSUtil(FreeBSDOSUtil):

def __init__(self):
super(NSBSDOSUtil, self).__init__()
self.agent_conf_file_path = '/etc/waagent.conf'

if self.resolver is None:
# NSBSD doesn't have a system resolver, configure a python one
Expand All @@ -37,7 +38,7 @@ def __init__(self):
except ImportError:
raise OSUtilError("Python DNS resolver not available. Cannot proceed!")

self.resolver = dns.resolver.Resolver()
self.resolver = dns.resolver.Resolver(configure=False)
servers = []
cmd = "getconf /usr/Firewall/ConfigFiles/dns Servers | tail -n +2"
ret, output = shellutil.run_get_output(cmd) # pylint: disable=W0612
Expand All @@ -47,6 +48,7 @@ def __init__(self):
server = server[:-1] # remove last '='
cmd = "grep '{}' /etc/hosts".format(server) + " | awk '{print $1}'"
ret, ip = shellutil.run_get_output(cmd)
ip = ip.strip() # Remove new line char
servers.append(ip)
self.resolver.nameservers = servers
dns.resolver.override_system_resolver(self.resolver)
Expand Down Expand Up @@ -74,6 +76,9 @@ def conf_sshd(self, disable_password):
logger.info("{0} SSH password-based authentication methods."
.format("Disabled" if disable_password else "Enabled"))

def get_root_username(self):
return "admin"

def useradd(self, username, expiration=None, comment=None):
"""
Create user account with 'username'
Expand Down
2 changes: 1 addition & 1 deletion config/nsbsd/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ OS.SudoersDir=/usr/local/etc/sudoers.d
# DetectScvmmEnv=n

#
Lib.Dir=/usr/Firewall/var/waagent
Lib.Dir=/usr/Firewall/lib/waagent

#
# DVD.MountPoint=/mnt/cdrom/secure
Expand Down

0 comments on commit 01bc320

Please sign in to comment.