Skip to content

Commit

Permalink
Merge remote-tracking branch 'apache/main' into 4.20-routed-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhouapache committed Jul 8, 2024
2 parents 40c12bf + b69cc02 commit 720f57e
Show file tree
Hide file tree
Showing 52 changed files with 1,472 additions and 352 deletions.
3 changes: 2 additions & 1 deletion .github/linters/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# E242 Tab after ','
# E273 Tab after keyword
# E274 Tab before keyword
# E713 Test for membership should be 'not in'
# E742 Do not define classes named 'I', 'O', or 'l'
# E743 Do not define functions named 'I', 'O', or 'l'
# E901 SyntaxError or IndentationError
Expand All @@ -37,4 +38,4 @@
exclude =
.git,
venv
select = E112,E113,E133,E223,E224,E227,E242,E273,E274,E742,E743,E901,E902,W291,W292,W293,W391
select = E112,E113,E133,E223,E224,E227,E242,E273,E274,E713,E742,E743,E901,E902,W291,W292,W293,W391
8 changes: 8 additions & 0 deletions api/src/main/java/org/apache/cloudstack/ca/CAManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public interface CAManager extends CAService, Configurable, PluggableService {
"15",
"The number of days before expiry of a client certificate, the validations are checked. Admins are alerted when auto-renewal is not allowed, otherwise auto-renewal is attempted.", true, ConfigKey.Scope.Cluster);


ConfigKey<String> CertManagementCustomSubjectAlternativeName = new ConfigKey<>("Advanced", String.class,
"ca.framework.cert.management.custom.san",
"cloudstack.internal",
"The custom Subject Alternative Name that will be added to the management server certificate. " +
"The actual implementation will depend on the configured CA provider.",
false);

/**
* Returns a list of available CA provider plugins
* @return returns list of CAProvider
Expand Down
29 changes: 27 additions & 2 deletions core/src/main/java/com/cloud/resource/CommandWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

package com.cloud.resource;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;

public abstract class CommandWrapper<T extends Command, A extends Answer, R extends ServerResource> {
protected Logger logger = LogManager.getLogger(getClass());
Expand All @@ -33,4 +36,26 @@ public abstract class CommandWrapper<T extends Command, A extends Answer, R exte
* @return A and the Answer from the command.
*/
public abstract A execute(T command, R serverResource);

protected String sanitizeBashCommandArgument(String input) {
StringBuilder sanitized = new StringBuilder();
for (char c : input.toCharArray()) {
if ("\\\"'`$|&;()<>*?![]{}~".indexOf(c) != -1) {
sanitized.append('\\');
}
sanitized.append(c);
}
return sanitized.toString();
}

public void removeDpdkPort(String portToRemove) {
logger.debug("Removing DPDK port: " + portToRemove);
int port;
try {
port = Integer.valueOf(portToRemove);
} catch (NumberFormatException nfe) {
throw new CloudRuntimeException(String.format("Invalid DPDK port specified: '%s'", portToRemove));
}
Script.executeCommand("ovs-vsctl", "del-port", String.valueOf(port));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Map;
Expand All @@ -45,6 +46,7 @@ public interface CAProvider {

/**
* Issues certificate with provided options
*
* @param domainNames
* @param ipAddresses
* @param validityDays
Expand Down Expand Up @@ -104,4 +106,6 @@ public interface CAProvider {
* @return returns description
*/
String getDescription();

boolean isManagementCertificate(java.security.cert.Certificate certificate) throws CertificateParsingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.cert.CertificateParsingException;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
Expand All @@ -47,4 +48,6 @@ public interface CAService {
* @return returns char[] passphrase
*/
char[] getKeyStorePassphrase();

boolean isManagementCertificate(java.security.cert.Certificate certificate) throws CertificateParsingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// under the License.
package com.cloud.cluster;

import org.apache.cloudstack.management.ManagementServerHost;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.management.ManagementServerHost;

import com.cloud.utils.component.Manager;

Expand Down Expand Up @@ -77,6 +77,8 @@ public interface ClusterManager extends Manager {
*/
String getSelfPeerName();

String getSelfNodeIP();

long getManagementNodeId();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
import javax.inject.Inject;
import javax.naming.ConfigurationException;

import com.cloud.cluster.dao.ManagementServerStatusDao;
import org.apache.cloudstack.management.ManagementServerHost;
import org.apache.cloudstack.framework.config.ConfigDepot;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import org.apache.cloudstack.management.ManagementServerHost;
import org.apache.cloudstack.utils.identity.ManagementServerNode;

import com.cloud.cluster.dao.ManagementServerHostDao;
import com.cloud.cluster.dao.ManagementServerHostPeerDao;
import com.cloud.cluster.dao.ManagementServerStatusDao;
import com.cloud.utils.DateUtil;
import com.cloud.utils.Profiler;
import com.cloud.utils.component.ComponentLifecycle;
Expand Down Expand Up @@ -128,7 +128,7 @@ public ClusterManagerImpl() {
// recursive remote calls between nodes
//
_executor = Executors.newCachedThreadPool(new NamedThreadFactory("Cluster-Worker"));
setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK);
setRunLevel(ComponentLifecycle.RUN_LEVEL_COMPONENT);
}

private void registerRequestPdu(final ClusterServiceRequestPdu pdu) {
Expand Down Expand Up @@ -473,6 +473,7 @@ public String getSelfPeerName() {
return Long.toString(_msId);
}

@Override
public String getSelfNodeIP() {
return _clusterNodeIP;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@ public interface ClusterServiceAdapter extends Adapter {

public ClusterService getPeerService(String strPeer) throws RemoteException;

public String getServiceEndpointName(String strPeer);

public int getServicePort();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.inject.Inject;
import javax.naming.ConfigurationException;

import org.apache.cloudstack.ca.CAManager;
import org.apache.cloudstack.framework.config.ConfigDepot;

import com.cloud.cluster.dao.ManagementServerHostDao;
Expand All @@ -42,14 +43,16 @@ public class ClusterServiceServletAdapter extends AdapterBase implements Cluster
@Inject
private ManagementServerHostDao _mshostDao;
@Inject
private CAManager caService;
@Inject
protected ConfigDepot _configDepot;

private ClusterServiceServletContainer _servletContainer;

private int _clusterServicePort = DEFAULT_SERVICE_PORT;

public ClusterServiceServletAdapter() {
setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK);
setRunLevel(ComponentLifecycle.RUN_LEVEL_COMPONENT);
}

@Override
Expand All @@ -64,12 +67,10 @@ public ClusterService getPeerService(String strPeer) throws RemoteException {
String serviceUrl = getServiceEndpointName(strPeer);
if (serviceUrl == null)
return null;

return new ClusterServiceServletImpl(serviceUrl);
return new ClusterServiceServletImpl(serviceUrl, caService);
}

@Override
public String getServiceEndpointName(String strPeer) {
protected String getServiceEndpointName(String strPeer) {
try {
init();
} catch (ConfigurationException e) {
Expand All @@ -93,7 +94,7 @@ public int getServicePort() {

private String composeEndpointName(String nodeIP, int port) {
StringBuffer sb = new StringBuffer();
sb.append("http://").append(nodeIP).append(":").append(port).append("/clusterservice");
sb.append("https://").append(nodeIP).append(":").append(port).append("/clusterservice");
return sb.toString();
}

Expand All @@ -106,7 +107,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
@Override
public boolean start() {
_servletContainer = new ClusterServiceServletContainer();
_servletContainer.start(new ClusterServiceServletHttpHandler(_manager), _clusterServicePort);
_servletContainer.start(new ClusterServiceServletHttpHandler(_manager), _manager.getSelfNodeIP(),
_clusterServicePort, caService);
return true;
}

Expand Down
Loading

0 comments on commit 720f57e

Please sign in to comment.