|
| 1 | +# Pattern Stack Authentication Setup |
| 2 | + |
| 3 | +This document explains how to set up authentication for Pattern Stack repositories to access private dependencies. |
| 4 | + |
| 5 | +## Current Setup: Service Account + PAT |
| 6 | + |
| 7 | +### 1. Create Service Account (One-time per organization) |
| 8 | + |
| 9 | +1. **Create GitHub Account** |
| 10 | + - Create a new GitHub account: `pattern-stack-ci` |
| 11 | + - Use an email like `ci@pattern-stack.com` |
| 12 | + |
| 13 | +2. **Add to Organization** |
| 14 | + - Invite `pattern-stack-ci` to the `pattern-stack` organization |
| 15 | + - Grant `Read` access to repositories that need to be accessed by CI |
| 16 | + - Specifically ensure access to: |
| 17 | + - `pattern-stack/geography-patterns` |
| 18 | + - `pattern-stack/backend-patterns` |
| 19 | + |
| 20 | +### 2. Generate Personal Access Token |
| 21 | + |
| 22 | +1. **Login as Service Account** |
| 23 | + - Login to GitHub as `pattern-stack-ci` |
| 24 | + |
| 25 | +2. **Create PAT** |
| 26 | + - Go to Settings → Developer settings → Personal access tokens → Tokens (classic) |
| 27 | + - Click "Generate new token (classic)" |
| 28 | + - **Name**: `Pattern Stack CI Access` |
| 29 | + - **Expiration**: 1 year (set calendar reminder to rotate) |
| 30 | + - **Scopes**: |
| 31 | + - ✅ `repo` (Full control of private repositories) |
| 32 | + - Generate and copy the token |
| 33 | + |
| 34 | +### 3. Add to Repository Secrets |
| 35 | + |
| 36 | +For each repository that needs access: |
| 37 | + |
| 38 | +1. Go to repository Settings → Secrets and variables → Actions |
| 39 | +2. Click "New repository secret" |
| 40 | +3. **Name**: `PATTERN_STACK_TOKEN` |
| 41 | +4. **Value**: The PAT from step 2 |
| 42 | +5. Save |
| 43 | + |
| 44 | +### 4. Verify Setup |
| 45 | + |
| 46 | +The workflows should now: |
| 47 | +- Use `PATTERN_STACK_TOKEN` for checkout and git configuration |
| 48 | +- Successfully install dependencies from private repositories |
| 49 | +- Pass all CI checks |
| 50 | + |
| 51 | +## Auth Pattern Used in Workflows |
| 52 | + |
| 53 | +All workflows use this consistent pattern: |
| 54 | + |
| 55 | +```yaml |
| 56 | +steps: |
| 57 | +- uses: actions/checkout@v4 |
| 58 | + with: |
| 59 | + token: ${{ secrets.PATTERN_STACK_TOKEN }} |
| 60 | + |
| 61 | +- name: Configure git for private repo access |
| 62 | + run: | |
| 63 | + git config --global url."https://x-access-token:${{ secrets.PATTERN_STACK_TOKEN }}@github.com/".insteadOf "https://github.com/" |
| 64 | +
|
| 65 | +- name: Install dependencies |
| 66 | + run: | |
| 67 | + uv sync --frozen |
| 68 | + # Dependencies from private repos now work |
| 69 | +``` |
| 70 | +
|
| 71 | +## Future Migration: GitHub App |
| 72 | +
|
| 73 | +When scaling to multiple repositories, we'll migrate to a GitHub App approach: |
| 74 | +
|
| 75 | +1. **Benefits**: Better security, automatic token rotation, granular permissions |
| 76 | +2. **Implementation**: Pattern Stack tooling will automate the creation and installation |
| 77 | +3. **Migration**: Seamless - workflows use same `PATTERN_STACK_TOKEN` interface |
| 78 | + |
| 79 | +## Troubleshooting |
| 80 | + |
| 81 | +### Common Issues |
| 82 | + |
| 83 | +1. **"fatal: could not read Username"** |
| 84 | + - Verify `PATTERN_STACK_TOKEN` secret exists in repository |
| 85 | + - Check service account has access to target repositories |
| 86 | + - Verify PAT has `repo` scope |
| 87 | + |
| 88 | +2. **PAT Expired** |
| 89 | + - Generate new PAT with same scopes |
| 90 | + - Update `PATTERN_STACK_TOKEN` secret in all repositories |
| 91 | + - Set calendar reminder for next rotation |
| 92 | + |
| 93 | +3. **403 Forbidden** |
| 94 | + - Service account needs to be added to private repositories |
| 95 | + - Check organization membership and repository access |
| 96 | + |
| 97 | +### Security Notes |
| 98 | + |
| 99 | +- PAT has broad access - rotate regularly (annually) |
| 100 | +- Only add to repositories that need private dependency access |
| 101 | +- Consider GitHub App migration for better security posture |
| 102 | +- Monitor usage in organization audit logs |
0 commit comments