Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Critical expiry checks can publish already-expired SAS credentials after delayed reads and continue returning them after renewal fails, causing authentication failures instead of the intended unavailability exception.
2 open issues
What changed in this PR
Adds internal SAS renewal and drain handling for Azure Storage migration. The manager has no runtime caller yet; workload-client integration remains separate.
Changes:
- Adds short-lived SAS renewal using Storage time, conditional control-row updates, cached delegation keys, and in-place credential updates.
- Introduces an unavailable-service exception and upgrades Azure.Storage.Queues for delegation-key support.
- Adds simulated Storage tests covering renewal, drain races, failures, cancellation, and refresh-loop lifecycle.
| File | Description |
|---|---|
| test/DurableTask.AzureStorage.Tests/MigrationSasManagerTests.cs | Tests renewal and drain handling using local SDK responses. |
| src/DurableTask.AzureStorage/Storage/MigrationSasManager.cs | Implements credential renewal, caching, and drain detection. |
| src/DurableTask.AzureStorage/OrchestrationServiceUnavailableException.cs | Defines the exception for unavailable backend access. |
| Directory.Packages.props | Updates Azure.Storage.Queues to 12.25.0. |
Review effort: Balanced
| if (this.EstimatedServerTime >= gate.AccessExpiresAt) | ||
| { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Should this have a minimum valid window? If we return right before it expires, what happens?
There was a problem hiding this comment.
I don't think it's necessary, this is meant to handle a pretty niche edge case anyway (like something in this loop taking longer than 15 seconds is quite unlikely imo), and in later PRs we have logic to retry a failed request if a SAS token does happen to be expired.
But I don't feel strongly about this and can add it
| async Task<bool> RefreshKeysAsync(DateTimeOffset serverTime, CancellationToken cancellationToken) | ||
| { | ||
| // Reuse delegation keys to sign new SAS tokens; normally only the control row needs refreshing. | ||
| bool refreshed = false; |
There was a problem hiding this comment.
Do we need a more granular boolean for what was refreshed?
There was a problem hiding this comment.
I don't think so - the point of this is to indicate that any of the keys were refreshed, it doesn't matter which
| { | ||
| case 'b': | ||
| var blob = new BlobSasBuilder { BlobContainerName = resource, Resource = "c", ExpiresOn = this.expiresAt }; | ||
| blob.SetPermissions(BlobContainerSasPermissions.Read | BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Create |
There was a problem hiding this comment.
Does migration need things like create/delete? Is this just for migration related metadata? Otherwise I would assume migration just needs read/list so it can move the data.
There was a problem hiding this comment.
So to clarify these SAS tokens are used in the normal Azure Storage flow to write customer data when migration is on, they actually aren't writing any migration metadata. We switch from keys/Entra/whatever the customer was using before to authenticate to their Azure Storage account to these short-lived tokens. The point of this is that we can bound our drain time when migration is ending. We set migration to ending, and the Azure Storage hosts recognize this and don't renew their SAS tokens any longer. But this means we also know that once we set migration to ending the longest an existing token can still be valid is only 15 seconds.

Migration hosts need to renew short-lived Storage SAS credentials while migration is active and stop renewing when the control row closes. Add the internal MigrationSasManager from stevosyan/storage-migration: it uses Storage's clock, publishes a 15-second expiry with an ETag-conditional update, reuses delegation keys, and updates cached credential objects. A drain that wins the ETag race prevents renewal.
This PR also adds OrchestrationServiceUnavailableException and updates Azure.Storage.Queues to 12.25.0 for Queue user delegation keys. Production behavior is unchanged from the integration branch. The manager has no runtime caller yet; workload-client wiring and request policies follow separately. No detailed performance telemetry is included.
Validation: 71 tests passed on each of .NET 8 and .NET Framework 4.8 (142 total), including 17 new renewal-manager cases. Coverage includes shared-key and identity credentials, the renewal margin, competing renewals/drain, missing control rows, failed and slow key acquisition, cancellation, and refresh-loop stop/restart. Tests use real SDK pipelines with simulated local Storage responses and do not contact Azure.