Windows Azure의 개인 컨테이너에 저장된 얼룩에 액세스하려고합니다. 컨테이너에 공유 액세스 서명이 있지만 Blob에 액세스하려고 을 시도하면 StorgeClientException이 발생합니다. "서버가 요청을 인증하지 못했습니다. 인증 헤더가 올바르게 서명을 포함하여 을 형성했는지 확인하십시오."SharedAccessSignature를 사용하여 얼룩에 액세스하는 방법
컨테이너를 생성하고 블롭은 다음과 같습니다 업로드 코드 :
나는 덩어리를 읽을 사용하려고 한 코드는 다음과 같습니다// create the container, set a Shared Access Signature, and share it
// first this to do is to create the connnection to the storage account
// this should be in app.config but as this isa test it will just be implemented
// here:
// add a reference to Microsoft.WindowsAzure.StorageClient
// and Microsoft.WindowsAzure.StorageClient set up the objects
//storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["ConnectionString"]);
blobClient = storageAccount.CreateCloudBlobClient();
// get a reference tot he container for the shared access signature
container = blobClient.GetContainerReference("blobcontainer");
container.CreateIfNotExist();
// now create the permissions policy to use and a public access setting
var permissions = container.GetPermissions();
permissions.SharedAccessPolicies.Remove("accesspolicy");
permissions.SharedAccessPolicies.Add("accesspolicy", new SharedAccessPolicy
{
// this policy is live immediately
// if the policy should be delatyed then use:
//SharedAccessStartTime = DateTime.Now.Add(T); where T is some timespan
SharedAccessExpiryTime =
DateTime.UtcNow.AddYears(2),
Permissions =
SharedAccessPermissions.Read | SharedAccessPermissions.Write
});
// turn off public access
permissions.PublicAccess = BlobContainerPublicAccessType.Off;
// set the permission on the ocntianer
container.SetPermissions(permissions);
var sas = container.GetSharedAccessSignature(new SharedAccessPolicy(), "accesspolicy");
StorageCredentialsSharedAccessSignature credentials = new StorageCredentialsSharedAccessSignature(sas);
CloudBlobClient client = new CloudBlobClient(storageAccount.BlobEndpoint,
new StorageCredentialsSharedAccessSignature(sas));
CloudBlob sasblob = client.GetBlobReference("blobcontainer/someblob.txt");
sasblob.UploadText("I want to read this text via a rest call");
// write the SAS to file so I can use it later in other apps
using (var writer = new StreamWriter(@"C:\policy.txt"))
{
writer.WriteLine(container.GetSharedAccessSignature(new SharedAccessPolicy(), "securedblobpolicy"));
}
:
// the storace credentials shared access signature is copied directly from the text file "c:\policy.txt"
CloudBlobClient client = new CloudBlobClient("https://my.azurestorage.windows.net/", new StorageCredentialsSharedAccessSignature("?sr=c&si=accesspolicy&sig=0PMoXpht2TF1Jr0uYPfUQnLaPMiXrqegmjYzeg69%2FCI%3D"));
CloudBlob blob = client.GetBlobReference("blobcontainer/someblob.txt");
Console.WriteLine(blob.DownloadText());
Console.ReadLine();
내가 할 수있는 계정 자격 증명을 추가하여 위의 작업을 수행 할 수 있지만 그게 바로 피하려고합니다. 나는 무언가 을 내 계정 자격 증명만큼 민감하게 보이기를 원치 않으며 계정 자격 증명 없이는 클라이언트 응용 프로그램에 서명하는 방법을 모릅니다.
도움을 주시면 대단히 감사하겠습니다.
my.azurestorage.windows.net에는 계정 정보를 공개 할 필요가 없으므로 여기에 있습니다. 그리고 코드는 여러분이 참조한 블로그의 코드와 매우 유사하게 보일 수 있으며, 어느 정도는 작동하지만 공유 액세스 서명을 사용하여 BLOB에 대한 익명 액세스를 허용하지 않습니다. 그것이 문제이다! – crunchy
하지만 실제 값은'.blob.core.windows.net'으로 끝납니다. 맞습니까? (접두어는 저장소 계정의 이름입니다.) – smarx
실제 응용 프로그램의 값은 컨테이너의 주소입니다. 현재 코드를 열지 못했지만 계정 자격 증명을 제공 할 때 컨테이너와 얼룩에 액세스 할 수 있으므로 정확합니다. 명명 된 정책이 올바른 값을 반환하지 않는 이유는 아직 확실하지 않지만 지금은 올바르게 작동합니다. 의견을 보내 주셔서 감사합니다. – crunchy