4

Azure クライアント ストレージ ライブラリを使用して生成した SAS キーを使用しようとすると、Azure Storage サービスから 403 認証エラーが発生し続けます。呼び出し元のコードで例外がスローされています。

これが私が得ている例外です:

StatusMessage:Server failed to authenticate the request. Make sure the value of
Authorization header is formed correctly including the signature.
ErrorCode:AuthenticationFailed

生成される SAS キーは次のとおりです (共有したくないため、最後の署名は正確ではありません)。

https://evinsight.blob.core.windows.net/jimsworld/jellyfish2.png?sv=2012-02-12&se=2013-08-29T03%3A36%3A52Z&sr=b&sp=w&sig=FJALKJFLKASJDF%JLKSDJLK%LJDLFKSDFJKL

呼び出しコードは次のとおりです。

/// Create the document and file objects and then return the fileAccessToken
/// <param name = "file_name"></param> */
public void GetSasInfoFromEb(string file_name)
{
    /*********************************** EVINSIGHT TESTING CODE ********************************************/
    try
    {
        AzureStorageTester ast = new AzureStorageTester();
        BlobSasUri = ast.getStorageLibrarySas(file_name);
    }
    catch (Exception ex)
    {
        throw ex;
    }
    /***************************************************************************************************************/
}

/// Sends the whole small file to Azure Blob
public void WriteSmallFileToBlob()
{
    int fileId = 0;
    try
    {
        Blob = new CloudBlockBlob(new Uri(BlobSasUri));
        Blob.UploadFromStream(File.InputStream);


        File.InputStream.Close();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

SAS生成コードは次のとおりです。

    /// <summary>
    ///  Returns the URI similar to how eB does it
    /// </summary>
    /// <param name="blobName">The name of the file being uploaded/downloaded</param>
    /// <returns>The full uri for blob access</returns>
    public string getStorageLibrarySas(string blobName)
    {
        string sasKey;
        string uri;

        setupBlobContainer();

        blobName = blobName.ToLower();
        _blob = _cloudRootContainer.GetBlockBlobReference(blobName);


        sasKey = _blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
        {
            Permissions = SharedAccessBlobPermissions.Write,
            SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1)
        });

        return string.Format(CultureInfo.InvariantCulture, "{0}{1}", _blob.Uri, sasKey);
    }

    /// Creates the Blob Container
    private void setupBlobContainer()
    {
        try
        {
            Microsoft.WindowsAzure.Storage.Auth.StorageCredentials credentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(_accountName, _accountKey);

            // Create the storage account with the connection string
            Microsoft.WindowsAzure.Storage.CloudStorageAccount _cloudStorageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(credentials, true);

            _cloudBlobClient = _cloudStorageAccount.CreateCloudBlobClient();
            _cloudRootContainer = _cloudBlobClient.GetContainerReference(_rootPath.ToLower());
            _cloudRootContainer.CreateIfNotExists();

            BlobContainerPermissions containerPermissions = new BlobContainerPermissions();


            containerPermissions.PublicAccess = BlobContainerPublicAccessType.Off;
            _cloudRootContainer.SetPermissions(containerPermissions);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

何か案は?感謝します!

4

4 に答える 4

1

コメントごとに、これを提案された回答として投稿させてください。クロック スキューが発生している可能性があります。SAS の開始時刻を現在の時刻より 1 分早く設定してみてください。デフォルトでは、開始時刻は (SAS を生成するサーバーの) 現在の開始時刻に設定されます。時間設定は、ストレージ システムのクロックからわずかにずれている可能性があります。

于 2013-08-29T03:06:20.773 に答える