|
21 | 21 | import java.net.InetAddress; |
22 | 22 | import java.net.URI; |
23 | 23 | import java.util.Arrays; |
24 | | -import java.util.Collections; |
25 | 24 | import java.util.HashMap; |
26 | 25 | import java.util.HashSet; |
27 | 26 | import java.util.List; |
|
32 | 31 |
|
33 | 32 | import org.apache.cloudstack.agent.lb.IndirectAgentLB; |
34 | 33 | import org.apache.cloudstack.ca.CAManager; |
35 | | -import org.apache.cloudstack.ca.SetupCertificateCommand; |
36 | 34 | import org.apache.cloudstack.direct.download.DirectDownloadManager; |
37 | | -import org.apache.cloudstack.framework.ca.Certificate; |
38 | 35 | import org.apache.cloudstack.utils.cache.LazyCache; |
39 | | -import org.apache.cloudstack.utils.security.KeyStoreUtils; |
40 | 36 |
|
41 | 37 | import com.cloud.agent.AgentManager; |
42 | 38 | import com.cloud.agent.Listener; |
|
66 | 62 | import com.cloud.resource.ResourceStateAdapter; |
67 | 63 | import com.cloud.resource.ServerResource; |
68 | 64 | import com.cloud.resource.UnableDeleteHostException; |
69 | | -import com.cloud.utils.PasswordGenerator; |
70 | 65 | import com.cloud.utils.StringUtils; |
71 | 66 | import com.cloud.utils.UuidUtils; |
72 | 67 | import com.cloud.utils.exception.CloudRuntimeException; |
@@ -174,55 +169,7 @@ private void setupAgentSecurity(final Connection sshConnection, final String age |
174 | 169 | throw new CloudRuntimeException("Cannot secure agent communication because SSH connection is invalid for host IP=" + agentIp); |
175 | 170 | } |
176 | 171 |
|
177 | | - Integer validityPeriod = CAManager.CertValidityPeriod.value(); |
178 | | - if (validityPeriod < 1) { |
179 | | - validityPeriod = 1; |
180 | | - } |
181 | | - |
182 | | - String keystorePassword = PasswordGenerator.generateRandomPassword(16); |
183 | | - final SSHCmdHelper.SSHCmdResult keystoreSetupResult = SSHCmdHelper.sshExecuteCmdWithResult(sshConnection, |
184 | | - String.format("sudo /usr/share/cloudstack-common/scripts/util/%s " + |
185 | | - "/etc/cloudstack/agent/agent.properties " + |
186 | | - "/etc/cloudstack/agent/%s " + |
187 | | - "%s %d " + |
188 | | - "/etc/cloudstack/agent/%s", |
189 | | - KeyStoreUtils.KS_SETUP_SCRIPT, |
190 | | - KeyStoreUtils.KS_FILENAME, |
191 | | - keystorePassword, |
192 | | - validityPeriod, |
193 | | - KeyStoreUtils.CSR_FILENAME)); |
194 | | - |
195 | | - if (!keystoreSetupResult.isSuccess()) { |
196 | | - throw new CloudRuntimeException("Failed to setup keystore on the KVM host: " + agentIp); |
197 | | - } |
198 | | - |
199 | | - final Certificate certificate = caManager.issueCertificate(keystoreSetupResult.getStdOut(), Arrays.asList(agentHostname, agentIp), Collections.singletonList(agentIp), null, null); |
200 | | - if (certificate == null || certificate.getClientCertificate() == null) { |
201 | | - throw new CloudRuntimeException("Failed to issue certificates for KVM host agent: " + agentIp); |
202 | | - } |
203 | | - |
204 | | - final SetupCertificateCommand certificateCommand = new SetupCertificateCommand(certificate); |
205 | | - final SSHCmdHelper.SSHCmdResult setupCertResult = SSHCmdHelper.sshExecuteCmdWithResult(sshConnection, |
206 | | - String.format("sudo /usr/share/cloudstack-common/scripts/util/%s " + |
207 | | - "/etc/cloudstack/agent/agent.properties %s " + |
208 | | - "/etc/cloudstack/agent/%s %s " + |
209 | | - "/etc/cloudstack/agent/%s \"%s\" " + |
210 | | - "/etc/cloudstack/agent/%s \"%s\" " + |
211 | | - "/etc/cloudstack/agent/%s \"%s\"", |
212 | | - KeyStoreUtils.KS_IMPORT_SCRIPT, |
213 | | - keystorePassword, |
214 | | - KeyStoreUtils.KS_FILENAME, |
215 | | - KeyStoreUtils.SSH_MODE, |
216 | | - KeyStoreUtils.CERT_FILENAME, |
217 | | - certificateCommand.getEncodedCertificate(), |
218 | | - KeyStoreUtils.CACERT_FILENAME, |
219 | | - certificateCommand.getEncodedCaCertificates(), |
220 | | - KeyStoreUtils.PKEY_FILENAME, |
221 | | - certificateCommand.getEncodedPrivateKey())); |
222 | | - |
223 | | - if (setupCertResult != null && !setupCertResult.isSuccess()) { |
224 | | - throw new CloudRuntimeException("Failed to setup certificate in the KVM agent's keystore file, please see logs and configure manually!"); |
225 | | - } |
| 172 | + caManager.provisionCertificateViaSsh(sshConnection, agentIp, agentHostname); |
226 | 173 |
|
227 | 174 | if (logger.isDebugEnabled()) { |
228 | 175 | logger.debug("Succeeded to import certificate in the keystore for agent on the KVM host: " + agentIp + ". Agent secured and trusted."); |
|
0 commit comments