forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[kvm]: decouple TLS cert detection from libvirtd restart toggle #3866
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
Open
zstack-robot-2
wants to merge
1
commit into
5.5.16
Choose a base branch
from
sync/yingzhe.hu/fix/ZSTAC-84446-reopen
base: 5.5.16
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−42
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5716,54 +5716,61 @@ public void run(FlowTrigger trigger, Map data) { | |
|
|
||
| @Override | ||
| public boolean skip(Map data) { | ||
| // ZSTAC-84446: run detection whenever TLS is enabled so check | ||
| // and first-deploy share the same IP source. | ||
| return CoreGlobalProperty.UNIT_TEST_ON | ||
| || !KVMGlobalConfig.LIBVIRT_TLS_ENABLED.value(Boolean.class) | ||
| || !rcf.getResourceConfigValue( | ||
| KVMGlobalConfig.RECONNECT_HOST_RESTART_LIBVIRTD_SERVICE, | ||
| self.getUuid(), Boolean.class); | ||
| || !KVMGlobalConfig.LIBVIRT_TLS_ENABLED.value(Boolean.class); | ||
| } | ||
|
|
||
| @Override | ||
| public void run(FlowTrigger trigger, Map data) { | ||
| String managementIp = getSelf().getManagementIp(); | ||
|
|
||
| SshShell sshShell = new SshShell(); | ||
| sshShell.setHostname(managementIp); | ||
| sshShell.setUsername(getSelf().getUsername()); | ||
| sshShell.setPassword(getSelf().getPassword()); | ||
| sshShell.setPort(getSelf().getPort()); | ||
|
|
||
| // Use the same logic as zstack-utility host_plugin.fact() so MN's | ||
| // expectation matches what the host itself reports. | ||
| String certIpList = KVMHostUtils.collectHostIps( | ||
| sshShell, self.getUuid(), managementIp); | ||
| List<String> allIps = new ArrayList<>(Arrays.asList(certIpList.split(","))); | ||
| // Save detected IPs so apply-ansible-playbook can union with EXTRA_IPS | ||
| // without running a second SSH. | ||
| data.put("TLS_DETECTED_IPS", certIpList); | ||
|
|
||
| SshResult sanResult = sshShell.runCommand( | ||
| "openssl x509 -in /etc/pki/libvirt/servercert.pem -noout -ext subjectAltName 2>/dev/null"); | ||
|
|
||
| boolean needDeploy = false; | ||
| if (sanResult.isSshFailure() || sanResult.getReturnCode() != 0 | ||
| || sanResult.getStdout() == null || sanResult.getStdout().trim().isEmpty()) { | ||
| // cert doesn't exist or can't be read | ||
| logger.info(String.format("TLS cert not found or unreadable on host[uuid:%s], need deploy", self.getUuid())); | ||
| needDeploy = true; | ||
| } else { | ||
| Set<String> sanIps = parseSanIps(sanResult.getStdout()); | ||
| for (String ip : allIps) { | ||
| if (!sanIps.contains(ip)) { | ||
| logger.info(String.format("TLS cert SAN missing IP %s on host[uuid:%s], need deploy", ip, self.getUuid())); | ||
| needDeploy = true; | ||
| break; | ||
| // ZSTAC-84446: detection is best-effort. SSH failures must NOT | ||
| // break reconnect; on error we skip and let the deploy step | ||
| // fall back to mgmtIp + EXTRA_IPS. | ||
| try { | ||
| String managementIp = getSelf().getManagementIp(); | ||
|
|
||
| SshShell sshShell = new SshShell(); | ||
| sshShell.setHostname(managementIp); | ||
| sshShell.setUsername(getSelf().getUsername()); | ||
| sshShell.setPassword(getSelf().getPassword()); | ||
| sshShell.setPort(getSelf().getPort()); | ||
|
|
||
| // Same logic as zstack-utility host_plugin.fact() so MN's | ||
| // expectation matches what the host itself reports. | ||
| String certIpList = KVMHostUtils.collectHostIps( | ||
| sshShell, self.getUuid(), managementIp); | ||
| List<String> allIps = new ArrayList<>(Arrays.asList(certIpList.split(","))); | ||
| // Save detected IPs so apply-ansible-playbook can union with | ||
| // EXTRA_IPS without running a second SSH. | ||
| data.put("TLS_DETECTED_IPS", certIpList); | ||
|
|
||
| SshResult sanResult = sshShell.runCommand( | ||
| "openssl x509 -in /etc/pki/libvirt/servercert.pem -noout -ext subjectAltName 2>/dev/null"); | ||
|
|
||
| boolean needDeploy = false; | ||
| if (sanResult.isSshFailure() || sanResult.getReturnCode() != 0 | ||
| || sanResult.getStdout() == null || sanResult.getStdout().trim().isEmpty()) { | ||
| logger.info(String.format("TLS cert not found or unreadable on host[uuid:%s], need deploy", self.getUuid())); | ||
| needDeploy = true; | ||
| } else { | ||
| Set<String> sanIps = parseSanIps(sanResult.getStdout()); | ||
| for (String ip : allIps) { | ||
| if (!sanIps.contains(ip)) { | ||
|
Comment on lines
+5741
to
+5759
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. 先规范化 Line 5743 直接 🛠️ 建议修改- List<String> allIps = new ArrayList<>(Arrays.asList(certIpList.split(",")));
+ List<String> allIps = Arrays.stream(certIpList.split(","))
+ .map(String::trim)
+ .filter(StringUtils::isNotBlank)
+ .collect(Collectors.toList());🤖 Prompt for AI Agents |
||
| logger.info(String.format("TLS cert SAN missing IP %s on host[uuid:%s], need deploy", ip, self.getUuid())); | ||
| needDeploy = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (needDeploy) { | ||
| data.put("NEED_DEPLOY_TLS_CERT", true); | ||
| if (needDeploy) { | ||
| data.put("NEED_DEPLOY_TLS_CERT", true); | ||
| } | ||
| } catch (Exception e) { | ||
| logger.warn(String.format( | ||
| "TLS cert detection failed on host[uuid:%s], continue connect flow: %s", | ||
| self.getUuid(), e.getMessage()), e); | ||
| } | ||
|
|
||
| trigger.next(); | ||
|
|
@@ -5910,11 +5917,19 @@ public void run(final FlowTrigger trigger, Map data) { | |
| self.getUuid(), managementIp, detectedIps); | ||
| deployArguments.setTlsCertIps(tlsCertIps); | ||
|
|
||
| // Force ansible deploy when TLS cert needs update (detected by check-tls-certs flow) | ||
| // ZSTAC-84446: force ansible re-run only when policy allows; | ||
| // see KVMHostUtils#shouldForceTlsRedeploy. | ||
| Boolean needDeployTlsCert = (Boolean) data.get("NEED_DEPLOY_TLS_CERT"); | ||
| if (Boolean.TRUE.equals(needDeployTlsCert)) { | ||
| boolean allowRestart = rcf.getResourceConfigValue( | ||
| KVMGlobalConfig.RECONNECT_HOST_RESTART_LIBVIRTD_SERVICE, | ||
| self.getUuid(), Boolean.class); | ||
| if (KVMHostUtils.shouldForceTlsRedeploy( | ||
| Boolean.TRUE.equals(needDeployTlsCert), allowRestart, info.isNewAdded())) { | ||
| runner.setForceRun(true); | ||
| deployArguments.setRestartLibvirtd("true"); | ||
| } else if (Boolean.TRUE.equals(needDeployTlsCert)) { | ||
| logger.info(String.format("TLS cert needs deploy on host[uuid:%s], skip " + | ||
| "force-run to keep kvmagent PID stable", self.getUuid())); | ||
| } | ||
|
|
||
| if (deployArguments.isForceRun()) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.