Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TLS error when using HTTPS/TLS URL (not permitted for non-TLS protected (non-https) URLs.) #9534

Closed
nofunatall opened this issue Jan 20, 2020 · 15 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Storage Storage Service (Queues, Blobs, Files)
Milestone

Comments

@nofunatall
Copy link

nofunatall commented Jan 20, 2020

Ubuntu 19.10
Linux rio-t460p 5.3.0-26-generic #28-Ubuntu SMP Wed Dec 18 05:37:46 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Python 3.7.5
azure-core==1.2.0
azure-identity==1.2.0
azure-storage-blob==12.1.0

Describe the bug
When trying to do a batch delete blob using a blob client created using a HTTPS URL the code errors with:

"Bearer token authentication is not permitted for non-TLS protected (non-https) URLs."
azure.core.exceptions.ServiceRequestError: Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.

This same blob client connection can successfully be used to list blobs in a container.
The credentials used to create the client are service principal with rbac (client/secret/tenant) and the role is set to "Storage Blob Data Owner".

Steps to reproduce
Here is some example code to reproduce the error:

STORAGE_URL = 'https://' + STORAGE_ACCOUNT + '.blob.core.windows.net'
client_credentials = ClientSecretCredential(client_id=AZURE_CLIENT, client_secret=AZURE_SECRET, tenant_id=AZURE_TENANT)
blob_service_client = BlobServiceClient(account_url=STORAGE_URL, credential=client_credentials)
container_client = blob_service_client.get_container_client(STORAGE_CONTAINER)
def run_azure_blob_list():
  result = []
  blob_list = container_client.list_blobs(name_starts_with=STORAGE_FOLDER)
  for blob in blob_list:
    if blob.last_modified < IGNORE_DATE: 
      result.append([blob.name, blob.last_modified])
  return result
blob_list = run_azure_blob_list()
container_client.delete_blobs(*blob_list)

Container endpoint:
print(container_client.primary_endpoint)

https://REDACTED.blob.core.windows.net/uploads

@chlowell chlowell added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Storage Storage Service (Queues, Blobs, Files) and removed triage labels Jan 21, 2020
@annatisch
Copy link
Member

Thanks for the report @nofunatall - I will investigate this today :)

@annatisch
Copy link
Member

annatisch commented Feb 7, 2020

Sorry for the delay @nofunatall!
Adding @xiafu-msft from the storage team for visibility.

@annatisch
Copy link
Member

Update:
I have managed to repro this locally and have confirmed that it's actually an incompatibility in the forming the Storage "batch" requests, and the way oauth policy in azure-core enforcing the 'https' URL scheme.
This fix will need to be added to Azure core, so updating the labels.
Adding @lmazuel and @chlowell
The issue is that each part in the multi-part requests for storage do not use a fully qualified URL, instead it's just a path stub, e.g. /my-container/my-blob.txt

Therefore, when we hit the TLS check in the BearerTokenCredentialsPolicy the request is deemed invalid.

Details on the Batch request formatting are here:
https://docs.microsoft.com/en-us/rest/api/storageservices/blob-batch
Note that each "subrequest" is authenticated independently - and each subrequest is fed through the pipeline independently in order to generate those auth headers.

@annatisch annatisch added Azure.Core and removed Storage Storage Service (Queues, Blobs, Files) labels Feb 11, 2020
@lmazuel
Copy link
Member

lmazuel commented Feb 11, 2020

I suggest we don't apply this check when the URL is partial (parse and check the scheme, instead of startswith)

@maggiepint maggiepint added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Feb 20, 2020
@annatisch
Copy link
Member

@lmazuel, @xiangyan99 - did we land on a solution for this issue?

@lmazuel
Copy link
Member

lmazuel commented Mar 9, 2020

Yes, waiting for #9821 to make it to azure-core (we missed the 1.3 timeline)

@annatisch
Copy link
Member

This fix has been merged into master and will ship with the next release :)

@Petermarcu
Copy link
Member

Should we close this issue now?

@annatisch
Copy link
Member

Yes :)

@vsalvino
Copy link

vsalvino commented Apr 18, 2020

Is this fix going out soon (1.4.*) - or is it not yet known when this will be released? I am still experiencing it in azure-core==1.4.0 and azure-storage-blobs==12.3.0.

@annatisch
Copy link
Member

Thanks @vsalvino - I had forgotten that the blobs update hadn't actually been released yet. Re-opening for now.
@xiafu-msft - do you have an idea as to when the next blobs release will be?

@annatisch annatisch reopened this Apr 18, 2020
@lmazuel
Copy link
Member

lmazuel commented May 4, 2020

Released part of 12.3.1 (see tags of this commit)

@lmazuel lmazuel closed this as completed May 4, 2020
@DroidUnknown
Copy link

Windows 11 preview
azure-core==1.16.0
azure-identity==1.5.0
azure-mgmt-synapse==2.0.0

I am getting this same error when trying to access Synapse

import os
from azure.identity import ClientSecretCredential
from azure.mgmt.synapse import SynapseManagementClient

clientId = "********-****-****-****-************";
secret = "D0i******************************";
tenant = "********-****-****-****-************";
subId = "********-****-****-****-************";
resourceGroupName = "******-***-***";
workspaceName = "***********";


credentials = ClientSecretCredential(tenant_id=tenant, client_id=clientId, client_secret=secret)

client = SynapseManagementClient(credentials, subId, base_url="dev.azuresynapse.net")

workspace = client.workspaces.get(resourceGroupName, workspaceName)
print(workspace)

This is the exception -> azure.core.exceptions.ServiceRequestError: Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.

@chlowell
Copy link
Member

chlowell commented Aug 3, 2021

That's by design in this case. Your base_url doesn't include a scheme, and the authentication policy requires that requests are protected by TLS, i.e. that their URLS begin with "https", because client requests carry access tokens. The solution then would be to add the scheme: base_url="https://dev.azuresynapse.net".

All that said, I think this is still an incorrect value. SynapseManagementClient manages Synapse resources via Azure Resource Management (ARM). base_url should be an ARM endpoint like https://management.azure.com, which is the default value and correct for Azure Public Cloud. So, you only need to specify base_url when managing resources in sovereign or private clouds. Is that what you're trying to do?

@DroidUnknown
Copy link

No I was simply trying to setup Synapse using python SDK. This is my first time trying to do something on azure and did not really understand the details. https://management.azure.com works in this case. Thanks

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

11 participants