Generated sas token using python is not working for azure blob

Viewed 352

I have to generate SAS token for blob inside a function app using python. I used the following code.

sas_url=generate_blob_sas(account_name=AZURE_ACC_NAME, container_name=AZURE_CONTAINER, blob_name=AZURE_BLOB, snapshot=None, account_key=AZURE_PRIMARY_KEY, user_delegation_key=None, permission="racwd", expiry='2021-06-08', start="2021-06-07", policy_id=None, ip=None)

# used following pattern to generate url

url='https://'+AZURE_ACC_NAME+'.blob.core.windows.net/'+AZURE_CONTAINER+'/'+AZURE_BLOB+'?'+sas_url

generated sas token has st,se,sp,sv,sr and sig

it gives me error as

<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:f8bf0c5e-xxxx-xxxx-xxxx-xxxxxxxxxxxx Time:2021-06-08T06:27:02.0864172Z</Message>
<AuthenticationErrorDetail>Signature not valid in the specified time frame: Start [Mon, 07 Jun 2021 00:00:00 GMT] - Expiry [Tue, 08 Jun 2021 00:00:00 GMT] - Current [Tue, 08 Jun 2021 06:27:02 GMT]</AuthenticationErrorDetail>
</Error>

requirement is I can not make blob as public and url should expire in sometime.

1 Answers

This issue is with your SAS expiry date which you are setting as 2021-06-08. What it means is that your SAS token expires on midnight of June 8th 2021 (in UTC).

Please change that to a future date (e.g. 2021-06-09) and your SAS token should work fine.

Related