【问题标题】:Azure Storage CloudTable Using read-only SAS key returns 403 ForbiddenAzure Storage CloudTable 使用只读 SAS 键返回 403 Forbidden
【发布时间】:2018-07-27 14:10:34
【问题描述】:

我正在尝试使用只读 SAS 密钥连接到 Azure CloudTable 并进行查询。我在 Microsoft Azure Storage Explorer 中使用了完全相同的 SAS,完全没有问题。

我尝试了几种方法(来自这个网站),但我总是得到 403 Forbidden:

方法一:

string _SAS = "https://[myaccount].table.core.windows.net/?sv=2017-07-29&ss=bfqt&srt=sco&sp=rlp&se=2019-02-22T03:14:04Z&st=2018-02-21T19:14:04Z&spr=https&sig=[mySignature]";
StorageCredentials accountSAS = new StorageCredentials(_devSAS);
CloudStorageAccount storageAccount = new CloudStorageAccount(accountSAS, "[MyAccount]", endpointSuffix: null, useHttps: true);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable tableClientTable = tableClient.GetTableReference("[MyTableName]");

TableQuery<AccessErrorLog> rangeQuery = new TableQuery<AccessErrorLog>().Where(
    TableQuery.CombineFilters(
        TableQuery.CombineFilters(
            TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, AspNetCompaniesId),
            TableOperators.And,
            TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, date)
        ),
        TableOperators.And,
        TableQuery.GenerateFilterCondition("ProgramSource", QueryComparisons.Equal, ProgramSource)
    )
);

foreach (AccessErrorLog entity in tableClientTable.ExecuteQuery(rangeQuery))
{
    LogInformationRecords.Add(entity.ErrorMessage);
}

方法二:

StorageCredentials accountSAS = new StorageCredentials(_devSAS);
CloudTable tableClientTable = new CloudTable(new Uri("https://[MyAccount].table.core.windows.net/[MyTableName]"), accountSAS);

// Same query and foreach as above...

如果我使用实际的连接字符串(即string _devKey = "DefaultEndpointsProtocol=https;AccountName=[MyAccount];AccountKey=[MyAccountKey]"; 并使用CloudStorageAccount.Parse(_devKey);,则查询和执行工作正常,不会出现 403 错误。

因为我可以在 Microsoft Azure 存储资源管理器中毫无问题地使用 SAS,并且我可以在我的应用程序中使用实际的连接字符串而没有任何问题,所以我只能认为我遗漏了一些非常明显的东西。

编辑:当我在 Azure 存储资源管理器中使用它时,我忘了提及 SAS 声称拥有“读取、列出、处理”权限。

感谢任何帮助,谢谢!

【问题讨论】:

    标签: c# azure azure-storage http-status-code-403


    【解决方案1】:

    我可以看到多种因素可能会导致您遇到的问题。一种是使用服务 SAS 与帐户 SAS。 Service SAS 允许您将 SAS 仅用于一种特定的存储产品(例如:仅 Blob)而不是所有产品,Account SAS 允许您将 SAS 用于不同的产品存储:Blob、表、队列等... 更多信息可以找到here。如果您将 Service SAS 用于特定产品,然后尝试使用 Tables,它将不允许您这样做。

    另一个因素是 SAS 帐户必须具有查询表操作(只读)才能使其工作。更多关于如何构建账户 SAS 表的 URl 可以找到here

    【讨论】:

    • 我已与帐户所有者确认这是一个帐户 SAS 密钥。他们还生成了一个包含所有服务、资源类型和权限的新密钥。我仍然得到 403。你知道我们是否必须允许 IP 地址吗?我们假设留空意味着我们没有白名单。
    • @MattCash 这完全可能是防火墙或代理问题,我推荐以下两个建议: 在防火墙/代理中允许 URL *.blob.core.windows.net 您的客户有测试方案:在您尝试从中访问 blob 的服务器上安装存储资源管理器,并检查您是否收到相同的 403 错误,此外,如果可能,还可以从不同的网络访问它。让我知道结果是什么。
    • @MattCash 您可以尝试上述建议吗?
    • 我发誓我几个月前就回答了这个问题,抱歉!不幸的是,没有任何效果。第三方终于给了我实际的连接字符串,一切都按预期工作。
    猜你喜欢
    • 2014-06-15
    • 2016-08-15
    • 2019-12-18
    • 2017-02-14
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多