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(manager/composer): support git-tags hostRules for github.com when updating artifacts #18004

Merged
merged 26 commits into from Jan 13, 2023

Conversation

etremblay
Copy link
Contributor

@etremblay etremblay commented Sep 27, 2022

Changes

Take 2 of #16193 considering

When generating the COMPOSER_AUTH json, handle special case for github host rule.

"hostRules": [
    {
      "hostType": "git-tags", 
      "matchHost": "github.com",
      "encrypted": {
        "token": "GitHub Personal Access Token"
      }
    },
]

Context

We cannot use the github hostType because it break the update of the dependancy dashboard.

Also, I found that git-tags hostRules where used when doing dependancy lookup so this fix everything related to private github php repositorie

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

@rarkins rarkins requested a review from viceice October 3, 2022 05:13
@chrillep
Copy link

chrillep commented Oct 5, 2022

ping :) . artifacts failing.
resolving it by manually running docker container with auth.json then pushing lock file

ps. using github app

@rarkins
Copy link
Collaborator

rarkins commented Oct 5, 2022

Do we know for sure what caused it to fail for others last time, and therefore we can be confident that we're avoiding the problem this time?

@etremblay
Copy link
Contributor Author

Do we know for sure what caused it to fail for others last time, and therefore we can be confident that we're avoiding the problem this time?

Am afraid it's difficult to know for shure.

The code modified 3 things

  1. Understand hostRules with the git-tags hostType and add it in composer auth.json

Users in #17778 did not mention having such rules. For this to be an issue they would need to hava a broken token in a git-tags host rule and it's not very likely.

  1. We removed the .replace('x-access-token:', '')

This is what I fix here. What I understood form @viceice comment is that x-access-token is possibly added in Github App installations.

  1. We accept only tokens that begins with the ghp_ prefix

We added this condition because github now only accept personnal access token

Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

Maybe these users have a github installation that still accept non-personnal access token. We can remove this check to improve our chances of not doing a breaking change.

Note that if it's the case, they will probably eventually have to update their tokens for PAT enventually anyway.

@rarkins
Copy link
Collaborator

rarkins commented Oct 5, 2022

  1. We removed the .replace('x-access-token:', '')

This is what I fix here. What I understood form @viceice comment is that x-access-token is possibly added in Github App installations.

This could be the problem

  1. We accept only tokens that begins with the ghp_ prefix

We added this condition because github now only accept personnal access token

This could also be the problem. The app uses ghs_ tokens (designates an "app" token). Can we skip the check altogether?

@etremblay
Copy link
Contributor Author

  1. We removed the .replace('x-access-token:', '')

This is what I fix here. What I understood form @viceice comment is that x-access-token is possibly added in Github App installations.

This could be the problem

  1. We accept only tokens that begins with the ghp_ prefix

We added this condition because github now only accept personnal access token

This could also be the problem. The app uses ghs_ tokens (designates an "app" token). Can we skip the check altogether?

Yes we can skip the check and the fix will still work for us. If you set a bad token in your hostRule composer will just fail.

I removed the check but kept the documentation saying you should user a PAT.

@viceice
Copy link
Member

viceice commented Oct 5, 2022

what about add a debug message when it's not. a pat or app token?

@etremblay
Copy link
Contributor Author

what about add a debug message when it's not. a pat or app token?

Good idea, I improved the personal access token logic to prefer ghp_ tokens but still use any token available if no ghp_ is set. In that case I log a debug.

725ee94

chrillep
chrillep previously approved these changes Oct 14, 2022
Copy link

@chrillep chrillep left a comment

Choose a reason for hiding this comment

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

i approve :)

@chrillep
Copy link

chrillep commented Oct 15, 2022

BTW does having in no-api in composer.json for your private repo have any effect on this issue?

https://getcomposer.org/doc/05-repositories.md#git-alternatives

If you set the no-api key to true on a github repository it will clone the repository as it would with any other git repository instead of using the GitHub API. But unlike using the git driver directly, Composer will still attempt to use github's zip files.

@etremblay
Copy link
Contributor Author

BTW does having in no-api in composer.json for your private repo have any effect on this issue?

https://getcomposer.org/doc/05-repositories.md#git-alternatives

If you set the no-api key to true on a github repository it will clone the repository as it would with any other git repository instead of using the GitHub API. But unlike using the git driver directly, Composer will still attempt to use github's zip files.

Before all this, most of our private repositories had the noapi + type=github and we had the "Support for password authentication was removed" error. Moreover renovate could not list dependencies versions.

Now all our repos use type=vcs + https url ans renovate is able to fetch dependency versions and generate pull request. The only problem is with the composer artifact update (done by composer itself not the renovate codebase). That's what this pull request fix.

@chrillep
Copy link

BTW does having in no-api in composer.json for your private repo have any effect on this issue?
https://getcomposer.org/doc/05-repositories.md#git-alternatives

If you set the no-api key to true on a github repository it will clone the repository as it would with any other git repository instead of using the GitHub API. But unlike using the git driver directly, Composer will still attempt to use github's zip files.

Before all this, most of our private repositories had the noapi + type=github and we had the "Support for password authentication was removed" error. Moreover renovate could not list dependencies versions.

Now all our repos use type=vcs + https url ans renovate is able to fetch dependency versions and generate pull request. The only problem is with the composer artifact update (done by composer itself not the renovate codebase). That's what this pull request fix.

@etremblay alright we use vcs and no-api.

and also thanks for creating the PR.

@viceice
Copy link
Member

viceice commented Oct 19, 2022

we probably also need to handle the new PAT type soon

https://github.blog/2022-10-18-introducing-fine-grained-personal-access-tokens-for-github/

@etremblay
Copy link
Contributor Author

we probably also need to handle the new PAT type soon

https://github.blog/2022-10-18-introducing-fine-grained-personal-access-tokens-for-github/

Indeed. With this version of the code we would only log a debug saying it's not a PAT.

I just generated a token and it's prefixed by github_pat_. I could update this pr to handle it like a ghp

lib/modules/manager/composer/artifacts.ts Outdated Show resolved Hide resolved
lib/modules/manager/composer/utils.ts Show resolved Hide resolved
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
@etremblay
Copy link
Contributor Author

Updated with master and fixed code coverage

@viceice viceice changed the title feat(manager/composer): support git-tags hostRules for github.com when updating artifacts take2 feat(manager/composer): support git-tags hostRules for github.com when updating artifacts Dec 30, 2022
@haridarshan21
Copy link

Any update, by when can we except this released?

@rarkins
Copy link
Collaborator

rarkins commented Jan 12, 2023

Needs conflict resolution

@etremblay
Copy link
Contributor Author

Needs conflict resolution

Fixed

rarkins
rarkins previously approved these changes Jan 12, 2023
@rarkins rarkins requested a review from viceice January 12, 2023 14:54
lib/modules/manager/composer/utils.ts Outdated Show resolved Hide resolved
lib/modules/manager/composer/artifacts.ts Outdated Show resolved Hide resolved
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

see regex issue

@viceice viceice requested a review from rarkins January 13, 2023 06:05
@rarkins rarkins enabled auto-merge (squash) January 13, 2023 08:45
@rarkins
Copy link
Collaborator

rarkins commented Jan 13, 2023

This branch should automerge the next time it (a) is up to date with main branch, and (b) has passed all tests

@rarkins rarkins merged commit e8a5437 into renovatebot:main Jan 13, 2023
@etremblay etremblay deleted the composer-private-repos-take2 branch January 13, 2023 13:34
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 34.101.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2023
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.

Composer private repositories not working
8 participants