Skip to content

Commit d13e15d

Browse files
authored
docs(github-app): add github app connection auth docs (#735)
* add github app connection auth docs * changelog * no defaultOpen
1 parent 024ae58 commit d13e15d

File tree

4 files changed

+105
-45
lines changed

4 files changed

+105
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111
- Remove references to demo from docs. [#734](https://github.com/sourcebot-dev/sourcebot/pull/734)
12+
- Add docs for GitHub App connection auth. #[735](https://github.com/sourcebot-dev/sourcebot/pull/735)
1213

1314
### Fixed
1415
- Fixed issue where 403 errors were being raised during a user driven permission sync against a self-hosted code host. [#729](https://github.com/sourcebot-dev/sourcebot/pull/729)

docs/docs/configuration/idp.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Sourcebot uses [Auth.js](https://authjs.dev/) to connect to external identity pr
5151

5252
[Auth.js GitHub Provider Docs](https://authjs.dev/getting-started/providers/github)
5353

54-
A GitHub connection can be used for either [authentication](/docs/configuration/auth) or [permission syncing](/docs/features/permission-syncing). This is controlled using the `purpose` field
54+
A GitHub connection can be used for [authentication](/docs/configuration/auth) and/or [permission syncing](/docs/features/permission-syncing). This is controlled using the `purpose` field
5555
in the GitHub identity provider config.
5656

5757
<Accordion title="instructions">
@@ -115,7 +115,7 @@ in the GitHub identity provider config.
115115

116116
[Auth.js GitLab Provider Docs](https://authjs.dev/getting-started/providers/gitlab)
117117

118-
A GitLab connection can be used for either [authentication](/docs/configuration/auth) or [permission syncing](/docs/features/permission-syncing). This is controlled using the `purpose` field
118+
A GitLab connection can be used for [authentication](/docs/configuration/auth) and/or [permission syncing](/docs/features/permission-syncing). This is controlled using the `purpose` field
119119
in the GitLab identity provider config.
120120

121121
<Accordion title="instructions">

docs/docs/connections/github.mdx

Lines changed: 101 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ icon: GitHub
55
---
66

77
import GitHubSchema from '/snippets/schemas/v3/github.schema.mdx'
8+
import LicenseKeyRequired from '/snippets/license-key-required.mdx'
89

910
Sourcebot can sync code from GitHub.com, GitHub Enterprise Server, and GitHub Enterprise Cloud.
1011

@@ -106,56 +107,114 @@ If you're not familiar with Sourcebot [connections](/docs/connections/overview),
106107

107108
## Authenticating with GitHub
108109

109-
In order to index private repositories, you'll need to generate a access token and provide it to Sourcebot. GitHub provides [two types](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#types-of-personal-access-tokens) of access tokens:
110+
In order to index private repositories, you'll need to authenticate with GitHub. Sourcebot supports the following mechanisms of authenticating a GitHub connection:
110111

111112

112113
<AccordionGroup>
113-
<Accordion title="Fine-grained personal access tokens" defaultOpen>
114-
Create a new fine-grained PAT [here](https://github.com/settings/personal-access-tokens/new). First, select the resource owner and the repositories that you want Sourcebot to have access to.
115-
116-
Next, under "Repository permissions", select permissions `Contents` and `Metadata` with access `Read-only`. The permissions should look like the following:
117-
118-
![GitHub PAT Scope](/images/github_pat_scopes_fine_grained.png)
119-
120-
[GitHub docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#fine-grained-personal-access-tokens)
114+
<Accordion title="GitHub App">
115+
<LicenseKeyRequired />
116+
<Steps>
117+
<Step title="Register a new GitHub App">
118+
Register a new [GitHub App](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app#registering-a-github-app) and provide it with the following permissions:
119+
- “Contents” repository permissions (read)
120+
- “Metadata” repository permissions (read)
121+
- “Members” organization permissions (read)
122+
- “Email addresses” account permissions (read)
123+
124+
This can be the same GitHub App you've registered and configured as an [external identity provider](/docs/configuration/idp#github)
125+
</Step>
126+
<Step title="Install the GitHub App">
127+
Install the GitHub App into the GitHub orgs that you want Sourcebot to be aware of. **Sourcebot will only be able to index repos from orgs with the GitHub App installed.**
128+
</Step>
129+
<Step title="Create a private key for the GitHub App">
130+
Create a [private key](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/managing-private-keys-for-github-apps) for the GitHub App.
131+
</Step>
132+
<Step title="Define the GitHub App config in Sourcebot">
133+
Create a new `apps` object in the Sourcebot [config file](/docs/configuration/config-file). The private key you created in the previous
134+
step must be passed in as a [token](/docs/configuration/config-file#tokens).
135+
```json wrap icon="code"
136+
"apps": [
137+
{
138+
"type": "github", // must be github
139+
"id": "1234567", // Your GitHub App ID
140+
"privateKey": {
141+
"env": "GITHUB_APP_PRIVATE_KEY" // Token which contains your Github App private key
142+
}
143+
}
144+
]
145+
```
146+
</Step>
147+
<Step title="You're done!">
148+
That's it! Sourcebot will now use this GitHub App to authenticate when pulling repos for this connection.
149+
</Step>
150+
</Steps>
151+
</Accordion>
152+
<Accordion title="Fine-grained personal access tokens">
153+
<Steps>
154+
<Step title="Create PAT">
155+
Create a new fine-grained PAT [here](https://github.com/settings/personal-access-tokens/new). Select the resource owner and the repositories that you want Sourcebot to have access to.
156+
157+
Next, under "Repository permissions", select permissions `Contents` and `Metadata` with access `Read-only`. The permissions should look like the following:
158+
159+
![GitHub PAT Scope](/images/github_pat_scopes_fine_grained.png)
160+
161+
[GitHub docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#fine-grained-personal-access-tokens)
162+
</Step>
163+
<Step title="Pass PAT into Sourcebot">
164+
Next, provide the PAT via a [token](/docs/configuration/config-file#tokens) which is referenced in the `token` field in the [connection](/docs/connections/overview) config object.
165+
166+
The most common mechanism of doing this is defining an environment variable that holds the PAT:
167+
168+
```json
169+
{
170+
"type": "github",
171+
"token": {
172+
// note: this env var can be named anything. It
173+
// doesn't need to be `GITHUB_TOKEN`.
174+
"env": "GITHUB_TOKEN"
175+
}
176+
// .. rest of config ..
177+
}
178+
```
179+
</Step>
180+
<Step title="You're done!">
181+
That's it! Sourcebot will now use this PAT to authenticate when pulling repos for this connection.
182+
</Step>
183+
</Steps>
121184
</Accordion>
122185
<Accordion title="Personal access tokens (classic)">
123-
Create a new PAT [here](https://github.com/settings/tokens/new) and make sure you select the `repo` scope:
124-
125-
![GitHub PAT Scope](/images/github_pat_scopes.png)
126-
127-
[GitHub docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#personal-access-tokens-classic)
186+
<Steps>
187+
<Step title="Create PAT">
188+
Create a new PAT [here](https://github.com/settings/tokens/new) and make sure you select the `repo` scope:
189+
190+
![GitHub PAT Scope](/images/github_pat_scopes.png)
191+
192+
[GitHub docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#personal-access-tokens-classic)
193+
</Step>
194+
<Step title="Pass PAT into Sourcebot">
195+
Next, provide the PAT via a [token](/docs/configuration/config-file#tokens) which is referenced in the `token` field in the [connection](/docs/connections/overview) config object.
196+
197+
The most common mechanism of doing this is defining an environment variable that holds the PAT:
198+
199+
```json
200+
{
201+
"type": "github",
202+
"token": {
203+
// note: this env var can be named anything. It
204+
// doesn't need to be `GITHUB_TOKEN`.
205+
"env": "GITHUB_TOKEN"
206+
}
207+
// .. rest of config ..
208+
}
209+
```
210+
</Step>
211+
<Step title="You're done!">
212+
That's it! Sourcebot will now use this PAT to authenticate when pulling repos for this connection.
213+
</Step>
214+
</Steps>
128215
</Accordion>
129216
</AccordionGroup>
130217

131-
Next, provide the access token via an environment variable [token](/docs/configuration/config-file#tokens) which is referenced in the `token` property:
132-
133-
<Tabs>
134-
<Tab title="Environment Variable">
135-
136-
1. Add the `token` property to your connection config:
137-
```json
138-
{
139-
"type": "github",
140-
"token": {
141-
// note: this env var can be named anything. It
142-
// doesn't need to be `GITHUB_TOKEN`.
143-
"env": "GITHUB_TOKEN"
144-
}
145-
// .. rest of config ..
146-
}
147-
```
148-
149-
2. Pass this environment variable each time you run Sourcebot:
150-
```bash
151-
docker run \
152-
-e GITHUB_TOKEN=<PAT> \
153-
/* additional args */ \
154-
ghcr.io/sourcebot-dev/sourcebot:latest
155-
```
156-
</Tab>
157-
</Tabs>
158-
159218
## Connecting to a custom GitHub host
160219

161220
To connect to a GitHub host other than `github.com`, provide the `url` property to your config:

docs/docs/connections/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Each connection defines how Sourcebot should authenticate and interact with a pa
2424
"env": "GITHUB_TOKEN"
2525
}
2626
},
27-
// 2. A self-hosted GitLab instance
27+
// 2. A connection to a self-hosted GitLab instance
2828
"gitlab-connection": {
2929
"type": "gitlab",
3030
"url": "https://gitlab.example.com",

0 commit comments

Comments
 (0)