Skip to content

gh cli does not consider no_proxy #5244

Closed

Description

@sergeiwaigant

Describe the bug

We face issues within a corporate network when trying to use gh cli with two GitHub instances - one hosted in Cloud, one hosted on-premises.
The problem occurs, when setting the HTTP_PROXY / HTTPS_PROXY / NO_PROXY environment variable to point to the corporate internet proxy.
gh cli is considering the proxy setting when connecting to the Cloud hosted GHES, but not considering the NO_PROXY when connecting to the on-premises one.

$ gh --version
gh version 2.5.1 (2022-02-15)

Steps to reproduce the behavior

  1. Type this '...'
export HTTP_PROXY=proxy.corp.internal:81
export NO_PROXY=.internal
gh auth login --hostname github.corporate.com # this works fine
gh auth login --hostname github.corp.internal # this fails due to attempt to connect through the proxy
  1. View the output '....'
## see above
  1. See error
gh auth login --hostname github.corp.internal

failed to authenticate via web browser: Post "https://github.corp.internal/login/device/cde": authenticationrequired

Expected vs actual behavior

gh cli should consider the NO_PROXY / no_proxy environment variable and skip the internet proxy when connecting to local GHES endpoints.

Activity

  1. added
    discussFeature changes that require discussion primarily among the GitHub CLI team
    enhancementa request to improve CLI
    and removed
    bugSomething isn't working
    on Feb 24, 2022
  2. samcoe commented on Feb 24, 2022

    @samcoe
    Contributor

    Ref. #2037

  3. sergeiwaigant commented on Feb 24, 2022

    @sergeiwaigant
    Author

    There is a "workaround" by just giving HTTP_PROXY="" in front of the gh execution when connecting to the github.corp.internal, just like...

    export HTTP_PROXY=proxy.corp.internal:81
    export NO_PROXY=.internal
    gh auth login --hostname github.corporate.com
    HTTP_PROXY="" gh auth login --hostname github.corp.internal
    
  4. vilmibm commented on Mar 2, 2022

    @vilmibm
    Contributor

    Hi,

    gh doesn't natively handle any of these environment variables -- they are consumed by Go's http connection code. We can at least document these variables in our manual, but we prefer to defer to Go's networking code here and do not intend to add our own proxy handling code to gh.

    Going to close this for now, but feel free to use this issue for documenting further workarounds.

  5. sergeiwaigant commented on Mar 3, 2022

    @sergeiwaigant
    Author

    ok, found my problem... my bad.
    there are multiple internal domains in the corporate network and for other tools it was fine to give it space separated as:

    NO_PROXY=".dev.corp .preprod.corp .prod.corp"

    For gh I had to add just a comma in between as:

    NO_PROXY=".dev.corp, .preprod.corp, .prod.corp"

    The reference to Go's http connection code helped a lot - thank you!
    https://pkg.go.dev/golang.org/x/net/http/httpproxy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussFeature changes that require discussion primarily among the GitHub CLI teamenhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions