-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[kvm]: update TLS certs via kvmagent on host reconnect #3706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.5.12
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |||||||||||||||||
| import org.zstack.core.db.SQLBatch; | ||||||||||||||||||
| import org.zstack.core.db.SimpleQuery; | ||||||||||||||||||
| import org.zstack.core.db.SimpleQuery.Op; | ||||||||||||||||||
| import org.zstack.core.jsonlabel.JsonLabel; | ||||||||||||||||||
| import org.zstack.core.thread.*; | ||||||||||||||||||
| import org.zstack.core.timeout.ApiTimeoutManager; | ||||||||||||||||||
| import org.zstack.core.timeout.TimeHelper; | ||||||||||||||||||
|
|
@@ -195,6 +196,7 @@ public class KVMHost extends HostBase implements Host { | |||||||||||||||||
| private String checkSnapshotPath; | ||||||||||||||||||
| private String mergeSnapshotPath; | ||||||||||||||||||
| private String hostFactPath; | ||||||||||||||||||
| private String updateTlsCertPath; | ||||||||||||||||||
| private String hostCheckFilePath; | ||||||||||||||||||
| private String attachIsoPath; | ||||||||||||||||||
| private String detachIsoPath; | ||||||||||||||||||
|
|
@@ -328,6 +330,10 @@ public KVMHost(KVMHostVO self, KVMHostContext context) { | |||||||||||||||||
| ub.path(KVMConstant.KVM_HOST_FACT_PATH); | ||||||||||||||||||
| hostFactPath = ub.build().toString(); | ||||||||||||||||||
|
|
||||||||||||||||||
| ub = UriComponentsBuilder.fromHttpUrl(baseUrl); | ||||||||||||||||||
| ub.path(KVMConstant.KVM_UPDATE_TLS_CERT_PATH); | ||||||||||||||||||
| updateTlsCertPath = ub.build().toString(); | ||||||||||||||||||
|
|
||||||||||||||||||
| ub = UriComponentsBuilder.fromHttpUrl(baseUrl); | ||||||||||||||||||
| ub.path(KVMConstant.KVM_HOST_CHECK_FILE_PATH); | ||||||||||||||||||
| hostCheckFilePath = ub.build().toString(); | ||||||||||||||||||
|
|
@@ -6025,6 +6031,70 @@ public void fail(ErrorCode errorCode) { | |||||||||||||||||
|
|
||||||||||||||||||
| flow(createCollectHostFactsFlow(info)); | ||||||||||||||||||
|
|
||||||||||||||||||
| flow(new NoRollbackFlow() { | ||||||||||||||||||
| String __name__ = "update-tls-certs-if-needed"; | ||||||||||||||||||
|
|
||||||||||||||||||
| @Override | ||||||||||||||||||
| public boolean skip(Map data) { | ||||||||||||||||||
| return CoreGlobalProperty.UNIT_TEST_ON | ||||||||||||||||||
| || !KVMGlobalConfig.LIBVIRT_TLS_ENABLED.value(Boolean.class); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| @Override | ||||||||||||||||||
| public void run(FlowTrigger trigger, Map data) { | ||||||||||||||||||
| String managementIp = getSelf().getManagementIp(); | ||||||||||||||||||
| String extraIps = HostSystemTags.EXTRA_IPS.getTokenByResourceUuid( | ||||||||||||||||||
| self.getUuid(), HostSystemTags.EXTRA_IPS_TOKEN); | ||||||||||||||||||
|
|
||||||||||||||||||
| List<String> allIps = new ArrayList<>(); | ||||||||||||||||||
| allIps.add(managementIp); | ||||||||||||||||||
| if (extraIps != null && !extraIps.isEmpty()) { | ||||||||||||||||||
| for (String ip : extraIps.split(",")) { | ||||||||||||||||||
| String trimmed = ip.trim(); | ||||||||||||||||||
| if (!trimmed.isEmpty() && !allIps.contains(trimmed)) { | ||||||||||||||||||
| allIps.add(trimmed); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| String certIps = String.join(",", allIps); | ||||||||||||||||||
|
|
||||||||||||||||||
| String caCert = new JsonLabel().get("libvirtTLSCA", String.class); | ||||||||||||||||||
| String caKey = new JsonLabel().get("libvirtTLSPrivateKey", String.class); | ||||||||||||||||||
| if (caCert == null || caKey == null) { | ||||||||||||||||||
| logger.warn("TLS CA cert/key not found in database, skipping cert update"); | ||||||||||||||||||
|
Comment on lines
+6062
to
+6065
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 把空白证书内容也当成缺失处理 这里只判断了 🩹 建议修改- String caCert = new JsonLabel().get("libvirtTLSCA", String.class);
- String caKey = new JsonLabel().get("libvirtTLSPrivateKey", String.class);
+ String caCert = StringUtils.trimToNull(new JsonLabel().get("libvirtTLSCA", String.class));
+ String caKey = StringUtils.trimToNull(new JsonLabel().get("libvirtTLSPrivateKey", String.class));
if (caCert == null || caKey == null) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| trigger.next(); | ||||||||||||||||||
| return; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| UpdateTlsCertCmd cmd = new UpdateTlsCertCmd(); | ||||||||||||||||||
| cmd.setCaCert(caCert); | ||||||||||||||||||
| cmd.setCaKey(caKey); | ||||||||||||||||||
| cmd.setCertIps(certIps); | ||||||||||||||||||
|
|
||||||||||||||||||
| new Http<>(updateTlsCertPath, cmd, UpdateTlsCertResponse.class) | ||||||||||||||||||
| .call(new ReturnValueCompletion<UpdateTlsCertResponse>(trigger) { | ||||||||||||||||||
| @Override | ||||||||||||||||||
| public void success(UpdateTlsCertResponse ret) { | ||||||||||||||||||
| if (!ret.isSuccess()) { | ||||||||||||||||||
| logger.warn(String.format("Failed to update TLS certs on host[uuid:%s]: %s", | ||||||||||||||||||
| self.getUuid(), ret.getError())); | ||||||||||||||||||
| } | ||||||||||||||||||
| // cert update failure should not block reconnect | ||||||||||||||||||
| trigger.next(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| @Override | ||||||||||||||||||
| public void fail(ErrorCode errorCode) { | ||||||||||||||||||
| logger.warn(String.format("Failed to update TLS certs on host[uuid:%s]: %s", | ||||||||||||||||||
| self.getUuid(), errorCode)); | ||||||||||||||||||
| // cert update failure should not block reconnect | ||||||||||||||||||
| trigger.next(); | ||||||||||||||||||
| } | ||||||||||||||||||
| }); | ||||||||||||||||||
| } | ||||||||||||||||||
| }); | ||||||||||||||||||
|
Comment on lines
+6034
to
+6096
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 避免在连接流程里无条件覆盖宿主机现有 TLS 证书 这里在 As per coding guidelines “平台不应直接覆盖用户可能自定义修改过的东西……应当对原状态做好记录,做好二次确认,做好回退准备”. 🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| if (info.isNewAdded()) { | ||||||||||||||||||
| flow(new NoRollbackFlow() { | ||||||||||||||||||
| String __name__ = "check-qemu-libvirt-version"; | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.