验证 Azure Table 基于 SAS 的凭据

Verify Azure Table SAS-based credentials

我正在寻找使用 Azure 存储的 Java SDK 来验证使用 SAS 的任意 Azure Table 连接字符串的简单方法,如下所示:

https://example.table.core.windows.net/example?sig=aaabbbcccdddeeefffggghhh%3D&se=2020-01-01T00%3A00%3A00Z&sv=2015-04-05&tn=example&sp=raud

我尝试了 CloudTable api 公开的一系列不同方法,但其中 none 有效。

回答您的问题:

CloudTable.exists() throws a StorageException, regardless of whether the credentials are valid

我认为在将此方法与 SAS 令牌一起使用时,SDK 存在错误。我记得 运行 前一段时间遇到过同样的问题。

getName(), getStorageUri(), getUri(), and other getters - all work locally, regardless of the credentials

这些将起作用,因为它们不进行网络呼叫。他们只是在不同的实例变量中使用他们可用的数据和return数据。

getServiceClient().downloadServiceProperties() and getServiceClient().getServiceStats() also throw various exceptions, while getServiceClient().getEndpoint() and getServiceClient().getCredentials() and others always work locally.

为了 getServiceClient().someMethod() 使用 SAS,您需要 Account SAS 而不是 Service SAS(您现在正在使用)。

Why don't I just query the Table for a row or two? Well, in many cases I need to verify a SAS that gives only write or update premissions (without delete or read permissions), and I do not want to execute a statement that changes something in the table just to check the credentials.

检查用于写操作的 SAS 令牌有效性的一种可能方法是执行您知道会因错误而失败的写操作。例如,您可以尝试插入一个已经存在的实体。在这种情况下,您应该得到 Conflict (409) 错误。您可以尝试做的另一件事是通过指定一些随机 Etag 值并检查 Precondition Failed (412) 错误来执行乐观写入。如果您收到 403 错误或 404 错误,则表明您的 SAS 令牌有问题。