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

Openshift Client ignores NO_PROXY setting #4247

Closed
brubrz opened this issue Jul 4, 2022 · 4 comments · Fixed by #4305
Closed

Openshift Client ignores NO_PROXY setting #4247

brubrz opened this issue Jul 4, 2022 · 4 comments · Fixed by #4305
Assignees
Labels
Milestone

Comments

@brubrz
Copy link

brubrz commented Jul 4, 2022

Describe the bug

The ConfigBuilder ignores .withNoProxy() Setting. I must set the HttpProxy to null in order to connect to my PaaS.

Fabric8 Kubernetes Client version

6.0.0-RC1

Steps to reproduce

Does not work:

    Config config = new ConfigBuilder()
            .withNoProxy("*.my.domain.com") // does not work: Socket Exception: "read timed out"
            .build();


    try (final KubernetesClient client = new KubernetesClientBuilder().withConfig(config).build()) {

        System.out.println(Arrays.toString(config.getNoProxy()));
        System.out.println(client.getConfiguration().getCurrentContext().getName());
        System.out.println(config.getUsername());
        System.out.println(config.getOauthToken());


        client.pods().inNamespace("default").list().getItems().stream().map(pod -> pod.getMetadata().getName()).forEach(System.out::println);

Weird workaround that works:

    Config config = new ConfigBuilder()
            .withHttpProxy(null)
            .withHttpsProxy(null)
            .build();


    try (final KubernetesClient client = new KubernetesClientBuilder().withConfig(config).build()) {
        //client.authorization().v1().localSubjectAccessReview()

        System.out.println(Arrays.toString(config.getNoProxy()));
        System.out.println(client.getConfiguration().getCurrentContext().getName());
        System.out.println(config.getUsername());
        System.out.println(config.getOauthToken());


        client.pods().inNamespace("default").list().getItems().stream().map(pod -> pod.getMetadata().getName()).forEach(System.out::println);

Expected behavior

    Config config = new ConfigBuilder()
            .withNoProxy("*.my.domain.com")
            .build();

This should work / not be ignored.

Runtime

OpenShift

Kubernetes API Server version

other (please specify in additional context)

Environment

Windows

Fabric8 Kubernetes Client Logs

No response

Additional context

Kubernetes API Server version: v1.21.11+6b3cbdd

@shawkins
Copy link
Contributor

shawkins commented Jul 6, 2022

The implementation

does not expect wildcards for hosts. It does have some match logic for IPs.

@brubrz
Copy link
Author

brubrz commented Jul 6, 2022

In that case, I would really appreciate an error msg. It appears to me as if the code is passing an IP that could not be parsed along to another component to let it fail there? I think an unparsable proxy ip should result in an error that can be associated with the proxy configuration. If the unparsable proxy string is passed to the level of concern of http connections then ofc I get an error message that is related to that layer: "read timed out", but that makes it hard to find out what's actually wrong.

    URL master = new URL(config.getMasterUrl());
    String host = master.getHost();
    if (config.getNoProxy() != null) {
      for (String noProxy : config.getNoProxy()) {
        if (isIpAddress(noProxy)) {
          if (new IpAddressMatcher(noProxy).matches(host)) {
            return null;
          }
        } else {
          if (host.contains(noProxy)) {
            return null;
          }
         // the proxy string was not parsable                    <--------------------- 
        }
      }
    }

@shawkins
Copy link
Contributor

shawkins commented Jul 6, 2022

The biggest issue here is there's no docs defining the expected behavior.

As implemented it would read something like:

noProxy - a list of addresses of hosts for which using the proxy is disabled. If an IP address is specified, it may include subnet masks. If a host name is specified the proxy won't be used if that name appears anywhere in the requested host name - there is no support for wildcard matches.

In that case, I would really appreciate an error msg.

I think you mean checking for non-url characters, so in this case * would cause an exception.

That's a possibility. As would be supporting glob matching - that would be backwards compatible. Full regex would not. In any case I also wonder about using host.contains - searching anywhere in the host name doesn't seem quite right.

@rohanKanojia @manusa what do you vote for expected behavior here?

@shawkins shawkins added this to the 6.x milestone Jul 15, 2022
@manusa
Copy link
Member

manusa commented Jul 19, 2022

The NO_PROXY env var support was added in #209 to fix an issue with Fabric8 Maven Plugin (fabric8io/fabric8#5178).

The spec was taken from http://www.gnu.org/software/wget/manual/html_node/Proxies.html

no_proxy
This variable should contain a comma-separated list of domain extensions proxy should not be used for. For instance, if the value of no_proxy is ‘.mit.edu’, proxy will not be used to retrieve documents from MIT.

However, the GNU emacs spec does support wildcards https://www.gnu.org/software/emacs/manual/html_node/url/Proxies.html

The NO_PROXY environment variable specifies URLs that should be excluded from proxying (on servers that should be contacted directly). This should be a comma-separated list of hostnames, domain names, or a mixture of both. Asterisks can be used as wildcards, but other clients may not support that.

The one for OpenShift doesn't accept wildcard characters either.


Regarding the current implementation, I think it's fine and I wouldn't overcomplicate it.

However, I think that the line

if (host.contains(noProxy)) {

should be changed to

if (host.endsWith(noProxy)) {

or even something a little bit more involved that actually checks for subdomains if expressed as .example.com or not if expressed as example.com

I would really appreciate an error msg

so in this case * would cause an exception.

Yes, this would improve the usability.

@manusa manusa modified the milestones: 6.x, 6.1.0 Jul 19, 2022
@manusa manusa added the bug label Jul 19, 2022
@rohanKanojia rohanKanojia self-assigned this Jul 26, 2022
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jul 27, 2022
…abric8io#4247)

+ Modify NO_PROXY check to use `.endsWith` instead of `.contains` to
  better match host name.
+ Add a check to throw an Exception if any of NO_PROXY contains `*`

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jul 27, 2022
…abric8io#4247)

+ Modify NO_PROXY check to use `.endsWith` instead of `.contains` to
  better match host name.
+ Add a check to throw an Exception if any of NO_PROXY contains `*`

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jul 28, 2022
have `@EqualsAndHashCode(callSuper = true)` (fabric8io#4247)

CustomResource classes generated in extra-annotations mode by Java generator
should have `@EqualsAndHashCode` annotation configured with `callSuper = true` in
case class extends another class.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jul 28, 2022
…abric8io#4247)

+ Modify NO_PROXY check to use `.endsWith` instead of `.contains` to
  better match host name.
+ Add a check to throw an Exception if any of NO_PROXY contains `*`

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
manusa pushed a commit to rohanKanojia/kubernetes-client that referenced this issue Aug 4, 2022
…abric8io#4247)

+ Modify NO_PROXY check to use `.endsWith` instead of `.contains` to
  better match host name.
+ Add a check to throw an Exception if any of NO_PROXY contains `*`

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
@manusa manusa changed the title Openshift Client ignores no_proxy setting Openshift Client ignores NO_PROXY setting Aug 5, 2022
manusa pushed a commit that referenced this issue Aug 5, 2022
…4247)

+ Modify NO_PROXY check to use `.endsWith` instead of `.contains` to
  better match host name.
+ Add a check to throw an Exception if any of NO_PROXY contains `*`

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants