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
13 changes: 12 additions & 1 deletion api/src/main/java/com/cloud/bgp/BGPService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@
import com.cloud.network.vpc.Vpc;
import com.cloud.utils.Pair;
import org.apache.cloudstack.api.command.user.bgp.ListASNumbersCmd;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.network.BgpPeer;

import java.util.List;

public interface BGPService {
public interface BGPService extends Configurable {

ConfigKey<Integer> MinHoldtime = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class,
"routed.bgp.min.holdtime",
"3",
"The lowest BGP hold time, in seconds, that a virtual router accepts. "
+ "It applies to every BGP peer on the router. "
+ "A session that negotiates a lower hold time, including 0, is refused.",
true,
ConfigKey.Scope.Account);

ASNumberRange createASNumberRange(long zoneId, long startASNumber, long endASNumber);
List<ASNumberRange> listASNumberRanges(Long zoneId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

public class SetBgpPeersCommand extends NetworkElementCommand {
BgpPeerTO[] bpgPeers;
Integer minHoldtime;

protected SetBgpPeersCommand() {
}
Expand All @@ -36,4 +37,12 @@ public SetBgpPeersCommand(List<BgpPeerTO> bpgPeers) {
public BgpPeerTO[] getBpgPeers() {
return bpgPeers;
}

public Integer getMinHoldtime() {
return minHoldtime;
}

public void setMinHoldtime(Integer minHoldtime) {
this.minHoldtime = minHoldtime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SetBgpPeersConfigItem extends AbstractConfigItemFacade {
@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
final SetBgpPeersCommand command = (SetBgpPeersCommand) cmd;
return generateConfigItems(new BgpPeers(Arrays.asList(command.getBpgPeers())));
return generateConfigItems(new BgpPeers(Arrays.asList(command.getBpgPeers()), command.getMinHoldtime()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

public class BgpPeers extends ConfigBase {
private List<BgpPeerTO> peers;
private Integer minHoldtime;

public BgpPeers() {
super(ConfigBase.BGP_PEERS);
Expand All @@ -35,11 +36,24 @@ public BgpPeers(List<BgpPeerTO> bgpPeers) {
this.peers = bgpPeers;
}

public BgpPeers(List<BgpPeerTO> bgpPeers, Integer minHoldtime) {
this(bgpPeers);
this.minHoldtime = minHoldtime;
}

public List<BgpPeerTO> getPeers() {
return peers;
}

public void setPeers(List<BgpPeerTO> bgpPeers) {
this.peers = bgpPeers;
}

public Integer getMinHoldtime() {
return minHoldtime;
}

public void setMinHoldtime(Integer minHoldtime) {
this.minHoldtime = minHoldtime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

package com.cloud.agent.resource.virtualnetwork.facade;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import org.apache.cloudstack.network.BgpPeerTO;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.cloud.agent.api.routing.SetBgpPeersCommand;
import com.cloud.agent.resource.virtualnetwork.ConfigItem;
import com.cloud.agent.resource.virtualnetwork.FileConfigItem;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

/**
* The BGP peers command carries the minimum hold time to the router. The push file
* holds it as min_holdtime beside the peers, so a router with BGP peers renders
* bgp minimum-holdtime.
*/
public class SetBgpPeersMinHoldtimeTest {

private SetBgpPeersCommand cmd;

@Before
public void setUp() {
BgpPeerTO peer = new BgpPeerTO(1L, "198.51.100.1", null, 65100L, null, 10L, 64600L,
"172.16.10.0/24", null, new HashMap<>());
cmd = new SetBgpPeersCommand(Collections.singletonList(peer));
}

private JsonObject pushFile() {
List<ConfigItem> items = new SetBgpPeersConfigItem().generateConfig(cmd);
for (ConfigItem item : items) {
if (item instanceof FileConfigItem) {
return JsonParser.parseString(((FileConfigItem) item).getFileContents()).getAsJsonObject();
}
}
throw new AssertionError("no push file in " + items);
}

@Test
public void commandCarriesMinHoldtime() {
cmd.setMinHoldtime(3);
Assert.assertEquals(Integer.valueOf(3), cmd.getMinHoldtime());
}

// The push file holds the default minimum hold time next to the peers.
@Test
public void pushFileCarriesMinHoldtime() {
cmd.setMinHoldtime(3);
JsonObject file = pushFile();
Assert.assertTrue("push file should hold min_holdtime: " + file, file.has("min_holdtime"));
Assert.assertEquals(3, file.get("min_holdtime").getAsInt());
Assert.assertEquals(1, file.getAsJsonArray("peers").size());
}

// A raised minimum hold time reaches the router as set.
@Test
public void pushFileCarriesRaisedMinHoldtime() {
cmd.setMinHoldtime(9);
Assert.assertEquals(9, pushFile().get("min_holdtime").getAsInt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,7 @@ CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.disk_offering', 'error_policy', 'VAR

-- 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 AND `value` NOT LIKE '%/var/log/frr/frr.log%';
11 changes: 11 additions & 0 deletions server/src/main/java/com/cloud/bgp/BGPServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.api.command.user.bgp.ListASNumbersCmd;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.network.BgpPeer;
import org.apache.cloudstack.network.BgpPeerVO;
import org.apache.cloudstack.network.RoutedIpv4Manager;
Expand Down Expand Up @@ -108,6 +109,16 @@ public class BGPServiceImpl implements BGPService {
public BGPServiceImpl() {
}

@Override
public String getConfigComponentName() {
return BGPService.class.getSimpleName();
}

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {MinHoldtime};
}

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_AS_RANGE_CREATE, eventDescription = "AS Range creation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.dao.NetworkOfferingJoinDao;
import com.cloud.api.query.vo.NetworkOfferingJoinVO;
import com.cloud.bgp.BGPService;
import com.cloud.capacity.CapacityManager;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.cluster.ManagementServerHostVO;
Expand Down Expand Up @@ -1531,6 +1532,9 @@ protected String validateValueRange(String name, String value, Class<?> type, Co
return String.format("[%s] value should be between 0 and 255. 0 value will disable this feature.", name);
}
}
if (BGPService.MinHoldtime.key().equalsIgnoreCase(name) && (val < 0 || val > 65535)) {
return String.format("[%s] value should be between 0 and 65535. 0 turns off the minimum.", name);
}
if (UnmanagedVMsManager.ThreadsOnMSToImportVMwareVMFiles.key().equalsIgnoreCase(name) ||
UnmanagedVMsManager.ThreadsOnKVMHostToImportVMwareVMFiles.key().equalsIgnoreCase(name)) {
if (val < -1 || val > 10) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import com.cloud.agent.api.to.PortForwardingRuleTO;
import com.cloud.agent.api.to.StaticNatRuleTO;
import com.cloud.agent.manager.Commands;
import com.cloud.bgp.BGPService;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.ASNumberVO;
Expand Down Expand Up @@ -1630,6 +1631,7 @@ public void createBgpPeersCommands(final List<? extends BgpPeer> bgpPeers, final
}

final SetBgpPeersCommand cmd = new SetBgpPeersCommand(bgpPeerTOs);
cmd.setMinHoldtime(BGPService.MinHoldtime.valueIn(router.getAccountId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frr.conf contains some sensitive info, not sure if good to add here by default

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only a masked copy, /var/cache/cloud/frr.conf.masked.
CsBgpPeers writes it each time it renders frr.conf, using the new CsFrrConfig.mask_passwords, which replaces every peer password with ; the plain frr.conf never leaves the router.
What's left is peer IPs, ASNs and route-maps, which admins can already see, and getDiagnosticsData is root-admin only.

Note however, while checking this I found that CsBgpPeers already logs the whole bgppeers databag to cloud.log, passwords included, and cloud.log is in the default bundle. Would you like me to raise an issue on this against 4.20?

"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
12 changes: 12 additions & 0 deletions server/src/test/java/com/cloud/bgp/BGPServiceImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.cloud.network.vpc.dao.VpcServiceMapDao;
import com.cloud.user.AccountVO;
import com.cloud.user.dao.AccountDao;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.network.BgpPeerVO;
import org.apache.cloudstack.network.RoutedIpv4Manager;
import org.apache.cloudstack.network.dao.BgpPeerDao;
Expand All @@ -43,6 +44,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -173,4 +175,14 @@ public void testApplyBgpPeersForVpcWithBgpPeers() throws ResourceUnavailableExce

verify(vpcVirtualRouterElement).applyBgpPeers(eq(vpc), eq(null), any());
}

// The minimum hold time is a dynamic account setting registered by this service.
@Test
public void minHoldtimeIsDynamicAccountSettingDefaulting3() {
Assert.assertEquals("routed.bgp.min.holdtime", BGPService.MinHoldtime.key());
Assert.assertEquals("3", BGPService.MinHoldtime.defaultValue());
Assert.assertTrue(BGPService.MinHoldtime.isDynamic());
Assert.assertEquals(Collections.singletonList(ConfigKey.Scope.Account), BGPService.MinHoldtime.getScopes());
Assert.assertTrue(Arrays.asList(bGPServiceImplSpy.getConfigKeys()).contains(BGPService.MinHoldtime));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.cloud.configuration;

import com.cloud.alert.AlertManager;
import com.cloud.bgp.BGPService;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.VlanVO;
Expand Down Expand Up @@ -861,6 +862,20 @@ public void validateValueRangeTestReturnsNotNullWhenConfigKeyHasRangeAndValueIsI
Assert.assertNotNull(configurationManagerImplSpy.validateValueRange(NetworkModel.MACIdentifier.key(), "-1", Integer.class, null));
}

@Test
public void validateValueRangeTestAcceptsBgpMinHoldtimeWithinRange() {
for (String value : new String[] {"0", "3", "65535"}) {
Assert.assertNull(configurationManagerImplSpy.validateValueRange(BGPService.MinHoldtime.key(), value, Integer.class, null));
}
}

@Test
public void validateValueRangeTestRejectsBgpMinHoldtimeOutsideRange() {
for (String value : new String[] {"-1", "65536"}) {
Assert.assertNotNull(configurationManagerImplSpy.validateValueRange(BGPService.MinHoldtime.key(), value, Integer.class, null));
}
}

@Test
public void validateValueRangeTestValidatesValueWhenConfigHasRange() {
Config config = Config.SecStorageEncryptCopy;
Expand Down
Loading