-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add GitHub app auth to cnquery #453
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
title: Give cnquery Access to GitHub using Custom App Credentials | ||
sidebar_label: GitHub with Custom App Credentials | ||
sidebar_position: 5 | ||
displayed_sidebar: cnquery | ||
description: Give cnquery access to GitHub using a custom application. | ||
image: /img/featured_img/mondoo-feature.jpg | ||
--- | ||
|
||
To [query GitHub organizations and repos](/cnquery/saas/github/), cnquery needs to authenticate with GitHub. There are two ways to do this: | ||
|
||
- Option 1: Give cnquery access using a personal access token and an environment variable. This approach is easier to set up but results isn't recommended for very large GitHub organizations. To learn how to give cnquery access using a personal access token, read [Give cnquery access using a personal access token and an environment variable](/cnquery/saas/github/). | ||
|
||
- Option 2: Give cnquery access using custom GitHub application credentials. This approach takes longer to set up, but scales for very large GitHub organizations (with API rate limits as much as 3x higher than personal access tokens). To learn how to give cnquery access using custom app credentials, continue reading below. | ||
|
||
For cnquery to authenticate with GitHub using [custom GitHub application credentials](https://docs.github.com/en/apps/creating-github-apps), create a GitHub application and give cnquery the app ID, private key, and installation ID. | ||
|
||
## Create a GitHub application and get the authentication information cnquery needs | ||
|
||
1. In the top-right corner of any page on GitHub, select your profile icon. | ||
|
||
2. Open your account settings: | ||
|
||
- To create an app owned by a personal account, select **Settings**. | ||
|
||
- To create an app owned by an organization, select **Your organizations** and, to the right of the organization you want, select **Settings**. | ||
|
||
3. In the left sidebar, select **Developer settings**. | ||
|
||
4. In the left sidebar, select GitHub Apps. | ||
|
||
5. Select the **New GitHub App** button. | ||
|
||
![Add a new GitHub app](/img/cnspec/github/name-new-app.png) | ||
|
||
6. In the **GitHub App name** box, type a name for your app that helps you easily recognize that it's for Mondoo. The name must be unique across GitHub. | ||
|
||
7. In the **Description** box, write that this app provides authentication for Mondoo queries. | ||
|
||
8. In the **Homepage URL** box, type `https://cnquery.io' or your own company URL. | ||
|
||
9. Skip past the settings under **Identifying and authorizing users** and **Post installation**. | ||
|
||
10. Under **Webhooks**, uncheck the **Active** box. | ||
|
||
![Webhooks](/img/cnspec/github/webhook.png) | ||
|
||
11. Under **Permissions**, assign **read-only** permission to all repository and organization data. | ||
|
||
![Permissions](/img/cnspec/github/perms.png) | ||
|
||
12. Under **Where can this GitHub App be installed?**, select **Only on this account**. | ||
|
||
![Add a new GitHub app](/img/cnspec/github/create-gh-app.png) | ||
|
||
12. Select the **Create GitHub App** button. | ||
|
||
GitHub creates the app and displays its properties. | ||
|
||
![Created GitHub app](/img/cnspec/github/created-app.png) | ||
|
||
13. In the **About** section, copy the **App ID** value and save it somewhere that you can access later. You need it when you query. | ||
|
||
14. Scroll down to the **Private keys** section and select the **Generate a private key** button. | ||
|
||
GitHub creates a new private key and downloads it to your workstation in a PEM certificate file. Note the path to the PEM file; you need it when you query. | ||
|
||
15. In the left sidebar, select **Install App**. | ||
|
||
16. Install your custom app to any repo so that you can see its installation ID. | ||
|
||
GitHub installs the app and displays a confirmation. | ||
|
||
![Install a new GitHub app](/img/cnspec/github/install-success.png) | ||
|
||
In your browser's address bar, find the installation ID in the URL, after `/installations/`. For example, the pictured app's installation ID is `56758584`. Copy this value and save it somewhere that you can access later. You need it when you query. | ||
|
||
## Query using your custom app credentials | ||
|
||
Enter the `cnquery shell` command, passing the information you stored in the steps above: | ||
|
||
| For... | Substitute... | | ||
|------------------------------|-------------------------------------------------------| | ||
| `YOUR-GITHUB-ORG` | The name of the GitHub organization you want to query | | ||
| `YOUR-GITHUB-APP-ID` | The app ID from step 13 | | ||
| `YOUR-GITHUB-APP-INSTALL-ID` | The installation ID from step 16 | | ||
| `PATH-TO-PEM-FILE` | The path you noted in step 14 | | ||
|
||
```bash | ||
cnquery shell github org <YOUR-GITHUB-ORG> --app-id <YOUR-GITHUB-APP-ID> --app-installation-id <YOUR-GITHUB-APP-INSTALL-ID> --app-private-key <PATH-TO-PEM-FILE> | ||
``` | ||
|
||
To learn more options for querying GitHub organizations and repositories, read [Assess the Configuration of GitHub Organizations and Repositories with cnspec](/cnspec/saas/github/). | ||
|
||
--- |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/mondoohq/docs/blob/main/static/img/cnspec/github/perms.png
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duh! I missed it. Thanks