Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ WHERE sp.`storage_provider_name` = 'NetApp ONTAP'
-- Rename persisted FlashArray provider name (plugin getName() changed from 'Flash Array' to 'FlashArray')
UPDATE `cloud`.`storage_pool` SET `storage_provider_name` = 'FlashArray' WHERE `storage_provider_name` = 'Flash Array';

-- Collect the FRR log and the frr.conf copy with masked passwords in router diagnostics
UPDATE `cloud`.`configuration` SET `value`=CONCAT(`value`, ',/var/log/frr/frr.log,/var/cache/cloud/frr.conf.masked')
WHERE `name`='diagnostics.data.router.defaults' AND `value` IS NOT NULL;

--- Recalculate the allocated size in bytes for each Object Storage provider
UPDATE `cloud`.`object_store`
JOIN (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface DiagnosticsFilesList {
"diagnostics.data.router.defaults", "Advanced", "iptables,ipaddr,iprule,iproute,/etc/cloudstack-release," +
"/etc/dnsmasq.conf,/etc/dhcphosts.txt,/etc/dhcpopts.txt,/etc/dnsmasq.d/cloud.conf,/etc/dnsmasq-resolv.conf,/var/lib/misc/dnsmasq.leases,/var/log/dnsmasq.log," +
"/etc/hosts,/etc/resolv.conf,/etc/haproxy/haproxy.cfg,/var/log/haproxy.log,/etc/ipsec.d/l2tp.conf,/var/log/cloud.log," +
"/var/log/routerServiceMonitor.log,/var/log/daemon.log",
"/var/log/routerServiceMonitor.log,/var/log/daemon.log,/var/log/frr/frr.log,/var/cache/cloud/frr.conf.masked",
"List of supported diagnostics data file options for the domain router.", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null);

List<String> generateFileList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.Objects;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@RunWith(MockitoJUnitRunner.class)
public class DiagnosticsFilesListFactoryTest {
Expand Down Expand Up @@ -79,4 +81,13 @@ public void testDiagnosticsFileListDefaultsRouter() {

assertEquals(filesList.size(), defaultFileArray.length);
}

@Test
public void testDiagnosticsFileListDefaultsRouterIncludeFrrFiles() {
List<String> filesList = Objects.requireNonNull(DiagnosticsFilesListFactory.getDiagnosticsFilesList(null, vmInstance)).generateFileList();

assertTrue(filesList.contains("/var/log/frr/frr.log"));
assertTrue(filesList.contains("/var/cache/cloud/frr.conf.masked"));
assertFalse(filesList.contains("/etc/frr/frr.conf"));
}
}
19 changes: 19 additions & 0 deletions systemvm/debian/opt/cloud/bin/cs/CsBgpPeers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
# under the License.

import logging
import re
from . import CsHelper
from .CsDatabag import CsDataBag
from .CsFile import CsFile

FRR_DIR = "/etc/frr/"
FRR_DAEMONS = "/etc/frr/daemons"
FRR_CONFIG = "/etc/frr/frr.conf"
# A copy of frr.conf without passwords, which getDiagnosticsData collects.
MASKED_COPY = "/var/cache/cloud/frr.conf.masked"


class CsBgpPeers(CsDataBag):
Expand Down Expand Up @@ -60,11 +63,25 @@ def process(self):
self._post_set()
if self.frr_conf.commit():
restart_frr = True
self._write_masked_copy()

if restart_frr:
CsHelper.execute("systemctl enable frr")
CsHelper.execute("systemctl restart frr")

def _write_masked_copy(self):
try:
with open(MASKED_COPY, "w") as f:
for line in self._mask_passwords([line.rstrip("\n") for line in self.frr_conf.new_config]):
f.write(line + "\n")
except IOError as e:
logging.error("Unable to write %s: %s" % (MASKED_COPY, e))

def _mask_passwords(self, lines):
# DOTALL masks a password that contains a line break, up to the end of the entry.
return [re.sub(r'^(\s*neighbor\s+\S+\s+password\s+)\S.*$', r'\g<1>****', line, flags=re.DOTALL)
for line in lines]

def _process_dbag_item(self, item):
as_number = item['network_as_number']
if as_number not in self.peers.keys():
Expand All @@ -80,6 +97,8 @@ def _pre_set(self):
self.frr_conf.add("frr defaults traditional")
self.frr_conf.add("hostname {}".format(CsHelper.get_hostname()))
self.frr_conf.add("service integrated-vtysh-config")
# FRR sends nothing to syslog without a log line. The frr package routes it to /var/log/frr/frr.log.
self.frr_conf.add("log syslog informational")
self.frr_conf.add("ip nht resolve-via-default")
self.frr_conf.add("ipv6 nht resolve-via-default")
return
Expand Down
33 changes: 33 additions & 0 deletions systemvm/test/TestCsBgpPeers.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,39 @@ def test_process_peers_password_and_multihop(self):
self.assertIn(" neighbor 100.64.0.1 password S3cr3t!", config)
self.assertIn(" neighbor 100.64.0.1 ebgp-multihop 2", config)

def test_mask_passwords(self):
lines = [" neighbor 100.64.0.1 remote-as 64496",
" neighbor 100.64.0.1 password S3cr3t!",
" neighbor 2001:db8::1 password two words",
" neighbor upstream password password"]
masked = self.csbgppeers._mask_passwords(lines)
self.assertEqual(masked, [" neighbor 100.64.0.1 remote-as 64496",
" neighbor 100.64.0.1 password ****",
" neighbor 2001:db8::1 password ****",
" neighbor upstream password ****"])

def test_mask_passwords_with_line_break(self):
masked = self.csbgppeers._mask_passwords([" neighbor 100.64.0.1 password abc\nfoo"])
self.assertEqual(masked, [" neighbor 100.64.0.1 password ****"])

@mock.patch('cs.CsBgpPeers.MASKED_COPY', "frr.conf.masked.test")
@mock.patch('cs.CsBgpPeers.CsHelper.get_hostname')
def test_write_masked_copy(self, mock_hostname):
mock_hostname.return_value = "r-1001-VM"
self.addCleanup(lambda: os.path.exists("frr.conf.masked.test") and os.remove("frr.conf.masked.test"))
self.csbgppeers._process_dbag_item(self._peer(ip4_address='100.64.0.1',
guest_ip4_cidr='192.0.2.0/24',
peer_password='S3cr3t!'))
self.csbgppeers._pre_set()
self.csbgppeers._process_peers()
self.csbgppeers._write_masked_copy()

with open("frr.conf.masked.test") as f:
masked = [line.rstrip('\n') for line in f]
self.assertNotIn("S3cr3t!", "\n".join(masked))
self.assertIn(" neighbor 100.64.0.1 password ****", masked)
self.assertEqual(len(masked), len(self.csbgppeers.frr_conf.new_config))

def test_route_map_set(self):
self.csbgppeers._route_map_set()

Expand Down
1 change: 1 addition & 0 deletions systemvm/test/frr-bgppeers-ipv4-ipv6.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
frr defaults traditional
hostname r-1001-VM
service integrated-vtysh-config
log syslog informational
ip nht resolve-via-default
ipv6 nht resolve-via-default
ip prefix-list all-v4 seq 1 permit any
Expand Down
75 changes: 75 additions & 0 deletions test/integration/smoke/test_ipv4_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

""" Test for IPv4 Routed mode"""
import datetime
import io
import logging
import random
import time
import urllib.request
import zipfile

from marvin.cloudstackAPI import getDiagnosticsData
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.base import ZoneIpv4Subnet, Domain, Account, ServiceOffering, NetworkOffering, VpcOffering, Network, \
Ipv4SubnetForGuestNetwork, VirtualMachine, VPC, NetworkACLList, NetworkACL, RoutingFirewallRule, Template, ASNRange, \
Expand Down Expand Up @@ -1671,3 +1675,74 @@ def test_13_asn_ranges(self):
self.apiclient
)
self.cleanup.remove(asnrange_2)

@attr(tags=['advanced'], required_hardware=True)
def test_14_diagnostics_frr_files(self):
""" Test for the FRR files in router diagnostics"""
"""
# 1. Create Isolated network with Dynamic routing and a BGP peer with a password
# 2. Create VM in the network
# 3. Get the router's diagnostics data with the default file list
# 4. Verify the zip holds frr.log and frr.conf.masked, and not frr.conf
# 5. Verify frr.conf.masked masks the password, and neither file holds it
"""
self.message("Running test_14_diagnostics_frr_files")

# 1. Create Isolated network with Dynamic routing and a BGP peer with a password
bgppeer_1 = BgpPeer.create(
self.apiclient,
zoneid=self.zone.id,
asnumber=ASN_1,
ipaddress=IP4_ADDR_1,
password=PASSWORD_1
)
self.cleanup.append(bgppeer_1)

test_network_dynamic = Network.create(
self.apiclient,
self.services["network"],
networkofferingid=self.network_offering_dynamic.id,
zoneid=self.zone.id,
domainid=self.sub_domain.id,
accountid=self.regular_user.name,
gateway=NETWORK_CIDR_PREFIX_DYNAMIC + ".1",
netmask="255.255.255.0",
bgppeerids=bgppeer_1.id
)
self.cleanup.append(test_network_dynamic)

# 2. Create VM in the network
test_network_dynamic_vm = VirtualMachine.create(
self.regular_user_apiclient,
self.services["virtual_machine"],
zoneid=self.zone.id,
domainid=self.sub_domain.id,
accountid=self.regular_user.name,
networkids=test_network_dynamic.id,
serviceofferingid=self.service_offering.id,
templateid=self.template.id)
self.cleanup.append(test_network_dynamic_vm)

network_router = self.get_router(networkid=test_network_dynamic.id)

# 3. Get the router's diagnostics data with the default file list
cmd = getDiagnosticsData.getDiagnosticsDataCmd()
cmd.targetid = network_router.id
response = self.apiclient.getDiagnosticsData(cmd)
data = urllib.request.urlopen(response.url).read()
files = zipfile.ZipFile(io.BytesIO(data))
names = files.namelist()
self.message("Diagnostics data files: %s" % names)

# 4. Verify the zip holds frr.log and frr.conf.masked, and not frr.conf
for name in ("frr.log", "frr.conf.masked"):
self.assertIn(name, names, "The diagnostics data should hold %s" % name)
self.assertNotIn("frr.conf", names, "The diagnostics data should not hold frr.conf")

# 5. Verify frr.conf.masked masks the password, and neither file holds it
masked = files.read("frr.conf.masked").decode()
self.assertIn("neighbor %s password ****" % IP4_ADDR_1, masked,
"frr.conf.masked should mask the password of %s" % IP4_ADDR_1)
for name in ("frr.log", "frr.conf.masked"):
self.assertNotIn(PASSWORD_1, files.read(name).decode(errors="replace"),
"%s should not hold the BGP peer password" % name)