Skip to content

Add migration SAS renewal and drain handling - #1444

Open
sophiatev wants to merge 4 commits into
mainfrom
stevosyan/storage-migration-sas-renewal
Open

sophiatev wants to merge 4 commits into
mainfrom
stevosyan/storage-migration-sas-renewal

Conversation

@sophiatev

Copy link
Copy Markdown
Contributor

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.

Copilot AI balanced review requested due to automatic review settings November 24, 2026 17:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Copilot AI balanced review requested due to automatic review settings November 24, 2026 19:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Capturing the monotonic timestamp after the gate read excludes response latency from the expiry calculation, allowing RefreshAsync to return already-expired SAS credentials.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 19:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The monotonic timestamp is captured after the storage read, omitting response latency and allowing renewal to return successfully with an already-expired SAS.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 20:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the internal SAS credential renewal and drain-handling changes.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

if (this.EstimatedServerTime >= gate.AccessExpiresAt)
{
continue;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have a minimum valid window? If we return right before it expires, what happens?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a more granular boolean for what was refreshed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants