<fix>[storage]: ZSV-12473 support encrypted clone upload#4301
<fix>[storage]: ZSV-12473 support encrypted clone upload#4301zstack-robot-2 wants to merge 4 commits into
Conversation
Resolves: ZSV-261 Change-Id: Iff94981e12e216380d980869b951f0d38105de87
Resolves: ZSV-12473 Change-Id: I2b78b72d2126bc51978e9dc4299b304a735bbe35
|
Warning Review limit reached
More reviews will be available in 7 minutes and 25 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough为 Ceph 主存储新增加密快照临时模板创建与上传至备份存储的支持:扩展 ChangesCeph 加密快照镜像上传流程
Sequence Diagram(s)sequenceDiagram
rect rgba(173, 216, 230, 0.5)
Note over CephPrimaryStorageFactory: create-temporary-template(加密分支)
CephPrimaryStorageFactory->>CephPrimaryStorageFactory: findConnectedHostForCephLuks(primaryStorageUuid)
CephPrimaryStorageFactory->>VolumeSnapshotEncryptionHelper: prepareEncryptedTemporarySnapshotImageDek(snapshotUuid, imageUuid)
VolumeSnapshotEncryptionHelper-->>CephPrimaryStorageFactory: encryptedDek
CephPrimaryStorageFactory->>CephPrimaryStorageFactory: makeTemporaryTemplateInstallPath
CephPrimaryStorageFactory->>KVMHost: KVMHostLuksCloneCmd (httpCallToKvmHost)
KVMHost-->>CephPrimaryStorageFactory: 成功,返回 size/actualSize
CephPrimaryStorageFactory->>WorkflowData: 写入 cephEncryptedTemporaryInstallPath/encryptedDek/hostUuid
end
rect rgba(144, 238, 144, 0.5)
Note over CephPrimaryStorageFactory: upload-to-backup-storage
CephPrimaryStorageFactory->>UploadBitsToBackupStorageMsg: 设置 primaryStorageInstallPath(加密临时路径)
CephPrimaryStorageFactory->>UploadBitsToBackupStorageMsg: 设置 encrypted/encryptedDek/encryptedHostUuid
CephPrimaryStorageFactory->>CephPrimaryStorageBase: 触发上传
CephPrimaryStorageBase->>MediatorUploadParam: 设置 encrypted/encryptedDek/encryptedHostUuid
MediatorUploadParam->>BackupStorage: 上传加密镜像
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
storage/src/main/java/org/zstack/storage/encrypt/VolumeEncryptedResourceKeyBackend.java (1)
43-44: ⚡ Quick win请为新增接口方法补充 Javadoc 契约说明
Line 43、Line 57、Line 59 新增了接口方法,但缺少方法级注释;这里是跨模块加密密钥复制契约,建议至少补齐参数语义与行为说明(例如“仅复制绑定关系/是否幂等/异常语义”)。
可参考的最小修改
+ /** + * 检查备份资源是否已绑定 key provider。 + * + * `@param` backupUuid 备份资源 UUID + * `@return` true 表示存在绑定记录 + */ boolean checkBackupKeyProviderAttached(String backupUuid); + /** + * 将备份资源的密钥绑定复制到临时快照镜像。 + */ void copyBackupKeyToTemporarySnapshotImage(String backupUuid, String imageUuid); + /** + * 将备份资源的密钥绑定复制到卷。 + */ void copyBackupKeyToVolume(String backupUuid, String volumeUuid);As per coding guidelines, “接口方法不应有多余的修饰符(例如 public),且必须配有有效的 Javadoc 注释。”
Also applies to: 57-60
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@storage/src/main/java/org/zstack/storage/encrypt/VolumeEncryptedResourceKeyBackend.java` around lines 43 - 44, Add Javadoc documentation to the new interface methods checkBackupKeyProviderAttached (line 43) and the two additional methods mentioned at lines 57-60. Each Javadoc comment should include parameter descriptions (explaining what the input parameters like backupUuid represent), a description of the method's behavior and return value, and any relevant contract details specific to this cross-module encrypted key copying scenario (such as whether the operation is idempotent, what binding relationships are affected, or what exceptions may be thrown). Ensure the comments clearly document the operational contract for callers of these interface methods.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java`:
- Around line 5230-5232: Add validation for the encryption upload parameters
before transparently passing them through. In the CephPrimaryStorageBase class
where param.encrypted, param.encryptedDek, and param.encryptedHostUuid are being
assigned from the message, first validate that when msg.getEncrypted() is true,
both msg.getEncryptedDek() and msg.getEncryptedHostUuid() must be present and
non-null. If encrypted is true but either of these required fields is missing,
fail fast by throwing an exception with a clear error message indicating the
missing encryption contract fields. Only populate param.encryptedDek and
param.encryptedHostUuid when the encrypted flag is actually true, to avoid
propagating incomplete encryption data downstream.
---
Nitpick comments:
In
`@storage/src/main/java/org/zstack/storage/encrypt/VolumeEncryptedResourceKeyBackend.java`:
- Around line 43-44: Add Javadoc documentation to the new interface methods
checkBackupKeyProviderAttached (line 43) and the two additional methods
mentioned at lines 57-60. Each Javadoc comment should include parameter
descriptions (explaining what the input parameters like backupUuid represent), a
description of the method's behavior and return value, and any relevant contract
details specific to this cross-module encrypted key copying scenario (such as
whether the operation is idempotent, what binding relationships are affected, or
what exceptions may be thrown). Ensure the comments clearly document the
operational contract for callers of these interface methods.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5bd87bf8-253e-4a19-8631-b94a232687de
📒 Files selected for processing (7)
header/src/main/java/org/zstack/header/storage/primary/MediatorUploadParam.javaplugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.javaplugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageFactory.javaplugin/ceph/src/main/java/org/zstack/storage/ceph/primary/UploadBitsToBackupStorageMsg.javastorage/src/main/java/org/zstack/storage/encrypt/DummyVolumeEncryptedResourceKeyBackend.javastorage/src/main/java/org/zstack/storage/encrypt/VolumeEncryptedInitialExtension.javastorage/src/main/java/org/zstack/storage/encrypt/VolumeEncryptedResourceKeyBackend.java
| param.encrypted = msg.getEncrypted(); | ||
| param.encryptedDek = msg.getEncryptedDek(); | ||
| param.encryptedHostUuid = msg.getEncryptedHostUuid(); |
There was a problem hiding this comment.
先校验加密上传参数再透传。
encrypted=true 时,encryptedDek 和 encryptedHostUuid 是后续 KVM/ImageStore 加密上传的必需契约;这里直接透传会把缺失字段推迟到下游失败,可能产出不可用的备份模板。建议在消息边界 fail fast,并只在加密场景填充敏感字段。
建议修复
param.primaryStorageUuid = msg.getPrimaryStorageUuid();
param.primaryStorageInstallPath = msg.getPrimaryStorageInstallPath();
param.backupStorageInstallPath = msg.getBackupStorageInstallPath();
- param.encrypted = msg.getEncrypted();
- param.encryptedDek = msg.getEncryptedDek();
- param.encryptedHostUuid = msg.getEncryptedHostUuid();
+ if (Boolean.TRUE.equals(msg.getEncrypted()) &&
+ (StringUtils.isBlank(msg.getEncryptedDek()) || StringUtils.isBlank(msg.getEncryptedHostUuid()))) {
+ reply.setError(operr(
+ "encrypted upload requires encryptedDek and encryptedHostUuid; image[uuid:%s], backupStorage[uuid:%s]",
+ msg.getImageUuid(), msg.getBackupStorageUuid()));
+ bus.reply(msg, reply);
+ completion.done();
+ return;
+ }
+ param.encrypted = Boolean.TRUE.equals(msg.getEncrypted());
+ if (param.encrypted) {
+ param.encryptedDek = msg.getEncryptedDek();
+ param.encryptedHostUuid = msg.getEncryptedHostUuid();
+ }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java`
around lines 5230 - 5232, Add validation for the encryption upload parameters
before transparently passing them through. In the CephPrimaryStorageBase class
where param.encrypted, param.encryptedDek, and param.encryptedHostUuid are being
assigned from the message, first validate that when msg.getEncrypted() is true,
both msg.getEncryptedDek() and msg.getEncryptedHostUuid() must be present and
non-null. If encrypted is true but either of these required fields is missing,
fail fast by throwing an exception with a clear error message indicating the
missing encryption contract fields. Only populate param.encryptedDek and
param.encryptedHostUuid when the encrypted flag is actually true, to avoid
propagating incomplete encryption data downstream.
Resolves: ZSV-12473 Change-Id: Ifcfb943d26a5bb4319a3bdbb5e9576524d8ef51e
Resolves: ZSV-12473 Change-Id: I6f6a8bccffe7b94df8c27617376008a9db14e17b
Summary
Fix encrypted Ceph clone template upload so the snapshot is cloned through a KVM host with the temporary encrypted DEK before ImageStore upload.
Changes
Testing
git diff --checkfor all four reposcbok zsv compile --no-deploy --docker-host none --zstack-root /Users/mizar/.config/superpowers/worktrees/zstack/ceph-sblk-clone-encryption:header,storage,ceph,premium,mevoco,sharedblocksucceeded; unrelatedpremium/cryptofailed on missingScannerAlarmStateVOpython -m py_compile kvmagent/kvmagent/plugins/imagestore.py kvmagent/kvmagent/plugins/ceph_storage_plugin.pyGOOS=linux GOARCH=amd64 go test -c ./clientand./client/driverundersrc/image-storeResolves: ZSV-12473
sync from gitlab !10259