Skip to content

Conversation

@minsis
Copy link
Contributor

@minsis minsis commented Dec 13, 2021

Adding no_proxy option for index searches.

Fixes #5497

@pull-request-size pull-request-size bot added the size/XS PR that changes 0-9 lines. Quick fix/merge. label Dec 13, 2021
@CLAassistant
Copy link

CLAassistant commented Dec 13, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@arm4b arm4b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Can you also add the Changelog record for this enhancement?

@minsis
Copy link
Contributor Author

minsis commented Dec 16, 2021

@armab Updated

proxies_dict["http"] = http_proxy

if no_proxy:
proxies_dict["no"] = no_proxy
Copy link
Member

@arm4b arm4b Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minsis Did you test it BTW and can confirm no_proxy setting works this way via no key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swear this was working, but I guess not.

I'm pretty sure the no key is correct. I looked in the requests library and when building the proxy info it does a split. Hence the reason the other kyes are http and https.

Looking at the requests docs they never mention no_proxy, but its mentioned in a release note saying its supposed to be no_proxy.

Regardless no and no_proxy doesn't even seem to work at all. I tested this directly using the requests library.

Copy link
Contributor Author

@minsis minsis Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

psf/requests#4871

Looks like maybe this has been broken for quite some time. There's a PR to fix it, but its still open for 15 months.

I suppose we could implement some similar logic as PR?
psf/requests@063f2ae

Copy link
Member

@arm4b arm4b Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swear this was working, but I guess not.

I'm just asking.

I'm good to merge it if you say if the code change was tested manually and works in your environment.
If you can confirm this is 👍 and fixes your case, - just let me know in the PR as the requests doc is a bit confusing indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add no or no_proxy doesn't work unfortunately. So I guess back to square one.

My thought now is to maybe use the same logic the PR is using. Basically if it detects the URL being used is in no_proxy it will remove the proxy info from the request.

@arm4b arm4b removed this from the 3.7.0 milestone Jan 12, 2022
@pull-request-size pull-request-size bot added size/S PR that changes 10-29 lines. Very easy to review. and removed size/XS PR that changes 0-9 lines. Quick fix/merge. labels Feb 5, 2022
@pull-request-size pull-request-size bot added size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. and removed size/S PR that changes 10-29 lines. Very easy to review. labels Feb 5, 2022
@pull-request-size pull-request-size bot added size/S PR that changes 10-29 lines. Very easy to review. and removed size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. labels Feb 5, 2022
@minsis
Copy link
Contributor Author

minsis commented Feb 5, 2022

@armab I've done another commit to do similar to what the bug fix is supposed to provide from the requests library.

Could you also do me a favor and just double check my upstream merge. I get confused on dealing with merge conflicts and such.

@minsis
Copy link
Contributor Author

minsis commented Feb 7, 2022

@armab I also tested this and it works now.

@minsis minsis requested a review from arm4b February 18, 2022 00:29
@arm4b arm4b added this to the 3.7.0 milestone Mar 7, 2022
@minsis minsis requested a review from arm4b March 7, 2022 16:37
request = requests.get(
index_url,
proxies=proxies_dict if not bypass_proxy else None,
verify=verify if not bypass_proxy else True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
verify=verify if not bypass_proxy else True,
verify=verify,

I still don't understand why adjusting the verify logic is needed in this situation.
I thought we were trying to fix no_proxy.

Could you perhaps provide more context or an example?

Copy link
Contributor Author

@minsis minsis Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ca_bundle_path = proxy_config.get("proxy_ca_bundle_path", None)
if https_proxy:
proxies_dict["https"] = https_proxy
verify = ca_bundle_path or True

Because verify is overwritten with the path to your proxy's ca bundle if proxy_ca_bundle_path environment variable is set. Since its outside the loop there could be a chance where you are specifying a ca bundle path but needing to bypass the proxy.

An example might be (without verify if not bypass_proxy else True,):

proxy_config = {
    "https_proxy": "http://proxy.company.local",
    "http_proxy":  "http://proxy.company.local",
    "no_proxy": "company.local,localhost,my.other.domain",
    "proxy_ca_bundle_path": "/path/to/proxy/ca_bundle"
}

proxies_dict = {
    "https": "http://proxy.company.local",
    "http":  "http://proxy.company.local",
    "no": "company.local,localhost,my.other.domain",
}

# verify is now overwritten from True to '/path/to/proxy/ca_bundle'
verify="/path/to/proxy/ca_bundle"

Now we enter loop:

# Iteration 1
verify="/path/to/proxy/ca_bundle" # permanently set

index_url="https://index.stackstorm.com"
bypass_proxy = False

requests.get(
    "https://index.stackstorm.com",
    proxies={
        "https": "http://proxy.company.local",
        "http":  "http://proxy.company.local",
        "no": "company.local,localhost,my.other.domain",
    },
    verify="/path/to/proxy/ca_bundle",
)
# Iteration 2
verify="/path/to/proxy/ca_bundle" # permanently set

index_url="https://index.mycompany.local"
bypass_proxy = True

requests.get(
    "https://index.mycompany.local",
    proxies=None
    verify="/path/to/proxy/ca_bundle",
)

So in Iteration 2 we would might end up failing because we're still trying to use our proxy's ca bundle, but not using the proxy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now, thanks for more context 👍

Copy link
Member

@arm4b arm4b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution 👍
The change is marked for the upcoming v3.7.0 release.

Before that, if you can add a unit test for the new logic in packs.py, - that would be helpful as proxy behavior is highly inconsistent between the different tools.

@minsis
Copy link
Contributor Author

minsis commented Mar 10, 2022

I thought about writing a test earlier, but I'm not sure how I would write a test for this. I'm still learning on writing good unit and/or integration testing. This one is particular difficult in my mind because of the looping mechanism. Any suggestions?

Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests for this would be awesome. However, there are no unit tests for things that retrieve the pack index. Writing tests for all of these index functions would be much more involved than merely a test for the proxy config.

I'm going to merge this now. I'm satisfied with the manual testing for this fix.

@cognifloyd cognifloyd enabled auto-merge March 31, 2022 20:27
@cognifloyd cognifloyd merged commit ec8f33e into StackStorm:master Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement size/S PR that changes 10-29 lines. Very easy to review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no_proxy is not respected during index searches

4 participants