Skip to content

Missing auth scope when using gh pr update-branch on a cross-repo PR #9380

Open

Description

@babakks

Describe the bug

I was trying to run gh pr update-branch on a PR I've submitted to the current repo cli/cli but I got this error message:

GraphQL: refusing to allow an OAuth App to create or update workflow `.github/workflows/lint.yml` without `workflow` scope (updatePullRequestBranch)

When I refreshed my auth scopes with gh auth refresh --scopes workflow, it worked.

Please correct me if I'm wrong to jumping to conclusion too fast, but I think we should either:

  • Add the workflow scope to minimum scopes. This seems like the easiest solution because the user doesn't have to do some extra steps, but could also be considered against the minimum access policy.
  • Detect this specific error and instruct the user to refresh their token with the required scope. We also might want to include this in the gh pr update-branch command docs. The same approach has been implemented here and here.

Steps to reproduce the behavior

I'm not quite sure that the steps below will reproduce the issue.

  1. Create a fork of one of your repositories that has a workflow triggered by push events. To be able to create a fork, you have to make it under a new temporary organization (or user account) because normally you cannot fork your own repos.
  2. Submit a PR from a branch on your fork to the original repo.
  3. Push some non-conflicting commits to your original repo's main branch. This is required, so that gh pr update-branch can finish its job and not bail out with a PR branch is already up-to-date message.
  4. Create a fine-grained PAT that only has access to your forked repo (under your organization).
  5. Run gh auth login and use the created token.
  6. Run gh pr update-branch -R <original repo> <PR number>.
  7. See the error.

Expected vs actual behavior

User expects the last command to work (i.e., see the PR branch updated) or a message that says what scopes they need to add to their auth token. Instead, they see the following error:

GraphQL: refusing to allow an OAuth App to create or update workflow `.github/workflows/lint.yml` without `workflow` scope (updatePullRequestBranch)

Activity

  1. added
    bug
    on Jul 28, 2024
  2. added
    needs-triage
    on Jul 28, 2024
  3. williammartin commented on Jul 28, 2024

    @williammartin
    Member

    When you gh auth login which protocol did you choose? I would expect you get workflow scope with https, and if you chose ssh and then happened to clone with https then yeh, I could see how you might run into this.

  4. added
    more-info-needed
    gh-pr
    and removed
    needs-triage
    on Jul 28, 2024
  5. babakks commented on Jul 28, 2024

    @babakks
    MemberAuthor

    Yeah, I used ssh for login, but I've cloned the repo with ssh. This is the git remote -v result:

    origin	[email protected]:babakks/cli.git (fetch)
    origin	[email protected]:babakks/cli.git (push)
    upstream	[email protected]:cli/cli.git (fetch)
    upstream	[email protected]:cli/cli.git (push)
    
  6. williammartin commented on Jul 29, 2024

    @williammartin
    Member

    Yeh I guess that makes sense. You would be able to git push a change with workflow changes (because it would use your ssh key) but you couldn't use an API endpoint that involves merging a workflow change because your scopes don't have it. I agree that we should probably just default to adding workflow scope here in all cases, I think it's a weird edge case and hard to uncover.

    That said, if you could share the GH_DEBUG=api output that would be handy. We do have an oauth scope detection mechanism based on headers but I suspect what's happening here is that the API isn't being faithful. It's kind of a weird quirk that depending on the content of the changes you may need this scope or not, and so I don't think it's reflected in the spec.

  7. added
    help wanted
    and removed
    more-info-needed
    on Jul 29, 2024
  8. babakks commented on Jul 29, 2024

    @babakks
    MemberAuthor

    If you think the workflow scope should be added to the minimum-scopes at login, I'd be happy to submit a PR for that. But what about the existing sessions? I mean, those users who have already logged in, and won't get the workflow scope until they login again. Shouldn't we check for the error message and instruct them to add the required scope (by using gh auth refresh)?

    With GH_DEBUG=api

    I tried to replicate it but couldn't. I mean, I logged out and logged in again with the same choices to ensure I don't have the workflow scope. Below is the result with GH_DEBUG=api.

    I'm curious because the response header X-Oauth-Scopes is always gist, read:org, repo. So, I really don't have the workflow scope but this time everything worked. Also, the lint workflow (which triggering of it was the source of error last time) has been triggered again, this time with no issues.

    # GH_DEBUG=api gh pr update-branch 
    [git remote -v]
    [git config --get-regexp ^remote\..*\.gh-resolved$]
    [git symbolic-ref --quiet HEAD]
    [git config --get-regexp ^branch\.9292-add-remove-milestone-option\.(remote|merge)$]
    [git remote -v]
    [git config --get-regexp ^remote\..*\.gh-resolved$]
    ⣾* Request at 2024-07-29 21:22:06.364235369 +0100 BST m=+0.059857363
    * Request to https://api.github.com/graphql
    > POST /graphql HTTP/1.1
    > Host: api.github.com
    > Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
    > Authorization: token ████████████████████
    > Content-Length: 603
    > Content-Type: application/json; charset=utf-8
    > Graphql-Features: merge_queue
    > Time-Zone: Europe/London
    > User-Agent: GitHub CLI 2.53.0
    
    GraphQL query:
    query PullRequestForBranch($owner: String!, $repo: String!, $headRefName: String!, $states: [PullRequestState!]) {
        repository(owner: $owner, name: $repo) {
          pullRequests(headRefName: $headRefName, states: $states, first: 30, orderBy: { field: CREATED_AT, direction: DESC }) {
            nodes {id,number,headRefName,headRefOid,headRepositoryOwner{id,login,...on User{name}},mergeable,state,baseRefName,isCrossRepository}
          }
          defaultBranchRef { name }
        }
      }
    GraphQL variables: {"headRefName":"9292-add-remove-milestone-option","owner":"cli","repo":"cli","states":null}
    
    ⢿< HTTP/2.0 200 OK
    < Access-Control-Allow-Origin: *
    < Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
    < Content-Security-Policy: default-src 'none'
    < Content-Type: application/json; charset=utf-8
    < Date: Mon, 29 Jul 2024 20:22:06 GMT
    < Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
    < Server: GitHub.com
    < Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
    < Vary: Accept-Encoding, Accept, X-Requested-With
    < X-Accepted-Oauth-Scopes: repo
    < X-Content-Type-Options: nosniff
    < X-Frame-Options: deny
    < X-Github-Media-Type: github.v4; param=merge-info-preview.nebula-preview; format=json
    < X-Github-Request-Id: 9018:149E48:9E92CB:A802ED:66A7F9EE
    < X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
    < X-Oauth-Scopes: gist, read:org, repo
    < X-Ratelimit-Limit: 5000
    < X-Ratelimit-Remaining: 4573
    < X-Ratelimit-Reset: 1722285389
    < X-Ratelimit-Resource: graphql
    < X-Ratelimit-Used: 427
    < X-Xss-Protection: 0
    
    {
      "data": {
        "repository": {
          "pullRequests": {
            "nodes": [
              {
                "id": "PR_kwDODKw3uc52A2bb",
                "number": 9344,
                "headRefName": "9292-add-remove-milestone-option",
                "headRefOid": "c9fb4ed0996e8b56ac755fe1d0d738f893e46906",
                "headRepositoryOwner": {
                  "id": "MDQ6VXNlcjM2NzI4OTMx",
                  "login": "babakks",
                  "name": "Babak K. Shandiz"
                },
                "mergeable": "MERGEABLE",
                "state": "OPEN",
                "baseRefName": "trunk",
                "isCrossRepository": true
              }
            ]
          },
          "defaultBranchRef": {
            "name": "trunk"
          }
        }
      }
    }
    
    * Request took 374.640985ms
    ⣾* Request at 2024-07-29 21:22:06.748319004 +0100 BST m=+0.443941027
    * Request to https://api.github.com/graphql
    > POST /graphql HTTP/1.1
    > Host: api.github.com
    > Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
    > Authorization: token ████████████████████
    > Content-Length: 488
    > Content-Type: application/json; charset=utf-8
    > Graphql-Features: merge_queue
    > Time-Zone: Europe/London
    > User-Agent: GitHub CLI 2.53.0
    
    GraphQL query:
    query ComparePullRequestBaseBranchWith($owner: String!, $repo: String!, $pullRequestNumber: Int!, $headRef: String!) {
        repository(owner: $owner, name: $repo) {
          pullRequest(number: $pullRequestNumber) {
            baseRef {
              compare (headRef: $headRef) {
                aheadBy, behindBy, status
              }
            }
          }
        }
      }
    GraphQL variables: {"headRef":"babakks:9292-add-remove-milestone-option","owner":"cli","pullRequestNumber":9344,"repo":"cli"}
    
    ⣻< HTTP/2.0 200 OK
    < Access-Control-Allow-Origin: *
    < Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
    < Content-Security-Policy: default-src 'none'
    < Content-Type: application/json; charset=utf-8
    < Date: Mon, 29 Jul 2024 20:22:06 GMT
    < Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
    < Server: GitHub.com
    < Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
    < Vary: Accept-Encoding, Accept, X-Requested-With
    < X-Accepted-Oauth-Scopes: repo
    < X-Content-Type-Options: nosniff
    < X-Frame-Options: deny
    < X-Github-Media-Type: github.v4; param=merge-info-preview.nebula-preview; format=json
    < X-Github-Request-Id: 9018:149E48:9E92EE:A80313:66A7F9EE
    < X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
    < X-Oauth-Scopes: gist, read:org, repo
    < X-Ratelimit-Limit: 5000
    < X-Ratelimit-Remaining: 4572
    < X-Ratelimit-Reset: 1722285389
    < X-Ratelimit-Resource: graphql
    < X-Ratelimit-Used: 428
    < X-Xss-Protection: 0
    
    {
      "data": {
        "repository": {
          "pullRequest": {
            "baseRef": {
              "compare": {
                "aheadBy": 12,
                "behindBy": 4,
                "status": "DIVERGED"
              }
            }
          }
        }
      }
    }
    
    * Request took 269.408265ms
    ⣾* Request at 2024-07-29 21:22:07.025053931 +0100 BST m=+0.720675953
    * Request to https://api.github.com/graphql
    > POST /graphql HTTP/1.1
    > Host: api.github.com
    > Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
    > Authorization: token ████████████████████
    > Content-Length: 286
    > Content-Type: application/json
    > Graphql-Features: merge_queue
    > Time-Zone: Europe/London
    > User-Agent: GitHub CLI 2.53.0
    
    GraphQL query:
    mutation PullRequestUpdateBranch($input:UpdatePullRequestBranchInput!){updatePullRequestBranch(input: $input){pullRequest{id}}}
    GraphQL variables: {"input":{"pullRequestId":"PR_kwDODKw3uc52A2bb","expectedHeadOid":"c9fb4ed0996e8b56ac755fe1d0d738f893e46906","updateMethod":"MERGE"}}
    
    ⢿< HTTP/2.0 200 OK
    < Access-Control-Allow-Origin: *
    < Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
    < Content-Security-Policy: default-src 'none'
    < Content-Type: application/json; charset=utf-8
    < Date: Mon, 29 Jul 2024 20:22:08 GMT
    < Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
    < Server: GitHub.com
    < Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
    < Vary: Accept-Encoding, Accept, X-Requested-With
    < X-Accepted-Oauth-Scopes: repo
    < X-Content-Type-Options: nosniff
    < X-Frame-Options: deny
    < X-Github-Media-Type: github.v4; param=merge-info-preview.nebula-preview; format=json
    < X-Github-Request-Id: 9018:149E48:9E930B:A80336:66A7F9EE
    < X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
    < X-Oauth-Scopes: gist, read:org, repo
    < X-Ratelimit-Limit: 5000
    < X-Ratelimit-Remaining: 4571
    < X-Ratelimit-Reset: 1722285389
    < X-Ratelimit-Resource: graphql
    < X-Ratelimit-Used: 429
    < X-Xss-Protection: 0
    
    {
      "data": {
        "updatePullRequestBranch": {
          "pullRequest": {
            "id": "PR_kwDODKw3uc52A2bb"
          }
        }
      }
    }
    
    * Request took 1.351488649s
    ✓ PR branch updated
    
  9. williammartin commented on Jul 30, 2024

    @williammartin
    Member

    I'll look at this when I come back from vacation in mid-August. Don't think there's much rush. The message at least gives direction even if it's not the best.

  10. removed
    help wanted
    on Apr 10, 2025
  11. jkylekelly commented on Mar 6, 2026

    @jkylekelly
    Contributor

    @williammartin any chance we'll be seeing this soon?

    I agree that we should probably just default to adding workflow scope here in all cases, I think it's a weird edge case and hard to uncover.

  12. added
    priority-3
    pitch
    on Mar 10, 2026
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

    buggh-prpitchpriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions