-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Enforce https in search #11337
Enforce https in search #11337
Conversation
@@ -45,6 +45,14 @@ class SearchServiceClient(HeadersMixin): # pylint: disable=too-many-public-meth | |||
def __init__(self, endpoint, credential, **kwargs): | |||
# type: (str, AzureKeyCredential, **Any) -> None | |||
|
|||
try: | |||
if endpoint.lower().startswith('http') and not endpoint.lower().startswith('https'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there scenario were a valid endpoint would not start by http
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
service only supports https
@@ -45,6 +45,14 @@ class SearchServiceClient(HeadersMixin): # pylint: disable=too-many-public-meth | |||
def __init__(self, endpoint, credential, **kwargs): | |||
# type: (str, AzureKeyCredential, **Any) -> None | |||
|
|||
try: | |||
if endpoint.lower().startswith('http') and not endpoint.lower().startswith('https'): | |||
raise ValueError("Endpoint should be secure. Use https.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use a wording more consistent with Azure-core:
azure-sdk-for-python/sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py
Line 55 in cd25de5
"Bearer token authentication is not permitted for non-TLS protected (non-https) URLs." |
@@ -45,6 +45,14 @@ class SearchServiceClient(HeadersMixin): # pylint: disable=too-many-public-meth | |||
def __init__(self, endpoint, credential, **kwargs): | |||
# type: (str, AzureKeyCredential, **Any) -> None | |||
|
|||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a shame we have to duplicate this code, should we have a SeachServiceClientBase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was think about the same - Will use this PR to do that
...search/azure-search-documents/azure/search/documents/_service/_search_service_client_base.py
Outdated
Show resolved
Hide resolved
…ice/_search_service_client_base.py
# type: (str, AzureKeyCredential, **Any) -> None | ||
|
||
try: | ||
if endpoint.lower().startswith('http') and not endpoint.lower().startswith('https'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity I would do it:
if not endpoint.lower().startswith('http'):
endpoint = "https://" + endpoint
elif not endpoint.lower().startswith('https'):
raise ValueError("Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.")
...search/azure-search-documents/azure/search/documents/_service/_search_service_client_base.py
Outdated
Show resolved
Hide resolved
…ice/_search_service_client_base.py
from ._indexes_client import SearchIndexesClient | ||
from ._indexers_client import SearchIndexersClient | ||
from ._skillsets_client import SearchSkillsetsClient | ||
from ._synonym_maps_client import SearchSynonymMapsClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't seem those imports are necessary here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is pylint passing? ⭕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed these - but im shocked to see pylint not catching unused-import
:end-before: [END create_search_service_with_key] | ||
:language: python | ||
:dedent: 4 | ||
:caption: Creating the SearchServiceClient with an API key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the snippet be on this base class that users will never use directly themselves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed these
elif not endpoint.lower().startswith('https'): | ||
raise ValueError("Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.") | ||
except AttributeError: | ||
raise ValueError("Endpoint must be a string.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could put this in a util function that has simple unit tests, then
self._endpoint = normalize_endpoint(endpoint)
below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
…into feature/text_analytics_v3.0 * 'master' of https://github.com/Azure/azure-sdk-for-python: (128 commits) add more content to index crud samples (#11443) Add a snippet to the Samples readme mirroring the core readme, guiding users to the currently mainline version of the lib if the end up on the wrong page. (#11420) 20200515 run resource live test (#11454) Release azure mgmt eventgrid (#11431) Smoke Tests use new workflow for package install (#11438) ServiceFabric 7.1 (#11451) update (#11424) Typing for appconfiguration (#11427) [form recognizer] Move `get_client` method from FormRecognizer -> FormTraining (#11423) release customvision (#11428) Enforce https in search (#11337) [Cosmos] Remove unused files (#11388) Sync eng/common directory with azure-sdk-tools repository (#11417) [form recognizer] consistency renames for FormTrainingClient (#11390) Release for azure mgmt eventhub (#11403) Network 2020 04 01 (#11405) link in to reference docs for sub-clients (#11396) Persistent caching for interactive credentials on Linux and macOS (#11319) [formrecognizer] add AAD auth support (#11275) Search docs/readme updates (#11391) ...
Fixes #10981
Case1: "xyz.search.windows.net"
Current Behavior: throws some random key error because it fails to parse in azure core
Changed to: "https://xyz.search.windows.net"
Case2: "https://xyz.search.windows.net"
No behavior changed - correct endpoint
Case3: "http://xyz.search.windows.net"
Behavior changed to raising value error and warn to use https
Case4: 1234 (non string)
Raises a value error