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

Github - 403 for issue permission #1710

Closed
JoshuaJackson-jobvite opened this issue Sep 16, 2024 · 13 comments · Fixed by #1735
Closed

Github - 403 for issue permission #1710

JoshuaJackson-jobvite opened this issue Sep 16, 2024 · 13 comments · Fixed by #1735

Comments

@JoshuaJackson-jobvite
Copy link
Contributor

JoshuaJackson-jobvite commented Sep 16, 2024

Upgrading from 0.6.40 to 0.6.42 resulted in the following error:
error getting pull request (as issue): GET https://api.github.com/repos/ORG/REPO/issues/1316: 403 Resource not accessible by integration []

On 0.6.40 exact same workflow executes without any errors to the api nor were permissions needed to be extended. In testing with added permissions for issue and pullrequest no change in error. I have not adjusted the workflows permissions yet to test that change.

digger.yml:

generate_projects:
  blocks:
    - include: "environments/<ENVNAME>/**"
      workflow: default_work_flow
      aws_role_to_assume:
        state: "arn:aws:iam::<ACCOUNT>:role/<envname>-digger_terraform_state_iam_role"
        command: "arn:aws:iam::<ACCOUNT>:role/<envname>-digger_iam_role"
   
auto_merge: true

workflows:
  default_work_flow:
    plan:
      steps:
        - init
        - plan
        - run: infracost breakdown --path=. | tee -a $DIGGER_OUT
    apply:
      steps:
        - init
        - apply
    workflow_configuration:
      on_pull_request_pushed: ["digger plan"]
      on_pull_request_closed: ["digger unlock"]
      on_commit_to_default: ["digger apply"]

Github action:

name: Digger PR flow

on:
  pull_request:
    branches: ["main"]
    types: [closed, opened, synchronize, reopened]
  issue_comment:
    types: [created]
    if: startsWith(github.event.comment.body, 'digger')
  workflow_dispatch:
    inputs:
      spec:
        required: true
      run_name:
        required: false

run-name: "${{inputs.run_name}}"

permissions:
  contents: write
  id-token: write
  pull-requests: write
  statuses: write

jobs:
  digger-job:
    runs-on: ubuntu-latest
    if: ${{ github.actor != 'automated-commit-application[bot]' }}
    permissions:
      contents: write # required to merge PRs
      id-token: write # required for workload-identity-federation
      pull-requests: write # required to post PR comments
      statuses: write # required to validate combined PR status
      packages: read # required to read the packages
      actions: read
    steps:
      # create a temp. token from the github app installed in the org.
      # The app needs to have read access to all private terraform repos  in the org
      # this token is used in the next step to allow cloning terraform module repos
      - name: Generate Token
        id: generate_token
        uses: tibdex/github-app-token@v2.1.0
        with:
          app_id: ${{ secrets.COMMIT_AUTOMATION_APP_ID }}
          private_key: ${{ secrets.COMMIT_AUTOMATION_CLIENT_SECRET }}
      # allow terraform to download our private modules
      - name: Set git config
        run: /usr/bin/git config --global --add url."https://github:$GITHUB_TOKEN_READ_REPOS@github.com/<ORG>".insteadOf https://github.com/<ORG>
        env:
          GITHUB_TOKEN_READ_REPOS: ${{ steps.generate_token.outputs.token }}
      - uses: actions/checkout@v4
      - name: Setup Infracost
        uses: infracost/actions/setup@v3
        # See https://github.com/infracost/actions/tree/master/setup for other inputs
        # If you can't use this action, see Docker images in https://infracost.io/cicd
        with:
          api-key: ${{ secrets.INFRACOST_TOKEN }}
      - uses: diggerhq/digger@v0.6.42
        with:
          digger-spec: ${{ inputs.spec }}
          setup-aws: false
          cache-dependencies: true
          #aws-role-to-assume: {{ ENV .assume_role }}
          no-backend: true
          disable-locking: true
          digger-hostname: "https://cloud.digger.dev"
          digger-organisation: "<ORG>"
          digger-token: ${{ secrets.DIGGER_TOKEN }}
          #upload-plan-destination: 'github'
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
          GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
          GITHUB_OWNER: <COMPANY>
          AWS_REGION: us-east-1
          TF_VAR_GITHUB_APP_PEM: ${{ secrets.TF_VAR_GITHUB_APP_PEM }}
@JoshuaJackson-jobvite
Copy link
Contributor Author

Odd bit is that the main bits of code:

pr, _, err := svc.Client.PullRequests.Get(context.Background(), svc.Owner, svc.RepoName, prNumber)
if err != nil {
log.Printf("error getting pull request: %v", err)
return fmt.Errorf("error getting pull request: %v", err)
}
haven't changed in 2 months. So its not anything that should be new...

@samroweemployinc
Copy link

I added issue: write to the permissions: section and it continued to fail while also saying that all checks had passed.

@motatoes
Copy link
Contributor

motatoes commented Sep 17, 2024

Hi @samroweemployinc try issues: write (plural) and let me know if it resolves it for you

@motatoes
Copy link
Contributor

I suspect its related to this change

if confirmed to fix I will be updating the docs

@samroweemployinc
Copy link

Sorry the typo was in my comment, not in my test. I'd written issues: write in the actual file.

@motatoes
Copy link
Contributor

Ensure it looks like this:

    permissions:
      contents: write      # required to merge PRs
      actions: write       # required for plan persistence
      id-token: write      # required for workload-identity-federation
      pull-requests: write # required to post PR comments
      issues: write
      statuses: write      # required to validate combined PR status

also ensure it exists in the main branch

@samroweemployinc
Copy link

I'll try to test soon.

@samroweemployinc
Copy link

Still seeing error getting pull request (as issue): error checking if pull request is issue: with permissions like so:

permissions:
  actions: write # required for plan persistence
  contents: write # required to merge PRs
  id-token: write # required for workload-identity-federation
  issues: write
  pull-requests: write # required to post PR comments
  statuses: write # required to validate combined PR status

@JoshuaJackson-jobvite
Copy link
Contributor Author

JoshuaJackson-jobvite commented Sep 17, 2024

Still seeing error getting pull request (as issue): error checking if pull request is issue: with permissions like so:

permissions:
  actions: write # required for plan persistence
  contents: write # required to merge PRs
  id-token: write # required for workload-identity-federation
  issues: write
  pull-requests: write # required to post PR comments
  statuses: write # required to validate combined PR status

Please note we did modifications to the job and global level, and as job and global were the same stripped it down to just global for the permissions configuration.

I can also confirm for the github app, that we have read/write access to issues, and pull requests on the repo level.

@motatoes
Copy link
Contributor

Thanks for continued investigation on this. I had someone report exact same error and it was fixed with issues: write. Not sure what may be going on in your case but if at all possible could we reproduce it in a minimal repo somehow? That would be immensely helpful!

@jacksonwilliamsva
Copy link

Can confirm moving the permissions from the job level to the global level has resolved this issue for me.

@motatoes
Copy link
Contributor

Great! Glad it helped

@minamijoyo
Copy link
Contributor

Today I hit the same problem. Starting from digger v0.6.41, issues permissions are appear to be required. Whether issues: write permission is required or not may depending on which functionality you use, but at least the minimum issues: read permissions worked for me.

minamijoyo added a commit to minamijoyo/digger that referenced this issue Oct 2, 2024
Fixes diggerhq#1710

Starting from digger v0.6.41, at least `issues: read` permission is
required to check if PR number is an issue or not. It should be clearly
stated in the document so that other folks are not confused.

I'm not sure when `issues:write` is needed, please add another note
where appropriate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants