Skip to content

Commit

Permalink
Merge pull request #690 from brendandixon/master
Browse files Browse the repository at this point in the history
Enabled FIPS support and address #668.
Support mixed case hostnames on RedHat #686.
  • Loading branch information
brendandixon authored May 1, 2017
2 parents aff2499 + a4b653f commit 955b532
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 3 deletions.
2 changes: 2 additions & 0 deletions azurelinuxagent/common/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def get_agent_pid_file_path(conf=__conf__):
def get_ext_log_dir(conf=__conf__):
return conf.get("Extension.LogDir", "/var/log/azure")

def get_fips_enabled(conf=__conf__):
return conf.get_switch("OS.FIPSEnabled", False)

def get_openssl_cmd(conf=__conf__):
return conf.get("OS.OpensslPath", "/usr/bin/openssl")
Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/common/osutil/redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def set_hostname(self, hostname):
Due to a bug in systemd in Centos-7.0, if this call fails, fallback
to hostname.
"""
hostnamectl_cmd = "hostnamectl set-hostname {0}".format(hostname)
hostnamectl_cmd = "hostnamectl set-hostname {0} --static".format(hostname)
if shellutil.run(hostnamectl_cmd, chk_err=False) != 0:
logger.warn("[{0}] failed, attempting fallback".format(hostnamectl_cmd))
DefaultOSUtil.set_hostname(self, hostname)
Expand Down
8 changes: 8 additions & 0 deletions azurelinuxagent/daemon/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
from azurelinuxagent.pa.provision import get_provision_handler
from azurelinuxagent.pa.rdma import get_rdma_handler

OPENSSL_FIPS_ENVIRONMENT = "OPENSSL_FIPS"


def get_daemon_handler():
return DaemonHandler()
Expand All @@ -61,6 +63,12 @@ def run(self):

self.check_pid()

# If FIPS is enabled, set the OpenSSL environment variable
# Note:
# -- Subprocesses inherit the current environment
if conf.get_fips_enabled():
os.environ[OPENSSL_FIPS_ENVIRONMENT] = '1'

while self.running:
try:
self.daemon()
Expand Down
3 changes: 3 additions & 0 deletions config/alpine/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Logs.Verbose=n
# Preferred network interface to communicate with Azure platform
Network.Interface=eth0

# Is FIPS enabled
OS.FIPSEnabled=n

# Root device timeout in seconds.
OS.RootDeviceScsiTimeout=300

Expand Down
3 changes: 3 additions & 0 deletions config/arch/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ LBProbeResponder=y
# Enable verbose logging (y|n)
Logs.Verbose=n

# Is FIPS enabled
OS.FIPSEnabled=n

# Root device timeout in seconds.
OS.RootDeviceScsiTimeout=300

Expand Down
3 changes: 3 additions & 0 deletions config/bigip/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ LBProbeResponder=y
# Enable verbose logging (y|n)
Logs.Verbose=n

# Is FIPS enabled
OS.FIPSEnabled=n

# Root device timeout in seconds.
OS.RootDeviceScsiTimeout=300

Expand Down
3 changes: 3 additions & 0 deletions config/clearlinux/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ ResourceDisk.SwapSizeMB=0
# Enable verbose logging (y|n)
Logs.Verbose=n

# Is FIPS enabled
OS.FIPSEnabled=n

# Root device timeout in seconds.
OS.RootDeviceScsiTimeout=300

Expand Down
3 changes: 3 additions & 0 deletions config/coreos/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ LBProbeResponder=y
# Enable verbose logging (y|n)
Logs.Verbose=n

# Is FIPS enabled
OS.FIPSEnabled=n

# Root device timeout in seconds.
OS.RootDeviceScsiTimeout=300

Expand Down
3 changes: 3 additions & 0 deletions config/freebsd/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ResourceDisk.MountOptions=None
# Enable verbose logging (y|n)
Logs.Verbose=n

# Is FIPS enabled
OS.FIPSEnabled=n

# Root device timeout in seconds.
OS.RootDeviceScsiTimeout=300

Expand Down
3 changes: 3 additions & 0 deletions config/suse/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ LBProbeResponder=y
# Enable verbose logging (y|n)
Logs.Verbose=n

# Is FIPS enabled
OS.FIPSEnabled=n

# Root device timeout in seconds.
OS.RootDeviceScsiTimeout=300

Expand Down
3 changes: 3 additions & 0 deletions config/ubuntu/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ LBProbeResponder=y
# Enable verbose logging (y|n)
Logs.Verbose=n

# Is FIPS enabled
OS.FIPSEnabled=n

# Root device timeout in seconds.
OS.RootDeviceScsiTimeout=300

Expand Down
3 changes: 3 additions & 0 deletions config/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ ResourceDisk.MountOptions=None
# Enable verbose logging (y|n)
Logs.Verbose=n

# Is FIPS enabled
OS.FIPSEnabled=n

# Root device timeout in seconds.
OS.RootDeviceScsiTimeout=300

Expand Down
27 changes: 25 additions & 2 deletions tests/daemon/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#
# Requires Python 2.4+ and Openssl 1.0+
#
from azurelinuxagent.daemon import get_daemon_handler

from azurelinuxagent.daemon import *
from azurelinuxagent.daemon.main import OPENSSL_FIPS_ENVIRONMENT
from tests.tools import *


Expand All @@ -30,8 +32,9 @@ def __call__(self, *args, **kw):
self.daemon_handler.running = False
raise Exception("Mock unhandled exception")

@patch("time.sleep")
class TestDaemon(AgentTestCase):

@patch("time.sleep")
def test_daemon_restart(self, mock_sleep):
#Mock daemon function
daemon_handler = get_daemon_handler()
Expand All @@ -45,6 +48,7 @@ def test_daemon_restart(self, mock_sleep):
mock_sleep.assert_any_call(15)
self.assertEquals(2, daemon_handler.daemon.call_count)

@patch("time.sleep")
@patch("azurelinuxagent.daemon.main.conf")
@patch("azurelinuxagent.daemon.main.sys.exit")
def test_check_pid(self, mock_exit, mock_conf, mock_sleep):
Expand All @@ -58,6 +62,25 @@ def test_check_pid(self, mock_exit, mock_conf, mock_sleep):

daemon_handler.check_pid()
mock_exit.assert_any_call(0)

@patch("azurelinuxagent.daemon.main.DaemonHandler.check_pid")
@patch("azurelinuxagent.common.conf.get_fips_enabled", return_value=True)
def test_set_openssl_fips(self, mock_conf, mock_daemon):
daemon_handler = get_daemon_handler()
daemon_handler.running = False
with patch.dict("os.environ"):
daemon_handler.run()
self.assertTrue(OPENSSL_FIPS_ENVIRONMENT in os.environ)
self.assertEqual('1', os.environ[OPENSSL_FIPS_ENVIRONMENT])

@patch("azurelinuxagent.daemon.main.DaemonHandler.check_pid")
@patch("azurelinuxagent.common.conf.get_fips_enabled", return_value=False)
def test_does_not_set_openssl_fips(self, mock_conf, mock_daemon):
daemon_handler = get_daemon_handler()
daemon_handler.running = False
with patch.dict("os.environ"):
daemon_handler.run()
self.assertFalse(OPENSSL_FIPS_ENVIRONMENT in os.environ)

if __name__ == '__main__':
unittest.main()
Expand Down

0 comments on commit 955b532

Please sign in to comment.