Azure Blob 存储(REST API):无法使用 SAS 令牌通过curl 列出容器中的 blob

问题描述 投票:0回答:1

我已经使用 Azure Blob 存储 REST API 几天了。

我可以毫无问题地连接到资源、列出容器并为任何给定容器生成 SAS 令牌。

但是,我现在在尝试使用为容器生成的 SAS 令牌列出容器内的 blob 时遇到问题。

使用生成的 SAS 令牌,我尝试了以下curl命令(取自https://learn.microsoft.com/en-us/rest/api/storageservices/list-blobs?tabs=microsoft-entra-id

curl -X GET "https://dat3473spa01cfeMtest.blob.core.windows.net/90480397-91234697-218-test-dir01?restype=container&comp=list&?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl"

其中

https://dat3473spa01cfeMtest.blob.core.windows.net
是 blobServiceUri,
90480397-91234697-218-test-dir01
是容器名称,
?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl
是我在上一步中为容器生成的 SAS 令牌。

运行curl命令时,我收到以下错误消息:

<?xml version="1.0" encoding="utf-8"?>
<Error>
    <Code>AuthenticationFailed</Code>
    <Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:d370a92d-301e-0082-34ee-25f845000000
Time:2024-10-24T08:30:24.7319888Z</Message>
    <AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail>
</Error>

我认为问题与我在curl命令中指定SAS令牌的方式有关,但是从前面提到的网站(

https://learn.microsoft.com/en-us/rest/api/storageservices/list-blobs?tabs=microsoft-entra-id
)上的文档中我看不到如何正确指定SAS令牌,如果确实,这是我的curl命令的问题。

我还尝试过以下命令:

curl -X GET "https://dat3473spa01cfeMtest.blob.core.windows.net/90480397-91234697-218-test-dir01?restype=container&comp=list" -H "x-ms-version: 2025-01-05" -H "x-ms-date: Thu, 24 oct. 2024 08:29:07 GMT" -H "Authorization: ?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl"

curl -X GET "https://dat3473spa01cfeMtest.blob.core.windows.net/90480397-91234697-218-test-dir01?restype=container&comp=list" -H "x-ms-version: 2025-01-05" -H "x-ms-date: Thu, 24 oct. 2024 08:29:07 GMT" -H "Authorization: credential=?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl"

curl -X GET "https://dat3473spa01cfeMtest.blob.core.windows.net/90480397-91234697-218-test-dir01?restype=container&comp=list" -H "x-ms-version: 2025-01-05" -H "x-ms-date: Thu, 24 oct. 2024 08:29:07 GMT" -H "Authorization: credentials=?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl"

curl -X GET "https://dat3473spa01cfeMtest.blob.core.windows.net/90480397-91234697-218-test-dir01?restype=container&comp=list" -H "x-ms-version: 2025-01-05" -H "x-ms-date: Thu, 24 oct. 2024 08:29:07 GMT" -H "Authorization: token ?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl"

这些都给出了错误:

<Error>
    <Code>InvalidAuthenticationInfo</Code>
    <Message>Authentication information is not given in the correct format. Check the value of Authorization header.
RequestId:79a74d3f-101e-0071-5bf0-255fd0000000
Time:2024-10-24T08:44:39.7753277Z</Message>
</Error>
azure curl azure-blob-storage
1个回答
0
投票

无法使用 SAS 令牌通过curl 列出容器中的 blob。

我遵循了同样的MS-Document

我从门户生成

sas
令牌。

传送门:

enter image description here

现在我使用以下请求来使用

cURL
获取 blob 列表。

要求:

curl -X GET "https://venkat326123.blob.core.windows.net/test?restype=container&comp=list&sp=racwdli&st=2024-10-24T08:59:44Z&se=2024-10-24T16:59:44Z&spr=https&sv=2022-11-02&sr=c&sig=redacted"

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.