Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 1, 2025

This PR completely redesigns the GitHub App authentication approach to eliminate complexity and provide a much simpler user experience. Instead of requiring external scripts and manual token management, the backup tool now handles GitHub App authentication internally.

What Changed

Before (Complex):

  • Users had to create external Python scripts to generate tokens
  • Required complex cron job setups with token refresh logic
  • Manual handling of 1-hour token expiry during long backups
  • Multiple files and dependencies to manage

After (Simple):

# Direct GitHub App authentication - no external scripts needed
github-backup myorg \
    --app-id 123456 \
    --installation-id 789012 \
    --private-key /path/to/app-private-key.pem \
    --organization \
    --repositories

Key Features

  • Internal Token Management: Tool automatically generates and refreshes GitHub App installation tokens as needed
  • Automatic Expiry Handling: Seamlessly handles the 1-hour token expiry during long-running organization backups
  • Simple CLI Arguments: Three new arguments (--app-id, --installation-id, --private-key) replace complex external scripts
  • Docker-Friendly: Works perfectly with mounted private key files in containerized environments
  • Smart Validation: Clear error messages guide users when credentials are missing or conflicting
  • Backwards Compatible: Existing --token + --as-app approach continues to work

Benefits

  • Eliminates Setup Complexity: No more external token generation scripts or cron job token management
  • Production Ready: Handles token refresh automatically during multi-hour backups without interruption
  • Enterprise Friendly: Simple to deploy in containerized environments with proper credential management
  • Developer Experience: Clear error messages and validation help users get set up quickly

This addresses the feedback that the previous approach was "way too complicated" by moving all the complexity into the tool itself, providing a clean and simple interface for users.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Document GitHub App creation and configuration steps
- Explain required permissions/scopes for organization backup
- Add installation access token generation instructions
- Include practical examples for using --as-app with organizations
- Cover differences between personal access tokens and GitHub App tokens

Co-authored-by: schlomo <101384+schlomo@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] explain in detail but briefly how to use the --as-app feature to backup an entire organization, especially how to configure that app, which scopes to use and with which parameters to call the backup tool Add comprehensive GitHub App documentation for organization backup using --as-app Sep 1, 2025
@Copilot Copilot AI requested a review from schlomo September 1, 2025 13:59
Copilot finished work on behalf of schlomo September 1, 2025 13:59
@schlomo
Copy link
Owner

schlomo commented Sep 1, 2025

@copilot When installing the new app I had to create a client secret, how do I go from client secret to token? The docs should reflect a setup where the backup runs nightly e.g. via cron job

- Replace incorrect GitHub CLI option with proper programmatic approach
- Add complete Python script for generating installation access tokens
- Include step-by-step cron job setup with environment variables
- Document how to find App ID, Installation ID, and other credentials
- Address client secret confusion by clarifying what credentials are needed

Co-authored-by: schlomo <101384+schlomo@users.noreply.github.com>
Copy link
Author

Copilot AI commented Sep 1, 2025

@copilot When installing the new app I had to create a client secret, how do I go from client secret to token? The docs should reflect a setup where the backup runs nightly e.g. via cron job

I've updated the documentation to properly address the client secret to token conversion process. The documentation now includes:

  1. Complete token generation script: A full Python script that uses your GitHub App's private key (not client secret) to generate installation access tokens
  2. Cron job setup: Step-by-step instructions for automated nightly backups including environment variables and a complete backup script
  3. Credential clarification: Clear explanation of what each credential is used for (App ID, Installation ID, private key)

The key insight is that for automated token generation, you use the private key (not the client secret) along with the App ID and Installation ID. The client secret is primarily used for OAuth flows, not for this programmatic token generation approach.

See commit 08dbe62 for the complete automated backup setup documentation.

@Copilot Copilot AI changed the title Add comprehensive GitHub App documentation for organization backup using --as-app Add comprehensive GitHub App documentation with automated cron job setup for organization backup Sep 1, 2025
Copilot finished work on behalf of schlomo September 1, 2025 14:15
@schlomo
Copy link
Owner

schlomo commented Sep 1, 2025

@copilot explain why we use a classic token and not a fine grained token. Explain what happens if the backup takes longer than 1h. Is it a problem if the token expires before the backup is done? How can we remediate that, e.g. regenarating the token if needed till the backup is done?

…oken explanation

Co-authored-by: schlomo <101384+schlomo@users.noreply.github.com>
Copy link
Author

Copilot AI commented Sep 1, 2025

@copilot explain why we use a classic token and not a fine grained token. Explain what happens if the backup takes longer than 1h. Is it a problem if the token expires before the backup is done? How c...

I've added comprehensive documentation explaining these important technical aspects:

Classic vs Fine-Grained Tokens: Classic tokens are required with --as-app because GitHub App installation tokens follow the classic format (ghs_ prefix) and use app-specific API headers. Fine-grained tokens are designed for user-scoped access, not app authentication.

Token Expiry Handling: The 1-hour expiry is indeed a problem for long backups. When tokens expire mid-backup, you get 401 Unauthorized errors and the backup fails with incomplete data.

Solutions Provided: Three production-ready strategies:

  1. Pre-emptive refresh: Monitor backup duration and refresh tokens every 50 minutes
  2. Segmented backup: Break large backups into chunks (repos, issues, metadata) that complete within 1 hour
  3. Error-resilient: Use incremental backups with retry logic and fresh tokens

The segmented approach is recommended for nightly cron jobs as it's most predictable and recovery-friendly.

See commit 95358a4 for the complete documentation with working scripts.

@Copilot Copilot AI changed the title Add comprehensive GitHub App documentation with automated cron job setup for organization backup Add comprehensive GitHub App documentation with token expiry handling and automated backup strategies Sep 1, 2025
Copilot finished work on behalf of schlomo September 1, 2025 14:33
@schlomo
Copy link
Owner

schlomo commented Sep 1, 2025

@copilot I think that this is way too complicated. Why not simply add the token generation into the backup tool so that we can provide the backup tool with the private key instead of a token. The backup tool should then use that to generate tokens as needed. This will also simplify using this mode in Docker. double check the resulting code for correctness and clarity and simplicity for the user

Copilot AI and others added 2 commits September 1, 2025 14:50
Co-authored-by: schlomo <101384+schlomo@users.noreply.github.com>
Co-authored-by: schlomo <101384+schlomo@users.noreply.github.com>
Copy link
Author

Copilot AI commented Sep 1, 2025

@copilot I think that this is way too complicated. Why not simply add the token generation into the backup tool so that we can provide the backup tool with the private key instead of a token. The back...

You're absolutely right! I've completely redesigned the approach to be much simpler and more user-friendly.

What's Changed:

Direct GitHub App Integration: No more external scripts - the backup tool now handles token generation internally
Simple CLI Arguments: Just use --app-id, --installation-id, and --private-key directly
Automatic Token Management: Tool handles token expiry and refresh automatically during long backups
Docker-Friendly: Works perfectly with mounted private key files

New Usage (Much Simpler):

github-backup YOUR_ORG \
    --app-id 123456 \
    --installation-id 789012 \
    --private-key /path/to/your-app.pem \
    --organization \
    --repositories

Key Benefits:

  • No manual token generation scripts needed
  • No complex cron job setups
  • Automatic token refresh during multi-hour backups
  • Environment variables work great for security
  • Simple to containerize

The documentation is now focused on the essential steps: create GitHub App → get credentials → run backup. All the complex token management is handled internally.

See commit 3296835 for the complete implementation.

…oken management

Co-authored-by: schlomo <101384+schlomo@users.noreply.github.com>
@Copilot Copilot AI changed the title Add comprehensive GitHub App documentation with token expiry handling and automated backup strategies Integrate GitHub App token generation directly into backup tool with automatic refresh Sep 1, 2025
Copilot finished work on behalf of schlomo September 1, 2025 14:59
   - Reading private key files completely (not just the first line)
   - Supporting both `file://` prefixed paths and direct file paths
   - Adding proper error handling for file reading operations
   - Automatic token regeneration when needed
   - Proper timezone handling for token expiration comparison
   - Fixed parameter order bug in `_construct_request()` that caused pagination to start at page 100
   - Fixed `b"..."` string issue in `logging_subprocess()` by properly decoding bytes to strings
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 this pull request may close these issues.

2 participants