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

feat(gomod): use git host rules as authentication for gosum updates #12230

Merged
merged 20 commits into from Oct 31, 2021

Conversation

Shegox
Copy link
Contributor

@Shegox Shegox commented Oct 20, 2021

Changes:

This PR adds all known GitHub, GitLab (and tbd) credentials it can find in the host rules as Git Environment variables for the gosum update as outlined in #7361 (comment)

  • The list of registries to provide authentation from should not be derived from registryUrls
  • Instead, the list should come from hostRules
  • Host rules could have hostType=go but we should probably also automatically do any with hostType=github too, maybe also hostType=gitlab?
  • Need to think about if we need to distinguish between api.github.com and github.com
  • Need to be clear that it relates to artifacts updating (go.sum, vendored modules, etc) and not to Renovate's own lookup phase

As of today it looks for all hostRules matching GitHub and GitLab. A custom hostType=go is not yet supported (but would be only 3 more lines). It currently uses hostRule.matchHost to construct the GitUrl it should use the credentials for. This allows it to use paths as well.

Open Topics/Questions:

  • Should we add a custom hostType=go for it? // not for now
  • Should we support all the other git platforms out of the box as well (bitbucket, gittea)? Is there a generic hosttype git I can use? // yes all platform + without hostType
  • Should we use hostRule.matchHost (supports paths) or hostRule.resolvedHost and construct the http(s) url from there? // hostRule.matchHost

To be done:

  • Docs needs to be updated
  • Run against a real repository

Context:

fixes #7361
follow up to #11077

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please tick one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@Shegox Shegox mentioned this pull request Oct 20, 2021
@Shegox Shegox changed the title feat(gomod): use git host rules as authentication for gosum updates **DO NOT MERGE YET** feat(gomod): use git host rules as authentication for gosum updates Oct 21, 2021
@Shegox Shegox marked this pull request as ready for review October 21, 2021 10:29
@Shegox
Copy link
Contributor Author

Shegox commented Oct 21, 2021

@rarkins I still have to update the docs and do some further testing with some of my own repositories, but if you have time I would like to ask you if you can please take already a look at the implementation and see if that is what you imagined. Many thanks in advance.

@rarkins rarkins marked this pull request as draft October 21, 2021 11:08
Copy link
Collaborator

@rarkins rarkins left a comment

Choose a reason for hiding this comment

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

Some questions:

  • Is there any harm in adding all hosts, even if they have nothing to do with Go (e.g. could be a Rubygems registry)?
  • Do we need to be "platform aware" (e.g. github, gitlab, etc) or if we do all hosts then will we have enough rules in place anyway?

lib/manager/gomod/artifacts.ts Outdated Show resolved Hide resolved
@viceice viceice changed the title **DO NOT MERGE YET** feat(gomod): use git host rules as authentication for gosum updates feat(gomod): use git host rules as authentication for gosum updates Oct 21, 2021
lib/util/host-rules.ts Outdated Show resolved Hide resolved
@Shegox
Copy link
Contributor Author

Shegox commented Oct 22, 2021

Is there any harm in adding all hosts, even if they have nothing to do with Go (e.g. could be a Rubygems registry)?
Not really as long as the hostname don't overlap. E.g.:

        {
            "matchHost": "github.enterprise.com",
            "token": "invalid"
        },
        {
            "matchHost": "github.enterprise.com/test",
            "token": "token"
        },

Might cause problems when accessing go modules under github.enterprise.com/test. I think however this is a very rare problem.

Do we need to be "platform aware" (e.g. github, gitlab, etc) or if we do all hosts then will we have enough rules in place anyway?

At the end of the day go get -d only uses git, so we don't need to be platform aware in any way as long as git clone works against the system. (There are other supported platform for go get as well, but git should be the majority).

@rarkins
Copy link
Collaborator

rarkins commented Oct 22, 2021

Not really as long as the hostname don't overlap. E.g.:

We could perhaps do an intelligent de-duplication to avoid that problem?

@Shegox
Copy link
Contributor Author

Shegox commented Oct 22, 2021

I just tested it again and I had an error in my previous testing (the github.enterprise.com with invalid) token affected other things as well causing problems.
Using works as expected. Even through the rule for github.enterprise.com is added to Git the other more precise hostname overrules it github.enterprise.com/test.

        {
            "matchHost": "github.enterprise.com",
            "token": "invalid",
            "hostType":"npm"
        },
        {
            "matchHost": "github.enterprise.com/test",
            "token": "token"
        },

I think this should be generally fine. The only other option I see would be to narrow it down to the 6 Git Platforms that are supported plus rules without hostType.

@viceice
Copy link
Member

viceice commented Oct 22, 2021

i think we should only use specific known host types plus new gomod for custom unknown hosts

@rarkins
Copy link
Collaborator

rarkins commented Oct 22, 2021

So known git platforms only?

@Shegox
Copy link
Contributor Author

Shegox commented Oct 22, 2021

I would suggest, in this order

  1. Known git-platforms (github, gitlab, azure devops, bitbucket, gittea)
  2. A generic new git type (maybe?)
  3. Rules without hostType

And adding it only if it is a different matchHost as an additional GIT_CONFIG.

        {
            "matchHost": "github.enterprise.com/test",
            "token": "token",
            "hostType":"github"
        },
        {
            "matchHost": "github.enterprise.com/test",
            "token": "invalid"
        },

Should result it token being token.

@rarkins
Copy link
Collaborator

rarkins commented Oct 23, 2021

This could be useful for more managers than just gomod, too

@Shegox Shegox mentioned this pull request Oct 27, 2021
6 tasks
@Shegox Shegox marked this pull request as ready for review October 28, 2021 08:10
docs/usage/golang.md Show resolved Hide resolved
docs/usage/golang.md Outdated Show resolved Hide resolved
docs/usage/golang.md Outdated Show resolved Hide resolved
lib/manager/gomod/artifacts.ts Outdated Show resolved Hide resolved
lib/manager/gomod/artifacts.ts Outdated Show resolved Hide resolved
lib/manager/gomod/artifacts.spec.ts Outdated Show resolved Hide resolved
lib/manager/gomod/artifacts.spec.ts Outdated Show resolved Hide resolved
lib/manager/gomod/artifacts.spec.ts Outdated Show resolved Hide resolved
lib/manager/gomod/artifacts.spec.ts Outdated Show resolved Hide resolved
lib/manager/gomod/artifacts.spec.ts Outdated Show resolved Hide resolved
@rarkins rarkins marked this pull request as draft October 28, 2021 09:11
@Shegox Shegox marked this pull request as ready for review October 28, 2021 10:07
@Shegox Shegox requested a review from rarkins October 28, 2021 10:13
docs/usage/golang.md Outdated Show resolved Hide resolved
docs/usage/golang.md Show resolved Hide resolved
lib/util/url.ts Show resolved Hide resolved
@rarkins rarkins enabled auto-merge (squash) October 31, 2021 06:50
@rarkins rarkins merged commit 87c5e8e into renovatebot:main Oct 31, 2021
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 28.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve go private auth
4 participants