You are developing a secure C# application using the `Azure.Storage.Blobs` SDK. The application must generate a Shared Access Signature (SAS) token that allows external clients to upload a single PDF file named `confidential.pdf` to a container named `secure-docs` in an Azure Storage account named `corpdata`.
Your application must comply with the following security and operational constraints:
- Authentication: Storage account access keys must not be used, stored, or referenced by the application. You must authenticate using the application's system-assigned managed identity.
- Permissions: The token must grant only write permissions to the specific blob. No read, delete, or list permissions should be granted.
- Protocol: Connections must be restricted to HTTPS only.
- Network Constraints: The token must only be usable from the client's public IP address ``.
- Validity: The token must be valid for exactly `` minutes from generation.
- Reliability: The token must be usable immediately upon receipt by the client, without failing due to potential clock synchronization differences (clock skew) between servers.
Which of the following C# code segments should you use to generate the SAS token?
- var credential = new DefaultAzureCredential();
var blobServiceClient = new BlobServiceClient(
new Uri("https://corpdata.blob.core.windows.net"), credential);
UserDelegationKey delegationKey = await blobServiceClient.GetUserDelegationKeyAsync(
startsOn: DateTimeOffset.UtcNow.AddMinutes(-15),
expiresOn: DateTimeOffset.UtcNow.AddMinutes(45)
);
var sasBuilder = new BlobSasBuilder()
{
BlobContainerName = "secure-docs",
BlobName = "confidential.pdf",
Resource = "b",
StartsOn = DateTimeOffset.UtcNow.AddMinutes(-15),
ExpiresOn = DateTimeOffset.UtcNow.AddMinutes(30),
Protocol = SasProtocol.Https,
IPRange = SasIPRange.Parse("198.51.100.72")
};
sasBuilder.SetPermissions(BlobSasPermissions.Write);
string sasToken = sasBuilder.ToSasQueryParameters(delegationKey, "corpdata").ToString();Answer - Bvar sharedKeyCredential = new StorageSharedKeyCredential("corpdata", "AccountKeyString");
var blobServiceClient = new BlobServiceClient(
new Uri("https://corpdata.blob.core.windows.net"), sharedKeyCredential);
var sasBuilder = new BlobSasBuilder()
{
BlobContainerName = "secure-docs",
BlobName = "confidential.pdf",
Resource = "b",
StartsOn = DateTimeOffset.UtcNow.AddMinutes(-15),
ExpiresOn = DateTimeOffset.UtcNow.AddMinutes(30),
Protocol = SasProtocol.Https,
IPRange = SasIPRange.Parse("198.51.100.72")
};
sasBuilder.SetPermissions(BlobSasPermissions.Write);
string sasToken = sasBuilder.ToSasQueryParameters(sharedKeyCredential).ToString(); - Cvar credential = new DefaultAzureCredential();
var blobServiceClient = new BlobServiceClient(
new Uri("https://corpdata.blob.core.windows.net"), credential);
UserDelegationKey delegationKey = await blobServiceClient.GetUserDelegationKeyAsync(
startsOn: DateTimeOffset.UtcNow,
expiresOn: DateTimeOffset.UtcNow.AddMinutes(30)
);
var sasBuilder = new BlobSasBuilder()
{
BlobContainerName = "secure-docs",
BlobName = "confidential.pdf",
Resource = "b",
StartsOn = DateTimeOffset.UtcNow,
ExpiresOn = DateTimeOffset.UtcNow.AddMinutes(30),
Protocol = SasProtocol.Https,
IPRange = SasIPRange.Parse("198.51.100.72")
};
sasBuilder.SetPermissions(BlobSasPermissions.Write);
string sasToken = sasBuilder.ToSasQueryParameters(delegationKey, "corpdata").ToString(); - Dvar credential = new DefaultAzureCredential();
var blobServiceClient = new BlobServiceClient(
new Uri("https://corpdata.blob.core.windows.net"), credential);
UserDelegationKey delegationKey = await blobServiceClient.GetUserDelegationKeyAsync(
startsOn: DateTimeOffset.UtcNow.AddMinutes(-15),
expiresOn: DateTimeOffset.UtcNow.AddMinutes(45)
);
var sasBuilder = new BlobSasBuilder()
{
BlobContainerName = "secure-docs",
Resource = "c",
StartsOn = DateTimeOffset.UtcNow.AddMinutes(-15),
ExpiresOn = DateTimeOffset.UtcNow.AddMinutes(30),
Protocol = SasProtocol.HttpsAndHttp,
IPRange = SasIPRange.Parse("198.51.100.72")
};
sasBuilder.SetPermissions(BlobSasPermissions.Write);
string sasToken = sasBuilder.ToSasQueryParameters(delegationKey, "corpdata").ToString();