Skip to content

Commit b46e29d

Browse files
Improvement: SSL offloading with Virtual Router (#11468)
* SSL offloading with Virtual Router * PR11468: fix pre-commit errors * PR11468: api->getAPI/postAPI in UI * SSL: add smoke tests for VPC in user project * PR11468: address Daan's comments * Fix test/integration/smoke/test_ssl_offloading.py * SSL: remove ssl certificates when clean up account * SSL offloading: add unit tests * SSL offloading: UI fixes part 1 * SSL offloading: UI changes part 2 * SSL offloading: add more unit tests * SSL offloading: more unit tests 3 * SSL offloading: wrong check * SSL offloading: more and more unit tests * SSL offloading: add testUpdateLoadBalancerRule5
1 parent 8089d32 commit b46e29d

File tree

38 files changed

+2081
-101
lines changed

38 files changed

+2081
-101
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ repos:
4848
exclude: >
4949
(?x)
5050
^scripts/vm/systemvm/id_rsa\.cloud$|
51+
^server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java$|
5152
^server/src/test/java/com/cloud/keystore/KeystoreTest\.java$|
5253
^server/src/test/resources/certs/dsa_self_signed\.key$|
5354
^server/src/test/resources/certs/non_root\.key$|
@@ -57,7 +58,8 @@ repos:
5758
^server/src/test/resources/certs/rsa_self_signed\.key$|
5859
^services/console-proxy/rdpconsole/src/test/doc/rdp-key\.pem$|
5960
^systemvm/agent/certs/localhost\.key$|
60-
^systemvm/agent/certs/realhostip\.key$
61+
^systemvm/agent/certs/realhostip\.key$|
62+
^test/integration/smoke/test_ssl_offloading.py$
6163
- id: end-of-file-fixer
6264
exclude: \.vhd$
6365
- id: fix-byte-order-marker
@@ -75,7 +77,7 @@ repos:
7577
name: run codespell
7678
description: Check spelling with codespell
7779
args: [--ignore-words=.github/linters/codespell.txt]
78-
exclude: ^systemvm/agent/noVNC/|^ui/package\.json$|^ui/package-lock\.json$|^ui/public/js/less\.min\.js$|^ui/public/locales/.*[^n].*\.json$
80+
exclude: ^systemvm/agent/noVNC/|^ui/package\.json$|^ui/package-lock\.json$|^ui/public/js/less\.min\.js$|^ui/public/locales/.*[^n].*\.json$|^server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java$|^test/integration/smoke/test_ssl_offloading.py$
7981
- repo: https://github.com/pycqa/flake8
8082
rev: 7.0.0
8183
hooks:

api/src/main/java/com/cloud/agent/api/to/LoadBalancerTO.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, S
7171
this.destinations = new DestinationTO[destinations.size()];
7272
this.stickinessPolicies = null;
7373
this.sslCert = null;
74-
this.lbProtocol = null;
74+
this.lbProtocol = protocol;
7575
int i = 0;
7676
for (LbDestination destination : destinations) {
7777
this.destinations[i++] = new DestinationTO(destination.getIpAddress(), destination.getDestinationPortStart(), destination.isRevoked(), false);
@@ -205,6 +205,10 @@ public LbSslCert getSslCert() {
205205
return this.sslCert;
206206
}
207207

208+
public void setLbSslCert(LbSslCert sslCert) {
209+
this.sslCert = sslCert;
210+
}
211+
208212
public String getSrcIpVlan() {
209213
return srcIpVlan;
210214
}

api/src/main/java/com/cloud/network/lb/LoadBalancingRulesService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ LoadBalancer createPublicLoadBalancerRule(String xId, String name, String descri
106106

107107
boolean applyLoadBalancerConfig(long lbRuleId) throws ResourceUnavailableException;
108108

109-
boolean assignCertToLoadBalancer(long lbRuleId, Long certId);
109+
boolean assignCertToLoadBalancer(long lbRuleId, Long certId, boolean isForced);
110110

111111
boolean removeCertFromLoadBalancer(long lbRuleId);
112112

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignCertToLoadBalancerCmd.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.response.FirewallRuleResponse;
2828
import org.apache.cloudstack.api.response.SslCertResponse;
2929
import org.apache.cloudstack.api.response.SuccessResponse;
30+
import org.apache.commons.lang3.BooleanUtils;
3031

3132
import com.cloud.event.EventTypes;
3233
import com.cloud.exception.ConcurrentOperationException;
@@ -57,11 +58,17 @@ public class AssignCertToLoadBalancerCmd extends BaseAsyncCmd {
5758
description = "the ID of the certificate")
5859
Long certId;
5960

61+
@Parameter(name = ApiConstants.FORCED,
62+
type = CommandType.BOOLEAN,
63+
since = "4.22",
64+
description = "Force assign the certificate. If there is a certificate assigned to the LB, it will be removed at first.")
65+
private Boolean forced;
66+
6067
@Override
6168
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
6269
ResourceAllocationException, NetworkRuleConflictException {
6370
//To change body of implemented methods use File | Settings | File Templates.
64-
if (_lbService.assignCertToLoadBalancer(getLbRuleId(), getCertId())) {
71+
if (_lbService.assignCertToLoadBalancer(getLbRuleId(), getCertId(), isForced())) {
6572
SuccessResponse response = new SuccessResponse(getCommandName());
6673
this.setResponseObject(response);
6774
} else {
@@ -95,4 +102,19 @@ public Long getCertId() {
95102
public Long getLbRuleId() {
96103
return lbRuleId;
97104
}
105+
106+
public boolean isForced() {
107+
return BooleanUtils.toBoolean(forced);
108+
}
109+
110+
@Override
111+
public String getSyncObjType() {
112+
return BaseAsyncCmd.networkSyncObject;
113+
}
114+
115+
@Override
116+
public Long getSyncObjId() {
117+
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getLbRuleId());
118+
return (lb != null)? lb.getNetworkId(): null;
119+
}
98120
}

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.cloudstack.api.response.NetworkResponse;
3434
import org.apache.cloudstack.api.response.ZoneResponse;
3535
import org.apache.cloudstack.context.CallContext;
36+
import org.apache.commons.lang3.StringUtils;
3637

3738
import com.cloud.dc.DataCenter;
3839
import com.cloud.dc.DataCenter.NetworkType;
@@ -112,7 +113,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements L
112113
+ "rule will be created for. Required when public Ip address is not associated with any Guest network yet (VPC case)")
113114
private Long networkId;
114115

115-
@Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, description = "The protocol for the LB such as tcp, udp or tcp-proxy.")
116+
@Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, description = "The protocol for the LB such as tcp, udp, tcp-proxy or ssl.")
116117
private String lbProtocol;
117118

118119
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
@@ -253,7 +254,7 @@ public List<String> getSourceCidrList() {
253254
}
254255

255256
public String getLbProtocol() {
256-
return lbProtocol;
257+
return StringUtils.trim(StringUtils.lowerCase(lbProtocol));
257258
}
258259

259260
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveCertFromLoadBalancerCmd.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,15 @@ public long getEntityOwnerId() {
8282
public Long getLbRuleId() {
8383
return this.lbRuleId;
8484
}
85+
86+
@Override
87+
public String getSyncObjType() {
88+
return BaseAsyncCmd.networkSyncObject;
89+
}
90+
91+
@Override
92+
public Long getSyncObjId() {
93+
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getLbRuleId());
94+
return (lb != null)? lb.getNetworkId(): null;
95+
}
8596
}

core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/LoadBalancerConfigItem.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
5656
final String[] statRules = allRules[LoadBalancerConfigurator.STATS];
5757

5858
final LoadBalancerRule loadBalancerRule = new LoadBalancerRule(configuration, tmpCfgFilePath, tmpCfgFileName, addRules, removeRules, statRules, routerIp);
59+
final LoadBalancerRule.SslCertEntry[] sslCerts = cfgtr.generateSslCertEntries(command);
60+
loadBalancerRule.setSslCerts(sslCerts);
5961

6062
final List<LoadBalancerRule> rules = new LinkedList<LoadBalancerRule>();
6163
rules.add(loadBalancerRule);

core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/LoadBalancerRule.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,61 @@ public class LoadBalancerRule {
2525
private String[] configuration;
2626
private String tmpCfgFilePath;
2727
private String tmpCfgFileName;
28+
private SslCertEntry[] sslCerts;
2829

2930
private String[] addRules;
3031
private String[] removeRules;
3132
private String[] statRules;
3233

3334
private String routerIp;
3435

36+
public static class SslCertEntry {
37+
private String name;
38+
private String cert;
39+
private String key;
40+
private String chain;
41+
private String password;
42+
43+
public SslCertEntry(String name, String cert, String key, String chain, String password) {
44+
this.name = name;
45+
this.cert = cert;
46+
this.key = key;
47+
this.chain = chain;
48+
this.password = password;
49+
}
50+
51+
public void setName(String name) {
52+
this.name = name;
53+
}
54+
public String getName() {
55+
return name;
56+
}
57+
public void setCert(String cert) {
58+
this.cert = cert;
59+
}
60+
public String getCert() {
61+
return cert;
62+
}
63+
public void setKey(String key) {
64+
this.key = key;
65+
}
66+
public String getKey() {
67+
return key;
68+
}
69+
public void setChain(String chain) {
70+
this.chain = chain;
71+
}
72+
public String getChain() {
73+
return chain;
74+
}
75+
public void setPassword(String password) {
76+
this.password = password;
77+
}
78+
public String getPassword() {
79+
return password;
80+
}
81+
}
82+
3583
public LoadBalancerRule() {
3684
// Empty constructor for (de)serialization
3785
}
@@ -101,4 +149,12 @@ public String getRouterIp() {
101149
public void setRouterIp(final String routerIp) {
102150
this.routerIp = routerIp;
103151
}
152+
153+
public SslCertEntry[] getSslCerts() {
154+
return sslCerts;
155+
}
156+
157+
public void setSslCerts(final SslCertEntry[] sslCerts) {
158+
this.sslCerts = sslCerts;
159+
}
104160
}

0 commit comments

Comments
 (0)