Uzyskiwanie dostępu do pamięci blob Azure za pomocą bash, curl

Próbuję użyć usługi magazynowania obiektów blob Azure ze skryptu bash za pomocą interfejsu API REST. Wiem, że jest to możliwe do wykonania za pomocą różnych innych narzędzi lub języków, jednak chciałbym to zrobić jako skrypt basha.

Poniższy skrypt jest próbą wyświetlenia obiektów typu blob w kontenerze pamięci masowej Azure.

Ten skrypt powoduje błąd uwierzytelnienia. Łańcuch podpisów i nagłówki wyglądają poprawnie na podstawie interfejsu API REST (odniesienie) dokumentacja. Podejrzewam, że problem może polegać na żonglowaniu różnymi częściami procesu podpisywania.

Czy ktoś pomyślnie wykorzystał bash i curl, aby uzyskać dostęp do zasobów pamięci masowej w chmurze, takich jak Azure lub inni dostawcy?

#!/bin/bash

# List the blobs in an Azure storage container.

echo "usage: ${0##*/} <storage-account-name> <container-name> <access-key>"

storage_account="$1"
container_name="$2"
access_key="$3"

blob_store_url="blob.core.windows.net"
authorization="SharedKey"

request_method="GET"
request_date=$(TZ=GMT date "+%a, %d %h %Y %H:%M:%S %Z")
storage_service_version="2011-08-18"

# HTTP Request headers
x_ms_date_h="x-ms-date:$request_date"
x_ms_version_h="x-ms-version:$storage_service_version"

# Build the signature string
canonicalized_headers="${x_ms_date_h}\n${x_ms_version_h}"
canonicalized_resource="/${storage_account}/${container_name}"

string_to_sign="${request_method}\n\n\n\n\n\n\n\n\n\n\n\n${canonicalized_headers}\n${canonicalized_resource}\ncomp:list\nrestype:container"

# Decode the Base64 encoded access key, convert to Hex.
decoded_hex_key="$(echo -n $access_key | base64 -d -w0 | xxd -p -c256)"

# Create the HMAC signature for the Authorization header
signature=$(echo -n "$string_to_sign" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$decoded_hex_key" | sed 's/^.*= //' | base64 -w0)

authorization_header="Authorization: $authorization $storage_account:$signature"

curl \
  -H "$x_ms_date_h" \
  -H "$x_ms_version_h" \
  -H "$authorization_header" \
  "https://${storage_account}.${blob_store_url}/${container_name}?restype=container&comp=list"

Aktualizacja - Błąd usługi pamięci masowej i odpowiedni łańcuch podpisu wygenerowany przez skrypt.

Oto, co zwraca usługa magazynowania dlaAuthenticationFailed błąd.

<?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:27e6337e-52f3-4e85-98c7-2fabaacd9ebc
Time:2013-11-21T22:10:11.7029042Z</Message>
  <AuthenticationErrorDetail>The MAC signature found in the HTTP request
'OGYxYjk1MTFkYmNkMCgzN2YzODQwNzcyNiIyYTQxZDg0OWFjNGJiZDlmNWY5YzM1ZWQzMWViMGFjYTAyZDY4NAo='
is not the same as any computed signature. Server used following string to sign:
'GET

x-ms-date:Thu, 21 Nov 2013 22:10:11 GMT
x-ms-version:2011-08-18
/storage_account_name/storage_container
comp:list
restype:container'
  </AuthenticationErrorDetail>
</Error>

Następny jeststring_to_sign że skrypt generuje.

GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:Thu, 21 Nov 2013 22:10:11 GMT\nx-ms-version:2011-08-18\n/storage_account_name/storage_container\ncomp:list\nrestype:container

questionAnswers(5)

yourAnswerToTheQuestion