cnspec icon indicating copy to clipboard operation
cnspec copied to clipboard

cnspec scan github org <org_name> --token <token_value> automatically traverses all org repositories hitting API rate limits

Open estenrye opened this issue 1 year ago • 5 comments

What is not working as you expected it?

When scanning a GitHub Organization, cnspec automatically scans all of the organization's repositories. This is not helpful when you have many repos in the organization because after about 5 repos you hit the GitHub API Rate limits and the scan errors out.

Where on the platform does it happen?

Mac Client and GitHub Actions.

How do we replicate the issue?

Our organization has about 172 repositories. The scan starts hitting the rate limit after about 5 repositories.

name: Scan GitHub organization
on:
  #push:
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  scan-github-org:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: mondoohq/actions/[email protected]
        env:
          MONDOO_CONFIG_BASE64: ${{ secrets.MONDOO_SERVICE_ACCOUNT }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          organization: platform9
      - uses: mondoohq/actions/[email protected]
        env:
          MONDOO_CONFIG_BASE64: ${{ secrets.MONDOO_SERVICE_ACCOUNT }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          organization: arlon

Expected behavior (i.e. solution)

Only the Organization itself should be scanned by default. An option could be provided to traverse the organization's repositories.

estenrye avatar May 17 '23 02:05 estenrye

@estenrye Thank you for the feedback, you can restrict the discovery to organizations via:

cnspec scan github org mondoohq --discover organization 

@tas50 I think we should not do auto-discovery for all repos right now and make it an opt-in for users at this point. Thoughts?

chris-rock avatar May 17 '23 04:05 chris-rock

Unless we have a magic bullet to solve the API rate limiting problem, I'm all for making the discovery of repos optional.

tas50 avatar May 17 '23 05:05 tas50

The rate limits are fairly well documented so it could do back-offs and delays to discover all within the limits of github has set. It would slow the call down but would make it successful.

There is an endpoint to hit to check the limits as well:

https://api.github.com/rate_limit https://docs.github.com/en/rest/rate-limit

sontek avatar May 17 '23 11:05 sontek

@estenrye Thank you for the feedback, you can restrict the discovery to organizations via:

cnspec scan github org mondoohq --discover organization 

@tas50 I think we should not do auto-discovery for all repos right now and make it an opt-in for users at this point. Thoughts?

I can try this workaround for now, but I think it's awfully inelegant. Why break out GitHub into multiple commands of org and repo when you have the --discover flag?

Is there a way to pass this option to the GitHub action?

estenrye avatar May 17 '23 12:05 estenrye

@estenrye 100% agree, I propose we are going to do the following:

  • update the github action to have the discover flag for org and change it https://github.com/mondoohq/actions/blob/main/github-org/action.yaml#L39-L40C7, we also want to add the option to the action to enable discovery
  • cnspec need to change the default for org to not discovery repositories by default
  • cnspec needs to learn about GitHub ratelimiting and handle that properly

chris-rock avatar May 17 '23 12:05 chris-rock