forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
<feature>[header]: Add TPM key backup for snapshot revert and rollback #3916
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
Closed
Closed
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
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
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
37 changes: 37 additions & 0 deletions
37
header/src/main/java/org/zstack/header/tpm/entity/TpmKeyBackupVO.java
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package org.zstack.header.tpm.entity; | ||
|
|
||
| import org.zstack.header.vo.ResourceVO; | ||
|
|
||
| import javax.persistence.Column; | ||
| import javax.persistence.Entity; | ||
| import javax.persistence.Table; | ||
| import java.sql.Timestamp; | ||
|
|
||
| /** | ||
| * Internal holder for a TPM encryption resource key snapshot during snapshot-group revert. | ||
| * The key material is stored in {@code EncryptedResourceKeyRefVO} with {@code resourceUuid} = this VO's uuid. | ||
| */ | ||
| @Entity | ||
| @Table | ||
| public class TpmKeyBackupVO extends ResourceVO { | ||
| @Column | ||
| private Timestamp createDate; | ||
| @Column | ||
| private Timestamp lastOpDate; | ||
|
|
||
| public Timestamp getCreateDate() { | ||
| return createDate; | ||
| } | ||
|
|
||
| public void setCreateDate(Timestamp createDate) { | ||
| this.createDate = createDate; | ||
| } | ||
|
|
||
| public Timestamp getLastOpDate() { | ||
| return lastOpDate; | ||
| } | ||
|
|
||
| public void setLastOpDate(Timestamp lastOpDate) { | ||
| this.lastOpDate = lastOpDate; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
header/src/main/java/org/zstack/header/tpm/entity/TpmKeyBackupVO_.java
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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package org.zstack.header.tpm.entity; | ||
|
|
||
| import org.zstack.header.vo.ResourceVO_; | ||
|
|
||
| import javax.persistence.metamodel.SingularAttribute; | ||
| import javax.persistence.metamodel.StaticMetamodel; | ||
| import java.sql.Timestamp; | ||
|
|
||
| @StaticMetamodel(TpmKeyBackupVO.class) | ||
| public class TpmKeyBackupVO_ extends ResourceVO_ { | ||
| public static volatile SingularAttribute<TpmKeyBackupVO, Timestamp> createDate; | ||
| public static volatile SingularAttribute<TpmKeyBackupVO, Timestamp> lastOpDate; | ||
| } |
24 changes: 24 additions & 0 deletions
24
header/src/main/java/org/zstack/header/tpm/message/DeleteTpmKeyBackupMsg.java
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.zstack.header.tpm.message; | ||
|
|
||
| import org.zstack.header.message.NeedReplyMessage; | ||
|
|
||
| public class DeleteTpmKeyBackupMsg extends NeedReplyMessage { | ||
| private String tpmUuid; | ||
| private String tpmKeyBackupUuid; | ||
|
|
||
| public String getTpmUuid() { | ||
| return tpmUuid; | ||
| } | ||
|
|
||
| public void setTpmUuid(String tpmUuid) { | ||
| this.tpmUuid = tpmUuid; | ||
| } | ||
|
|
||
| public String getTpmKeyBackupUuid() { | ||
| return tpmKeyBackupUuid; | ||
| } | ||
|
|
||
| public void setTpmKeyBackupUuid(String tpmKeyBackupUuid) { | ||
| this.tpmKeyBackupUuid = tpmKeyBackupUuid; | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
header/src/main/java/org/zstack/header/tpm/message/DeleteTpmKeyBackupReply.java
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package org.zstack.header.tpm.message; | ||
|
|
||
| import org.zstack.header.message.MessageReply; | ||
|
|
||
| public class DeleteTpmKeyBackupReply extends MessageReply { | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
备份清理失败不应导致整个 revert 操作失败。
此时主要的 revert 操作(卷恢复、TPM 密钥恢复)已经成功完成。
TpmKeyBackupVO是临时性的辅助记录,其清理失败不应该使整个流程失败。建议改为记录警告日志并继续执行。🔧 建议的修复方案
.then(Flow.of("delete-tpm-key-backup") .runIf(data -> context.tpmKeyBackupUuid != null) .handle(trigger -> { DeleteTpmKeyBackupMsg delMsg = new DeleteTpmKeyBackupMsg(); delMsg.setTpmUuid(context.tpmUuid); delMsg.setTpmKeyBackupUuid(context.tpmKeyBackupUuid); bus.makeTargetServiceIdByResourceUuid(delMsg, SERVICE_ID, context.tpmUuid); bus.send(delMsg, new CloudBusCallBack(trigger) { `@Override` public void run(MessageReply r) { - if (r.isSuccess()) { - context.tpmKeyBackupUuid = null; - trigger.next(); - } else { - trigger.fail(r.getError()); + if (!r.isSuccess()) { + logger.warn(String.format( + "failed to delete TpmKeyBackupVO[uuid:%s] after successful revert, but continuing: %s", + context.tpmKeyBackupUuid, r.getError().getDetails())); } + context.tpmKeyBackupUuid = null; + trigger.next(); } }); }) .build())🤖 Prompt for AI Agents