[Storage] Detect region reorder during Blob decryption - #48559
[Storage] Detect region reorder during Blob decryption#48559Jacob Lauzon (jalauzon-msft) wants to merge 6 commits into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 9 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Strengthens Blob client-side encryption v2 by detecting reordered authenticated regions during decryption.
Changes:
- Parses response content ranges to derive expected nonce counters.
- Validates each region nonce, with an environment-variable recovery bypass.
- Adds synchronous and asynchronous live tests for reordered regions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
_encryption.py |
Adds content-range parsing and nonce-order validation. |
test_blob_encryption_v2.py |
Adds synchronous reorder coverage. |
test_blob_encryption_v2_async.py |
Adds asynchronous reorder coverage. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
sdk/storage/azure-storage-blob/azure/storage/blob/_encryption.py:1005
- Please document both the new default rejection of reordered CSE v2 regions and this recovery-only environment variable in the package's Unreleased CHANGELOG entry. Without release documentation, existing blobs that previously decrypted can begin failing after upgrade, while users have no public guidance about the intentionally provided recovery path or its integrity tradeoff.
# Bypass nonce validation via an environment variable for data-recovery scenarios
# where regions were reordered. Not recommended: it can allow tampered data through.
validate_nonce = not os.environ.get("AZURE_STORAGE_CSE_V2_ALLOW_MISORDERED_AUTH_REGIONS")
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
sdk/storage/azure-storage-blob/tests/test_blob_encryption_v2.py:463
- The recovery branch introduced by this change is not covered: this test verifies only the default rejection path. Because the environment variable deliberately bypasses a security validation, exercise it here and assert that the reordered plaintext can be recovered.
# Act / Assert -- a region's nonce no longer matches its position
with pytest.raises(HttpResponseError) as e:
blob.download_blob().readall()
assert "Decryption failed." in str(e.value)
sdk/storage/azure-storage-blob/azure/storage/blob/_encryption.py:1014
- This data-recovery switch is currently discoverable only by reading private implementation code, while the unreleased CHANGELOG section has no entry for either the new decryption failure or its opt-out. Add a Bugs Fixed note documenting the behavior and the exact environment variable so affected users can recover previously reordered blobs.
# Bypass nonce validation via an environment variable for data-recovery scenarios
# where regions were reordered. Not recommended: it can allow tampered data through.
validate_nonce = os.environ.get(
"AZURE_STORAGE_CSE_V2_ALLOW_MISORDERED_AUTH_REGIONS", ""
).strip().lower() not in ("true", "1")
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
sdk/storage/azure-storage-blob/azure/storage/blob/_encryption.py:1025
- These candidate sets are not disjoint, so selecting from their union independently for every region does not reliably detect reordering. For example, Java region 256 has nonce
000000000000010000000000, which is also the .NET candidate for expected region 65535 (65536little-endian after the four-byte prefix). A ranged read after moving that block in a valid 256-GiB Java blob would therefore authenticate and return plaintext from the wrong position. Bind a blob/download to one nonce encoding (and enforce it consistently across regions) rather than accepting the per-region union; the compatibility mechanism may require a protocol-level decision.
if validate_nonce:
if nonce not in _region_nonce_candidates(nonce_counter, nonce_length):
raise ValueError("The encryption metadata is not valid and may have been modified.")
sdk/storage/azure-storage-blob/azure/storage/blob/_encryption.py:1011
- The new recovery switch is not exercised by either reordered-region test; both only cover default rejection. Add coverage that sets this environment variable, confirms reordered authenticated regions can be recovered, and restores the environment afterward. This security-sensitive escape hatch otherwise could regress or have its boolean semantics inverted unnoticed.
validate_nonce = os.environ.get(
"AZURE_STORAGE_CSE_V2_ALLOW_MISORDERED_AUTH_REGIONS", ""
).strip().lower() not in ("true", "1")
This comment has been minimized.
This comment has been minimized.
| "AZURE_STORAGE_CSE_V2_ALLOW_MISORDERED_AUTH_REGIONS", "" | ||
| ).strip().lower() not in ("true", "1") | ||
|
|
||
| candidate_encodings = _region_nonce_encodings(nonce_length) |
[Pilot] PR Pipeline Failure AnalysisA CI pipeline failed on this pull request. Here is an automated analysis of what went wrong and how to get the build green. What failedThe
Recommended next steps
Raw pipeline analysis (azsdk ci analyze)
|
No description provided.