Skip to content

Commit 61e74e0

Browse files
author
Daan Hoogland
committed
Merge branch '4.19' into 4.20
2 parents 49c6fbd + 7715b3d commit 61e74e0

File tree

9 files changed

+210
-128
lines changed

9 files changed

+210
-128
lines changed

.github/workflows/ui.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
npm run test:unit
5757
5858
- uses: codecov/codecov-action@v4
59+
if: github.repository == 'apache/cloudstack'
5960
with:
6061
working-directory: ui
6162
files: ./coverage/lcov.info

core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939

4040
import javax.net.ssl.HttpsURLConnection;
4141
import javax.net.ssl.SSLContext;
42-
import javax.net.ssl.TrustManager;
4342

44-
import org.apache.cloudstack.utils.security.SSLUtils;
4543
import org.apache.commons.collections.MapUtils;
4644
import org.apache.commons.httpclient.HttpStatus;
4745
import org.apache.commons.io.IOUtils;
@@ -55,6 +53,7 @@
5553
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
5654
import org.apache.http.impl.client.CloseableHttpClient;
5755
import org.apache.http.impl.client.HttpClients;
56+
import org.apache.http.ssl.SSLContexts;
5857
import org.apache.http.util.EntityUtils;
5958

6059
import com.cloud.utils.Pair;
@@ -120,10 +119,10 @@ private SSLContext getSSLContext() {
120119
String password = "changeit";
121120
defaultKeystore.load(is, password.toCharArray());
122121
}
123-
TrustManager[] tm = HttpsMultiTrustManager.getTrustManagersFromKeyStores(customKeystore, defaultKeystore);
124-
SSLContext sslContext = SSLUtils.getSSLContext();
125-
sslContext.init(null, tm, null);
126-
return sslContext;
122+
return SSLContexts.custom()
123+
.loadTrustMaterial(customKeystore, null)
124+
.loadTrustMaterial(defaultKeystore, null)
125+
.build();
127126
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | KeyManagementException e) {
128127
logger.error(String.format("Failure getting SSL context for HTTPS downloader, using default SSL context: %s", e.getMessage()), e);
129128
try {

core/src/main/java/org/apache/cloudstack/direct/download/HttpsMultiTrustManager.java

Lines changed: 0 additions & 102 deletions
This file was deleted.

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupDirectDownloadCertificateCommandWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private String getKeyStoreFilePath(File agentFile) {
8484
private void importCertificate(String tempCerFilePath, String keyStoreFile, String certificateName, String privatePassword) {
8585
logger.debug("Importing certificate from temporary file to keystore");
8686
String keyToolPath = Script.getExecutableAbsolutePath("keytool");
87-
int result = Script.executeCommandForExitValue(keyToolPath, "-importcert", "file", tempCerFilePath,
87+
int result = Script.executeCommandForExitValue(keyToolPath, "-importcert", "-file", tempCerFilePath,
8888
"-keystore", keyStoreFile, "-alias", sanitizeBashCommandArgument(certificateName), "-storepass",
8989
privatePassword, "-noprompt");
9090
if (result != 0) {

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterResourceModifierActionWorker.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu
159159

160160
protected String kubernetesClusterNodeNamePrefix;
161161

162+
private static final int MAX_CLUSTER_PREFIX_LENGTH = 43;
163+
162164
protected KubernetesClusterResourceModifierActionWorker(final KubernetesCluster kubernetesCluster, final KubernetesClusterManagerImpl clusterManager) {
163165
super(kubernetesCluster, clusterManager);
164166
}
@@ -775,19 +777,35 @@ protected void setupKubernetesClusterVpcTierRules(IpAddress publicIp, Network ne
775777
}
776778
}
777779

780+
/**
781+
* Generates a valid name prefix for Kubernetes cluster nodes.
782+
*
783+
* <p>The prefix must comply with Kubernetes naming constraints:
784+
* <ul>
785+
* <li>Maximum 63 characters total</li>
786+
* <li>Only lowercase alphanumeric characters and hyphens</li>
787+
* <li>Must start with a letter</li>
788+
* <li>Must end with an alphanumeric character</li>
789+
* </ul>
790+
*
791+
* <p>The generated prefix is limited to 43 characters to accommodate the full node naming pattern:
792+
* <pre>{'prefix'}-{'control' | 'node'}-{'11-digit-hash'}</pre>
793+
*
794+
* @return A valid node name prefix, truncated if necessary
795+
* @see <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/names/">Kubernetes "Object Names and IDs" documentation</a>
796+
*/
778797
protected String getKubernetesClusterNodeNamePrefix() {
779-
String prefix = kubernetesCluster.getName();
780-
if (!NetUtils.verifyDomainNameLabel(prefix, true)) {
781-
prefix = prefix.replaceAll("[^a-zA-Z0-9-]", "");
782-
if (prefix.length() == 0) {
783-
prefix = kubernetesCluster.getUuid();
784-
}
785-
prefix = "k8s-" + prefix;
798+
String prefix = kubernetesCluster.getName().toLowerCase();
799+
800+
if (NetUtils.verifyDomainNameLabel(prefix, true)) {
801+
return StringUtils.truncate(prefix, MAX_CLUSTER_PREFIX_LENGTH);
786802
}
787-
if (prefix.length() > 40) {
788-
prefix = prefix.substring(0, 40);
803+
804+
prefix = prefix.replaceAll("[^a-z0-9-]", "");
805+
if (prefix.isEmpty()) {
806+
prefix = kubernetesCluster.getUuid();
789807
}
790-
return prefix;
808+
return StringUtils.truncate("k8s-" + prefix, MAX_CLUSTER_PREFIX_LENGTH);
791809
}
792810

793811
protected KubernetesClusterVO updateKubernetesClusterEntry(final Long cores, final Long memory, final Long size,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package com.cloud.kubernetes.cluster.actionworkers;
19+
20+
import com.cloud.kubernetes.cluster.KubernetesCluster;
21+
import com.cloud.kubernetes.cluster.KubernetesClusterManagerImpl;
22+
import com.cloud.kubernetes.cluster.dao.KubernetesClusterDao;
23+
import com.cloud.kubernetes.cluster.dao.KubernetesClusterDetailsDao;
24+
import com.cloud.kubernetes.cluster.dao.KubernetesClusterVmMapDao;
25+
import com.cloud.kubernetes.version.dao.KubernetesSupportedVersionDao;
26+
import org.junit.Assert;
27+
import org.junit.Before;
28+
import org.junit.Test;
29+
import org.junit.runner.RunWith;
30+
import org.mockito.Mock;
31+
import org.mockito.Mockito;
32+
import org.mockito.junit.MockitoJUnitRunner;
33+
34+
@RunWith(MockitoJUnitRunner.class)
35+
public class KubernetesClusterResourceModifierActionWorkerTest {
36+
@Mock
37+
private KubernetesClusterDao kubernetesClusterDaoMock;
38+
39+
@Mock
40+
private KubernetesClusterDetailsDao kubernetesClusterDetailsDaoMock;
41+
42+
@Mock
43+
private KubernetesClusterVmMapDao kubernetesClusterVmMapDaoMock;
44+
45+
@Mock
46+
private KubernetesSupportedVersionDao kubernetesSupportedVersionDaoMock;
47+
48+
@Mock
49+
private KubernetesClusterManagerImpl kubernetesClusterManagerMock;
50+
51+
@Mock
52+
private KubernetesCluster kubernetesClusterMock;
53+
54+
private KubernetesClusterResourceModifierActionWorker kubernetesClusterResourceModifierActionWorker;
55+
56+
@Before
57+
public void setUp() {
58+
kubernetesClusterManagerMock.kubernetesClusterDao = kubernetesClusterDaoMock;
59+
kubernetesClusterManagerMock.kubernetesSupportedVersionDao = kubernetesSupportedVersionDaoMock;
60+
kubernetesClusterManagerMock.kubernetesClusterDetailsDao = kubernetesClusterDetailsDaoMock;
61+
kubernetesClusterManagerMock.kubernetesClusterVmMapDao = kubernetesClusterVmMapDaoMock;
62+
63+
kubernetesClusterResourceModifierActionWorker = new KubernetesClusterResourceModifierActionWorker(kubernetesClusterMock, kubernetesClusterManagerMock);
64+
}
65+
66+
@Test
67+
public void getKubernetesClusterNodeNamePrefixTestReturnOriginalPrefixWhenNamingAllRequirementsAreMet() {
68+
String originalPrefix = "k8s-cluster-01";
69+
String expectedPrefix = "k8s-cluster-01";
70+
71+
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
72+
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
73+
}
74+
75+
@Test
76+
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldOnlyContainLowerCaseCharacters() {
77+
String originalPrefix = "k8s-CLUSTER-01";
78+
String expectedPrefix = "k8s-cluster-01";
79+
80+
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
81+
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
82+
}
83+
84+
@Test
85+
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldBeTruncatedWhenRequired() {
86+
int maxPrefixLength = 43;
87+
88+
String originalPrefix = "c".repeat(maxPrefixLength + 1);
89+
String expectedPrefix = "c".repeat(maxPrefixLength);
90+
91+
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
92+
String normalizedPrefix = kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix();
93+
Assert.assertEquals(expectedPrefix, normalizedPrefix);
94+
Assert.assertEquals(maxPrefixLength, normalizedPrefix.length());
95+
}
96+
97+
@Test
98+
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldBeTruncatedWhenRequiredAndWhenOriginalPrefixIsInvalid() {
99+
int maxPrefixLength = 43;
100+
101+
String originalPrefix = "1!" + "c".repeat(maxPrefixLength);
102+
String expectedPrefix = "k8s-1" + "c".repeat(maxPrefixLength - 5);
103+
104+
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
105+
String normalizedPrefix = kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix();
106+
Assert.assertEquals(expectedPrefix, normalizedPrefix);
107+
Assert.assertEquals(maxPrefixLength, normalizedPrefix.length());
108+
}
109+
110+
@Test
111+
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldOnlyIncludeAlphanumericCharactersAndHyphen() {
112+
String originalPrefix = "Cluster!@#$%^&*()_+?.-01|<>";
113+
String expectedPrefix = "k8s-cluster-01";
114+
115+
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
116+
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
117+
}
118+
119+
@Test
120+
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldContainClusterUuidWhenAllCharactersAreInvalid() {
121+
String clusterUuid = "2699b547-cb56-4a59-a2c6-331cfb21d2e4";
122+
String originalPrefix = "!@#$%^&*()_+?.|<>";
123+
String expectedPrefix = "k8s-" + clusterUuid;
124+
125+
Mockito.when(kubernetesClusterMock.getUuid()).thenReturn(clusterUuid);
126+
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
127+
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
128+
}
129+
130+
@Test
131+
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldNotStartWithADigit() {
132+
String originalPrefix = "1 cluster";
133+
String expectedPrefix = "k8s-1cluster";
134+
135+
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
136+
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
137+
}
138+
}

server/src/main/java/com/cloud/template/TemplateAdapterBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ public TemplateProfile prepare(boolean isIso, long userId, String name, String d
194194

195195
if (!isAdmin && zoneIdList == null && !isRegionStore ) {
196196
// domain admin and user should also be able to register template on a region store
197-
throw new InvalidParameterValueException("Please specify a valid zone Id. Only admins can create templates in all zones.");
197+
throw new InvalidParameterValueException("Template registered for 'All zones' can only be owned a Root Admin account. " +
198+
"Please select specific zone(s).");
198199
}
199200

200201
// check for the url format only when url is not null. url can be null incase of form based upload

utils/src/main/java/com/cloud/utils/net/NetUtils.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,13 +1058,23 @@ public static String portRangeToString(final int portRange[]) {
10581058
return Integer.toString(portRange[0]) + ":" + Integer.toString(portRange[1]);
10591059
}
10601060

1061+
/**
1062+
* Validates a domain name.
1063+
*
1064+
* <p>Domain names must satisfy the following constraints:
1065+
* <ul>
1066+
* <li>Length between 1 and 63 characters</li>
1067+
* <li>Contain only ASCII letters 'a' through 'z' (case-insensitive)</li>
1068+
* <li>Can include digits '0' through '9' and hyphens (-)</li>
1069+
* <li>Must not start or end with a hyphen</li>
1070+
* <li>If used as hostname, must not start with a digit</li>
1071+
* </ul>
1072+
*
1073+
* @param hostName The domain name to validate
1074+
* @param isHostName If true, verifies whether the domain name starts with a digit
1075+
* @return true if the domain name is valid, false otherwise
1076+
*/
10611077
public static boolean verifyDomainNameLabel(final String hostName, final boolean isHostName) {
1062-
// must be between 1 and 63 characters long and may contain only the ASCII letters 'a' through 'z' (in a
1063-
// case-insensitive manner),
1064-
// the digits '0' through '9', and the hyphen ('-').
1065-
// Can not start with a hyphen and digit, and must not end with a hyphen
1066-
// If it's a host name, don't allow to start with digit
1067-
10681078
if (hostName.length() > 63 || hostName.length() < 1) {
10691079
LOGGER.warn("Domain name label must be between 1 and 63 characters long");
10701080
return false;

0 commit comments

Comments
 (0)