[PM-35198] - remove orphaned blob attachments after deletion#7539
[PM-35198] - remove orphaned blob attachments after deletion#7539jaasen-livefront wants to merge 2 commits intomainfrom
Conversation
nick-livefront
left a comment
There was a problem hiding this comment.
I appreciate the detailed diagnosis! Does anything need to be done with attachments that are already orphaned? Do they need to be cleaned up across environments?
@nick-livefront I was thinking the same. I'll reach out to Matt. |
|
@nick-livefront I've created a separate ticket to handle cleanup and linked it in the description. |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7539 +/- ##
==========================================
+ Coverage 59.54% 59.59% +0.05%
==========================================
Files 2089 2089
Lines 92452 92457 +5
Branches 8218 8218
==========================================
+ Hits 55050 55103 +53
+ Misses 35458 35405 -53
- Partials 1944 1949 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|



🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-35198
Blob cleanup ticket for reference
https://bitwarden.atlassian.net/browse/PM-36194
📔 Objective
Fix a type confusion bug in the
POST /ciphers/attachment/validate/azureEventGrid handlerthat caused orphaned attachment blobs in the
attachments-v2container to persist permanentlyand never be cleaned up.
Root cause
The orphan-cleanup branch checked whether
_attachmentStorageService is AzureSendFileStorageService— the concrete type used by the Send file storage pipeline. The field is injected as
IAttachmentStorageService, which resolves toAzureAttachmentStorageServiceat runtime.Because the types are unrelated, the
ischeck always evaluated tofalse, theDeleteBlobAsynccall was never reached, and every blob that arrived without a matchingcipher attachment record was silently skipped and left in the container indefinitely.
Fix
_attachmentStorageService.FileUploadType == FileUploadType.Azure, which correctlyidentifies the attachment storage back-end without a downcast.
IAttachmentStorageService.DeleteAttachmentAsyncinterface method, passing a
CipherAttachment.MetaDatawithContainerNameset toattachments-v2(the EventGrid-enabled container) and theAttachmentIdparsed from theblob name.
organizationIddeconstruction variable fromAzureAttachmentStorageService.IdentifiersFromBlobName.Test coverage
Added
AzureValidateFile_WhenCipherNotFound_DeletesOrphanedBlob— a unit testthat posts a realistic EventGrid
Microsoft.Storage.BlobCreatedpayload through the controllerand asserts that
DeleteAttachmentAsyncis called with the correctcipherId,attachmentId,and
ContainerNamewhen no matching cipher record exists in the repository.📸 Screenshots
N/A — no UI changes.