I am having problems with Azure Blobs and sharing signatures when they expire. I need to provide access to the blob for more than 1 hour (7 days), so I use the named container policy, but, unfortunately, I can not generate new URLs as soon as these 7 days.
I have the following code to create a default policy. Note that in this code I set the expiration time to 1 minute to make it easier to test:
CloudStorageAccount account = new CloudStorageAccount(credentials, true); CloudBlobClient client = new CloudBlobClient(account.BlobEndpoint, credentials); CloudBlobContainer container = client.GetContainerReference("files"); SharedAccessPolicy sharedAccessPolicy = new SharedAccessPolicy(); sharedAccessPolicy.Permissions = SharedAccessPermissions.Read; sharedAccessPolicy.SharedAccessStartTime = DateTime.UtcNow; sharedAccessPolicy.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(1); BlobContainerPermissions blobContainerPermissions = new BlobContainerPermissions(); blobContainerPermissions.SharedAccessPolicies.Add("default", sharedAccessPolicy); container.SetPermissions(blobContainerPermissions);
Then I create a SharedAccessSignature URL with the following:
CloudStorageAccount account = new CloudStorageAccount(credentials, true); CloudBlobClient client = new CloudBlobClient(account.BlobEndpoint, credentials); CloudBlobContainer container = client.GetContainerReference("files"); CloudBlob blob = container.GetBlobReference(path); string sas = blob.GetSharedAccessSignature(new SharedAccessPolicy(), "default"); Console.WriteLine(blob.Uri.AbsoluteUri + sas);
This creates the url and the url works correctly for the next minute (or 7 days in real code). After one minute, the URL is invalid and no longer works as expected.
But as soon as this expiration passed, I ran the code again to create a new URL. Unfortunately, it generates the same URL, which is still invalid.
Are the start and end times for container policies absolute, that is, when I install this policy right now:
sharedAccessPolicy.SharedAccessStartTime = DateTime.UtcNow; sharedAccessPolicy.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(1);
Is anything using this policy valid only from 10:10 AM (EDT) to 10:11 AM (EDT) today?
mfanto
source share