Skip to content

Commit 934ee4b

Browse files
authored
Merge pull request #467 from Iamrodos/docs/187-189-auth-docs
Add GitHub Apps documentation and stdin token example
2 parents 37a0c5c + ef99048 commit 934ee4b

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

README.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,37 @@ Customise the permissions for your use case, but for a personal account full bac
177177
**Repository permissions**: Read access to contents, issues, metadata, pull requests, and webhooks.
178178

179179

180+
GitHub Apps
181+
~~~~~~~~~~~
182+
183+
GitHub Apps are ideal for organization backups in CI/CD. Tokens are scoped to specific repositories and expire after 1 hour.
184+
185+
**One-time setup:**
186+
187+
1. Create a GitHub App at *Settings -> Developer Settings -> GitHub Apps -> New GitHub App*
188+
2. Set a name and homepage URL (can be any URL)
189+
3. Uncheck "Webhook > Active" (not needed for backups)
190+
4. Set permissions (same as fine-grained tokens above)
191+
5. Click "Create GitHub App", then note the **App ID** shown on the next page
192+
6. Under "Private keys", click "Generate a private key" and save the downloaded file
193+
7. Go to *Install App* in your app's settings
194+
8. Select the account/organization and which repositories to back up
195+
196+
**CI/CD usage with GitHub Actions:**
197+
198+
Store the App ID as a repository variable and the private key contents as a secret, then use ``actions/create-github-app-token``::
199+
200+
- uses: actions/create-github-app-token@v1
201+
id: app-token
202+
with:
203+
app-id: ${{ vars.APP_ID }}
204+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
205+
206+
- run: github-backup myorg -t ${{ steps.app-token.outputs.token }} --as-app -o ./backup --all
207+
208+
Note: Installation tokens expire after 1 hour. For long-running backups, use a fine-grained personal access token instead.
209+
210+
180211
Prefer SSH
181212
~~~~~~~~~~
182213

@@ -364,6 +395,9 @@ Debug an error/block or incomplete backup into a temporary directory. Omit "incr
364395

365396
github-backup -f $FINE_ACCESS_TOKEN -o /tmp/github-backup/ -l debug -P --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --pulls --pull-comments --pull-commits --labels --milestones --repositories --wikis --releases --assets --pull-details --gists --starred-gists $GH_USER
366397

398+
Pipe a token from stdin to avoid storing it in environment variables or command history (Unix-like systems only)::
399+
400+
my-secret-manager get github-token | github-backup user -t file:///dev/stdin -o /backup --repositories
367401

368402
Restoring from Backup
369403
=====================

github_backup/github_backup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,6 @@ def _construct_request(per_page, query_args, template, auth, as_app=None, fine=F
800800
else:
801801
auth = auth.encode("ascii")
802802
request.add_header("Authorization", "token ".encode("ascii") + auth)
803-
request.add_header(
804-
"Accept", "application/vnd.github.machine-man-preview+json"
805-
)
806803

807804
log_url = template if "?" not in template else template.split("?")[0]
808805
if querystring:

0 commit comments

Comments
 (0)