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

[EventHubs] Custom ssl certificate support when using http proxy #16304

Closed
yunhaoling opened this issue Jan 22, 2021 · 6 comments
Closed

[EventHubs] Custom ssl certificate support when using http proxy #16304

yunhaoling opened this issue Jan 22, 2021 · 6 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Event Hubs Messaging Messaging crew Service Bus uAMQP
Milestone

Comments

@yunhaoling
Copy link
Contributor

yunhaoling commented Jan 22, 2021

Summary

EventHub allows connecting to the service via http proxy.
Currently we expose http proxy setting including:

proxy_hostname (str)
proxy_port (int)
username (str)
password (str)

However, there're scenarios:

  • the http proxy server has its own Server SSL certificate -- when the client wants to build tls connection to the http proxy, a custom certificate is required for authenticating the identity of the proxy server.
  • Apart from the server certificate, there is also Client SSL certificate which is used by the server to authenticate the identity of a client.

We would like to provide the ability to set server/client certificate in EventHub Python SDK for authenticating the identity of the proxy server/client when connection to the service via a http proxy.

Scope of work

  • Client accepts server SSL certificate and uses the certificate (path to the CA_BUNDLE file) in the case of http proxy usage for authenticating the identity of the proxy server when building tls connection.
    • (?) certificate ignored if there's no proxy setting
  • Client accepts client SSL certificate and uses the certificate in the case of http proxy usage for authenticating the identity of the client when building tls connection.
    • (?) certificate ignored if there's no proxy setting
  • The surface should align with the azure-core on exposing the certificate settings at the top-level client

Success Criteria

  • The server ssl certificate and client certificate is supported/implemented in the underlying uamqp library
  • clients accept ssl certificate and client certificate could connect to the service via http proxy which requires the certificates.

Samples

http_proxy = {
proxy_hostname (str)
proxy_port (int)
username (str)
password (str)
connection_verify: path the server certificate CA_BUNDLE file
connection_cert: path to the client side certificate CA_BUNDLE file or (key, certificate pair?)
}

References

Python request ssl cert
Python request client cert

@yunhaoling yunhaoling added Event Hubs Client This issue points to a problem in the data-plane of the library. labels Jan 22, 2021
@yunhaoling yunhaoling added this to the [2021] March milestone Jan 22, 2021
@yunhaoling yunhaoling self-assigned this Jan 22, 2021
@yunhaoling yunhaoling changed the title [EventHubs] Custom certificate support http proxy [EventHubs] Custom certificate support when using http proxy Jan 22, 2021
@yunhaoling
Copy link
Contributor Author

yunhaoling commented Jan 22, 2021

action items:

  • investigate the "verify" feature in uamqp auth and test setting the server certificate to connect to http proxy server
  • investigate the client side certification in uamqp-c library
    • whether setting client side cert is supported or not

issue opened in the azure-c-shared-utility repo asking for the certificate support: Azure/azure-c-shared-utility#501
PR for tls http proxy: Azure/azure-c-shared-utility#512

issue about the client-side certificate: Azure/azure-c-shared-utility#513

api proposal for the c lib: https://gist.github.com/yunhaoling/753677c4ee8137f50da38402c6646595

@yunhaoling yunhaoling changed the title [EventHubs] Custom certificate support when using http proxy [EventHubs] Custom ssl certificate support when using http proxy Jan 27, 2021
@fulii
Copy link

fulii commented Mar 2, 2021

Hi!

I would really like this to happen.
Currently we cannot use azure service bus because our proxy server has a custom certificate.
I cannot see any workaround at the moment how to bypass this, i spent hours to figure out.
Aslo from uamqp library side there is not much information about bad certificate.
If this happens in march that is really great, until then do you have any workaround?

@yunhaoling
Copy link
Contributor Author

yunhaoling commented Mar 9, 2021

hey @fulii,

I'm sorry to tell you that the currently the underlying C networking implementation for http proxy only supports basic auth (username and password) and we could do nothing until the support is being added into the C library first so that our uamqp library could take advantage of the feature and expose the settings to the upper layer.

I'll continue my work on adding support to the C library this month, but I can't guarantee you the timeline.

@yunhaoling
Copy link
Contributor Author

yunhaoling commented May 5, 2021

uamqp PR: Azure/azure-uamqp-python#232

prototype is available here: https://github.com/yunhaoling/uamqp-tls-proxy-prototype

event hub API proposal is here: https://gist.github.com/yunhaoling/720e8bea2cdd06cdf94515c7e31dd266

API shape in requests:

https://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification
https://docs.python-requests.org/en/latest/user/advanced/#client-side-certificates

source code: https://github.com/psf/requests/blob/master/requests/api.py#L16-L47
certificates related api shape:

'''
    :param verify: (optional) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use. Defaults to ``True``.
    :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.

sample:
'''python
requests.get('https://kennethreitz.org', verify='/path/to/certfile', cert=('/path/client.cert', '/path/client.key'))

API shape in httpx:

https://www.python-httpx.org/advanced/#ssl-certificates
https://www.python-httpx.org/advanced/#client-side-certificates

source code:
on requests: https://github.com/encode/httpx/blob/master/httpx/_api.py#L70-L77
on client: https://github.com/encode/httpx/blob/master/httpx/_client.py#L575-L582
certificates related api:

    * **verify** - *(optional)* SSL certificates (a.k.a CA bundle) used to
    verify the identity of requested hosts. Either `True` (default CA bundle),
    a path to an SSL certificate file, an `ssl.SSLContext`, or `False`
    (which will disable verification).
    * **cert** - *(optional)* An SSL certificate used by the requested host
    to authenticate the client. Either a path to an SSL certificate file, or
    two-tuple of (certificate file, key file), or a three-tuple of (certificate
    file, key file, password).

sample:

# verify/server certificates
import httpx
r = httpx.get("https://example.org", verify="path/to/client.pem")
# or pass a ssl context
import ssl
import httpx
context = ssl.create_default_context()
context.load_verify_locations(cafile="/tmp/client.pem")
# context = httpx.create_ssl_context(verify="/tmp/client.pem")
httpx.get('https://example.org', verify=context)
# or client side
client = httpx.Client(verify=False)
# client side certificates
import httpx

r = httpx.get("https://example.org", cert="path/to/client.pem")
# tuple
cert = ("path/to/client.pem", "path/to/client.key")
# cert = ("path/to/client.pem", "path/to/client.key", "password")
httpx.get("https://example.org", cert=cert)

@lmazuel lmazuel modified the milestones: [2021] May, [2021] June May 19, 2021
@yunhaoling
Copy link
Contributor Author

yunhaoling commented May 21, 2021

hey @fulii , apologize for not getting back to you sooner.

I have tried to implement the feature in the uamqp library based on my understanding.
I would like to invite you to try out my implementation to see if it works for your scenario -- uamqp wheels for linux and samples for service bus sdk could be found here: https://github.com/yunhaoling/uamqp-tls-proxy-prototype.

please let me know if you need help on testing it out, your feedbacks on the API are also welcomed!

(if you're working on Windows or macOS, I could manually build wheels for you as well)

@yunhaoling yunhaoling modified the milestones: [2021] June, Backlog Jun 14, 2021
@yunhaoling yunhaoling removed the P0 label Aug 17, 2021
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-python that referenced this issue Dec 9, 2021
Microsoft.SecurityInsights 2021-09-01-preview (Azure#16933)

* Adds base for updating Microsoft.SecurityInsights from version preview/2021-03-01-preview to version 2021-09-01-preview

* Updates readme

* Updates API version in new specs and examples

* Microsoft.security insights 2021 09 01 preview add missing resources (Azure#15531)

* Copy missing resources specs and examples from 2019-01-01-preview

* Update added resources specs and examples and extract common types

* Update readme

* Extract ClientInfo, UserInfo and Lable to common types

* Fix SpellCheck and Avocado

* Return ThreatIntelligence to readme

* Fix broken refs in Watchlists

* Resolve duplicate schema errors

* Run prettier

* Make common types prettier

* Add required property to operations according to ARM requirments

* Fix readme

* Add file separators to readme

* Rename example file

* Supress OBJECT_ADDITIONAL_PROPERTIES

* Add 'where' to OBJECT_ADDITIONAL_PROPERTIES supression

* Move OBJECT_ADDITIONAL_PROPERTIES supression under general Supression section.

* Copy dataConnectors from 2021-03-01-preview

* Update version of dataConnectors (this was done as there were errors when trying to generate C# client. Copying and changing version again fixed the problem).

* Add dataConnectorsCheckRequirments path, parameters and definitions from 2019-01-01-preveiw

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Use newest common types in new 2021-09-01-preview API version (Azure#15778)

* Use newest common types in AlertRules

* Use newest common types in AutomationRules

* Use newest common types in Bookmarks

* Use newest common types in dataConnectors

* Use newest common types in Enrichment

* Use newest common types in Entities

* Use newest common types in EntityQueries

* Use newest common types in Incidents

* Use newest common types in Metadata

* Use newest common types in OfficeConsents

* Use newest common types in OnboardingStates

* Use newest common types in operations

* Use newest common types in Settings

* Use newest common types in SourceControls

* Use newest common types in ThreatIntelligence

* Use newest common types in Watchlist

* Use newest common types in EntityTypes

* Use newest common types in RelationTypes

* Fix ThreatIntelligence

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Add template version to the scheduled alert rule + scheduled template (Azure#15919)

* Add template version to the scheduled alert rule

* Update AlertRules.json

* Update AlertRules.json

* Update AlertRules.json

* Update AlertRules.json

* Update GetAlertRuleTemplates.json

* Update GetAlertRuleTemplateById.json

* add aws s3 connector (Azure#15844)

* Add a new kind of alert rules - NRT (Azure#15980)

* add NRT rule

* add NRT rule

* add NRT rule

* add NRT rule

* fix typo

* fix typo

* fix

* Align new Metadata feature with 2021-03-01-preview (Azure#16304)

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Add fixes from 2021-03-01-preview (Azure#16238)

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Add entity query templates (Azure#16269)

* Add entity query templates from 2021-03-01-preview

* Update version

* Use newest common types and update readme

* Fix conflicting common types

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Fix bookmark relations operatinIds to be consistent with other operationIds. (Azure#16519)

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Add corrections from 2021-03-01-preview (Azure#16490)

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Remove unused parameters (Azure#16619)

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Update readme default readme tag for client generation (Azure#16620)

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Use CloudError instead of ErrorResponse to avoid breaking change (Azure#16691)

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Add data connectors polling ccp api support (Azure#16293)

* adding dataConnectors polling CCP api Support. (witout tests validations)

* azure sentinel dataconnectors update examples

* azure sentinel dataConnectors examples update and fix

* azure sentinel dataConnectors prettier

* azure sentinel dataConnectors add connect disconnect examples update path

* azure sentinel dataConnectors add connect disconnect examples fix

* azure sentinel dataConnectors add connect disconnect examples fix 2

* azure sentinel dataConnectors rebase dataConnectors dev

* azure sentinel dataconnectors - fix put to post on connect and disconnect endpoints

* azure sentinel dataconnectors - adding x-ms-secret to password on connect

* azure sentinel dataconnectors - connect/disconnect endpoint remove unnedded 201 return

* azure sentinel dataConnectors - remove empty body DataConnectorDisconnectBody

Co-authored-by: Alon Danoch <adanoch@microsoft.com>

* Add office IRM Connector (Azure#16764)

* Add office IRM

* fix

* fix

* fix

* fix

Co-authored-by: omerhaimov <omer.haimovich@gmail.com>

* Add teamInformation to IncidentProperties 2021-09-01-preview (Azure#16787)

* Fix Swagger for SecurityInsights - Add teamInformation to IncidentProperties

* Try change description as advised by Swagger reviewer Yuchao Yan to fix the validation error.

* Revert change in ntDomain description as it has nothing to do with validations

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Make CloudError and CloudErrorBody external resources (already exist under Microsoft.Rest.Azure namespace) (Azure#16872)

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Remove operational insights parameter 2021 09 01 preview (Azure#16891)

* Remove operationalInsightsResourceProvider parameter from specs

* Remove parameter from examples

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>

* Update EntityTypes.json (Azure#16972)

Co-authored-by: Anat Gilenson <anatgilenson@microsoft.com>
Co-authored-by: Amit Bergman <38046493+Amitbergman@users.noreply.github.com>
Co-authored-by: sagamzu <52034287+sagamzu@users.noreply.github.com>
Co-authored-by: necoh <53861229+necoh@users.noreply.github.com>
Co-authored-by: alondanoch <alondanoch@hotmail.com>
Co-authored-by: Alon Danoch <adanoch@microsoft.com>
Co-authored-by: omerhaimov <55688621+omerhaimov@users.noreply.github.com>
Co-authored-by: omerhaimov <omer.haimovich@gmail.com>
Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
@yunhaoling
Copy link
Contributor Author

closing the issue as there's no active development plan for it.
besides we heard no feedback from the community.

Please create a new issue if you feel this is the feature you need, and we could discuss.

@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
Client This issue points to a problem in the data-plane of the library. Event Hubs Messaging Messaging crew Service Bus uAMQP
Projects
None yet
Development

No branches or pull requests

3 participants