FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: skip permission verification exception when Github Apps by psalaberria002 · Pull Request #272 · semantic-release/github · GitHub

fix: skip permission verification exception when Github Apps - #272

Merged
gr2m merged 1 commit into
semantic-release:masterfrom
psalaberria002:patch-1
May 22, 2020
Merged

fix: skip permission verification exception when Github Apps#272
gr2m merged 1 commit into
semantic-release:masterfrom
psalaberria002:patch-1

Conversation

psalaberria002 commented May 19, 2020
edited by hearts Bot
Loading

Copy link
Copy Markdown
Contributor

Similar to Github Actions, when using installation tokens from Github Apps the verification should be skipped.

Should we use a more generic flag for skipping the permission validation? e.g. SKIP_PERMISSIONS?

I will add the relevant docs to the Readme once I get the ok.

psalaberria002 changed the title Skip permission verification when using Github Apps fix: skip permission verification when using Github Apps May 19, 2020
Comment thread lib/verify.js Outdated
// github.repos.get({repo, owner}) does not return the "permissions" key in that case. But GitHub Actions and Apps
// have all permissions required for @semantic-release/github to work
if (env.GITHUB_ACTION) {
if (env.GITHUB_ACTION || env.GITHUB_APP) {

gr2m May 19, 2020
edited by hearts Bot
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

where does the GITHUB_APP environment variable come from? If it's a custom environment variable that you set in your particular case, then I don't think we should add a check for it to semantic-release

gr2m commented May 19, 2020
edited by hearts Bot
Loading

Copy link
Copy Markdown
Member

Can you share your semantic-release setup? I wonder how you create an installation access token and pass it to semantic release :)

psalaberria002 commented May 19, 2020
edited by hearts Bot
Loading

Copy link
Copy Markdown
Contributor Author

This is running in Jenkins with the new auth method for the Github plugin. See https://www.jenkins.io/blog/2020/04/16/github-app-authentication/

Example:

withCredentials([usernamePassword(credentialsId: scm.userRemoteConfigs[0].credentialsId, passwordVariable: 'GH_TOKEN', usernameVariable: 'GH_USER')]) {
              sh("GH_TOKEN=${GH_TOKEN} npx semantic-release")
            }

Github Apps create installation tokens the same way Github Actions do. These tokens have short expiration time.

The flag will need to be provided as an extra environment variable. Something like the following:

withCredentials([usernamePassword(credentialsId: scm.userRemoteConfigs[0].credentialsId, passwordVariable: 'GH_TOKEN', usernameVariable: 'GH_USER')]) {
              sh("SKIP_PERMISSION_VERIFICATION="true" GH_TOKEN=${GH_TOKEN} npx semantic-release")
            }

Github Apps have lots of advantages over personal access tokens. Higher rate limits, scopes permissions,...

gr2m commented May 19, 2020
edited by hearts Bot
Loading

Copy link
Copy Markdown
Member

Is see.

I wish there was a way to check if the current installation has access and the required permissions, but I don't think there is right now.

I suggest to add a skipVerify option to address your use case. Would that work for you?

psalaberria002 commented May 20, 2020
edited by hearts Bot
Loading

Copy link
Copy Markdown
Contributor Author

That should work. I will try to add that flag.

gr2m commented May 20, 2020
edited by hearts Bot
Loading

Copy link
Copy Markdown
Member

Good point, I think we shouldn't skip all the verifications, only the permissions verifications 🤔

I have another idea. We could send a request that is guaranteed to succeed when authenticated as an installation, but fail otherwise. I would suggest we send a HEAD /installation/repositories. We are only interested in the response status, and sending a HEAD is faster than a GET.

What I would like to try is the following:

If push is false here, send the following request

// If authenticated as GitHub App installation, `push` will always be false.
// We send another request to check if current authentication is an installation.
// Note: we cannot check if the installation has all required permissions, it's
// up to the user to make sure it has
if (await github.request('HEAD /installation/repositories', { per_page: 1 }).catch(() => return false) {
  return
}

I think I'd prefer doing that check to address your specific use case, over adding a new configuration option. What do you think?

For testing: HEAD /installation/repositories responds with a 200 status without a body if it succeeds, and with a 403 status if it fails

psalaberria002 changed the title fix: skip permission verification when using Github Apps fix: skip permission verification exception when Github Apps May 22, 2020

gr2m left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

looks good 👍

gr2m merged commit 32654fb into semantic-release:master May 22, 2020

semantic-release-bot commented May 22, 2020
edited by hearts Bot
Loading

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 7.0.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

psalaberria002 commented May 25, 2020
edited by hearts Bot
Loading

Copy link
Copy Markdown
Contributor Author

@gr2m I don't think this is working as expected. "Accept: application/vnd.github.machine-man-preview+json" is needed in installation/repositories. How do you handle that?

psalaberria002 commented May 25, 2020
edited by hearts Bot
Loading

Copy link
Copy Markdown
Contributor Author

And there is an issue in the semantic-release repo aswell, which needs to be solved like semantic-release/semantic-release@cb2c506

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL