Hi Community,
I am recently trying to make the cosmos table access more secure using SAS token. I have existing implementation to access table using CloudTableClient, and I observed CloudTableClient can be created using SAS token, thus I gave it a try but I am stuck due to an issue discussed here.
Following are the steps I have followed:
- First, I am creating CloudTableClient :
StorageCredentials credentials = new StorageCredentials(
cosmosTableSettings.Uri.Host.Split('.').First(),
accountKey.ToOriginalString());
var cosmosTableClient = new CloudTableClient(cosmosTableSettings.Uri, credentials);
- I get the SAS token
var tableRef = cosmosTableClient.GetTableReference(tableName);
SharedAccessTablePolicy policy = new SharedAccessTablePolicy()
{
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1),
Permissions = SharedAccessTablePermissions.Add
| SharedAccessTablePermissions.Query
| SharedAccessTablePermissions.Update
| SharedAccessTablePermissions.Delete
};
string sasToken = tableRef.GetSharedAccessSignature(policy);
- I created CloudTableClient from sas token
credentials = new StorageCredentials(sasToken);
cosmosTableClient = new CloudTableClient(cosmosTableSettings.Uri, credentials);
- Finally I am trying to check if table exist(or any other operation) from this new client:
var cosmosTable = this.Client.GetTableReference(tableName);
var options = new TableRequestOptions()
{
// For the sake of consistency, we handle the retry logic with a
// custom more robust retry policy whose data type matches across the data store
// implementations.
RetryPolicy = new Microsoft.Azure.Cosmos.Table.NoRetry()
};
await cosmosTable.ExistsAsync(options, new OperationContext(), cancellationToken).ConfigureAwait(false)
But in the last step I am getting the following error:
{"Value cannot be null. (Parameter 'authKeyOrResourceToken | secureAuthKey')"}
Stack Trace is :
at Microsoft.Azure.Cosmos.Table.Extensions.TableExtensionOperationHelper.<ExecuteOperationAsync>d__0`1.MoveNext()
at Microsoft.Azure.Cosmos.Table.Extensions.TableExtensionRetryPolicy.<ExecuteUnderRetryPolicy>d__2`1.MoveNext()
at Microsoft.Azure.Cosmos.Table.CloudTable.<ExistsAsync>d__85.MoveNext()
Please do let me know if SAS token is supported with CloudTableClient/CloudTable or am I missing something else ?