Merge ~ltrager/maas:lp1916860 into maas:master

Proposed by Lee Trager
Status: Merged
Approved by: Adam Collard
Approved revision: 60d33a59c1ee5aac6f2e4cc2b64963341495605f
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1916860
Merge into: maas:master
Diff against target: 114 lines (+61/-26)
2 files modified
src/metadataserver/builtin_scripts/commissioning_scripts/bmc_config.py (+25/-25)
src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_bmc_config.py (+36/-1)
Reviewer Review Type Date Requested Status
Björn Tillenius Approve
MAAS Lander Approve
Review via email: mp+399134@code.launchpad.net

Commit message

LP: #1916860 - Check for gaps in supported ciphers when using ipmitool

When ipmitool was being used to configure IPMI ciphers MAAS wasn't
accounting for BMCs which omit support for certain ciphers. In this
case the setting string MAAS uses to enable ciphers was offset which
resulted in the wrong ciphers being enabled and disabled.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1916860 lp:~ltrager/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/9402/console
COMMIT: 403734fb90155f1fac808b4aa98f18819045143d

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1916860 lp:~ltrager/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: c81a66a887094ee336bd26c5e06f3a07efca99dd

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1916860 lp:~ltrager/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 60d33a59c1ee5aac6f2e4cc2b64963341495605f

review: Approve
Revision history for this message
Björn Tillenius (bjornt) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/metadataserver/builtin_scripts/commissioning_scripts/bmc_config.py b/src/metadataserver/builtin_scripts/commissioning_scripts/bmc_config.py
2index 69cc4c6..2c2777c 100755
3--- a/src/metadataserver/builtin_scripts/commissioning_scripts/bmc_config.py
4+++ b/src/metadataserver/builtin_scripts/commissioning_scripts/bmc_config.py
5@@ -622,32 +622,32 @@ class IPMI(BMCConfig):
6 supported_cipher_suite_ids,
7 cipher_suite_privs,
8 ):
9- new_cipher_suite_privs = ""
10- for i, v in enumerate(cipher_suite_privs):
11- if i < len(supported_cipher_suite_ids):
12- cipher_suite_id = supported_cipher_suite_ids[i]
13- if cipher_suite_id in [17, 3, 8, 12]:
14- if cipher_suite_id == max_cipher_suite_id and v != "a":
15- print(
16- 'INFO: Enabling IPMI cipher suite id "%s" '
17- "for MAAS use..." % cipher_suite_id
18- )
19- new_cipher_suite_privs += "a"
20- else:
21- new_cipher_suite_privs += v
22- else:
23- if v != "X":
24- print(
25- "INFO: Disabling insecure IPMI cipher suite id "
26- '"%s"' % cipher_suite_id
27- )
28- new_cipher_suite_privs = "X"
29- else:
30- # 15 characters are usually given even if there
31- # aren't 15 ciphers supported. Copy the current value
32- # incase there is some OEM use for them.
33- new_cipher_suite_privs += v
34+ cipher_suite_privs_list = list(cipher_suite_privs)
35+ for i, cipher_suite_id in enumerate(supported_cipher_suite_ids):
36+ if cipher_suite_id > 17:
37+ # The IPMI spec reserves ciphers > 17 for vendor use.
38+ # Don't touch them
39+ continue
40+ elif cipher_suite_id == max_cipher_suite_id:
41+ if cipher_suite_privs_list[i] != "a":
42+ # Make sure the maximum supported cipher suite is enabled,
43+ # this is the cipher suite MAAS will use.
44+ cipher_suite_privs_list[i] = "a"
45+ print(
46+ 'INFO: Enabling IPMI cipher suite id "%s" '
47+ "for MAAS use..." % cipher_suite_id
48+ )
49+ elif cipher_suite_id not in [17, 3, 8, 12]:
50+ # Disable any cipher suite which isn't a known secure
51+ # cipher suite.
52+ if cipher_suite_privs_list[i] != "X":
53+ cipher_suite_privs_list[i] = "X"
54+ print(
55+ "INFO: Disabling insecure IPMI cipher suite id "
56+ '"%s"' % cipher_suite_id
57+ )
58
59+ new_cipher_suite_privs = "".join(cipher_suite_privs_list)
60 if cipher_suite_privs == new_cipher_suite_privs:
61 # Cipher suites are already properly configured, nothing
62 # to do.
63diff --git a/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_bmc_config.py b/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_bmc_config.py
64index 6065608..af571d1 100644
65--- a/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_bmc_config.py
66+++ b/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_bmc_config.py
67@@ -1,4 +1,4 @@
68-# Copyright 2020 Canonical Ltd. This software is licensed under the
69+# Copyright 2020-2021 Canonical Ltd. This software is licensed under the
70 # GNU Affero General Public License version 3 (see the file LICENSE).
71
72 """Test bmc_config functions."""
73@@ -796,6 +796,41 @@ EndSection
74 )
75 self.assertEqual("17", self.ipmi._cipher_suite_id)
76
77+ def test_config_ipmitool_cipher_suite_ids_with_gaps(self):
78+ mock_get_ipmitool_lan_print = self.patch(
79+ self.ipmi, "_get_ipmitool_lan_print"
80+ )
81+ mock_get_ipmitool_lan_print.return_value = (
82+ "2",
83+ factory.make_name("output"),
84+ )
85+
86+ # This tests a BMC which has IPMI ciphers 0, 4, 5, 9, 10, 13, and
87+ # 14. The BMC has options for all supported ciphers plus 4 vendor
88+ # ciphers which are not listed. ciphers 1, 2, 3 and two vendor
89+ # ciphers are currently enabled while the others are disabled.
90+ self.ipmi._config_ipmitool_cipher_suite_ids(
91+ 17, [1, 2, 3, 6, 7, 8, 11, 12, 15, 16, 17], "aaaXXXXXXXXXXaa"
92+ )
93+
94+ # This verifies MAAS would keep cipher 3 and the two vendor ciphers
95+ # as is while enabling cipher 17 for MAAS to use.
96+ self.assertThat(
97+ self.mock_check_call,
98+ MockCalledOnceWith(
99+ [
100+ "ipmitool",
101+ "lan",
102+ "set",
103+ "2",
104+ "cipher_privs",
105+ "XXaXXXXXXXaXXaa",
106+ ],
107+ timeout=60,
108+ ),
109+ )
110+ self.assertEqual("17", self.ipmi._cipher_suite_id)
111+
112 def test_config_ipmitool_cipher_suite_ids_does_nothing(self):
113 mock_get_ipmitool_lan_print = self.patch(
114 self.ipmi, "_get_ipmitool_lan_print"

Subscribers

People subscribed via source and target branches