|
| 1 | +## Deployment |
| 2 | + |
| 3 | +1. [Add a custom attribute on the users](https://support.google.com/a/answer/6208725?hl=en#zippy=%2Cadd-a-new-custom-attribute) |
| 4 | + |
| 5 | + 1. Go to https://admin.google.com/ac/customschema |
| 6 | + 1. Enter |
| 7 | + - Category: `Accounts` |
| 8 | + - Description: `Accounts held elsewhere to link in` |
| 9 | + - Custom fields: |
| 10 | + - name: `github` |
| 11 | + - info type: `text` |
| 12 | + - visibility: `Visible to the organisation` |
| 13 | + - no. of values: `multi-value` |
| 14 | + |
| 15 | +1. [Add values to custom attributes for the users](https://support.google.com/a/answer/6208725?hl=en#add_value) |
| 16 | + |
| 17 | + 1. go to https://admin.google.com/ac/users |
| 18 | + 1. click a user to edit them |
| 19 | + 1. click 'user information' |
| 20 | + 1. under Accounts, click `github` |
| 21 | + 1. add all the github accounts for that user |
| 22 | + 1. click Save |
| 23 | + |
| 24 | +1. [Make a gcp project](https://console.cloud.google.com/projectcreate) |
| 25 | + |
| 26 | + 1. enable the [Admin SDK API](https://console.cloud.google.com/apis/library/admin.googleapis.com?q=workspace%20admin&id=d0a160dd-c410-4fd0-a951-c47e05309cb9) |
| 27 | + 1. [create credentials](https://console.cloud.google.com/apis/credentials/wizard?project=githubusermanager) |
| 28 | + |
| 29 | + - Which API are you using?: `Admin SDK API` |
| 30 | + - Are you planning to use this API with App Engine or Compute Engine: `no` |
| 31 | + - Service account name: `githubusermanager` |
| 32 | + - Role: `[none]` |
| 33 | + - Key type: `JSON` |
| 34 | + - Click `Continue`, then confirm `CREATE WITHOUT ROLE` |
| 35 | + - edit the user, Click `Enable G Suite domain-wide delegation` |
| 36 | + - product name for the consent screen: `githubusermanager` |
| 37 | + |
| 38 | + 1. [Delegate domain-wide authority to your service account](https://developers.google.com/admin-sdk/directory/v1/guides/delegation) |
| 39 | + |
| 40 | + - https://admin.google.com/ac/owl/domainwidedelegation |
| 41 | + - client ID: `client id from user` |
| 42 | + - OAuth scopes: |
| 43 | + - `https://www.googleapis.com/auth/admin.directory.user.readonly` |
| 44 | + |
| 45 | +1. Register new GitHub App |
| 46 | + 1. https://github.com/settings/organizations |
| 47 | + - click `Settings` on your organization |
| 48 | + - click `Developer settings` |
| 49 | + - click `GitHub Apps` |
| 50 | + - click `New GitHub App` |
| 51 | + 1. Enter: |
| 52 | + - GitHub App name: `Google workspace github users` |
| 53 | + - Homepage URL: github.com |
| 54 | + - Webhook |
| 55 | + - Active `uncheck` |
| 56 | + - Organization permissions |
| 57 | + - Members: `Read-only` |
| 58 | + - Where can this GitHub App be installed? `Only on this account` |
| 59 | + 1. Click `Generate a private key` (should download a .pem) |
| 60 | + 1. Click `Install App` |
| 61 | + 1. Click `Install` |
| 62 | + 1. Click `Install` |
| 63 | + - take node of the url, it'll look something like: `github.com/organizations/myorg/settings/installations/15627551`, the installationId is the last number `15627551` |
| 64 | + |
| 65 | +## RUN |
| 66 | + |
| 67 | +### Setup environment variables |
| 68 | + |
| 69 | +| Environment Variable | Description | Example | Default | |
| 70 | +| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------- | ----------------- | ------- | |
| 71 | +| `GOOGLE_EMAIL_ADDRESS` | Email address to assume to, needs to be an workspace admin | `foo@example.com` | `null` | |
| 72 | +| `GOOGLE_CREDENTIALS` | Base64'd json as downloaded from the google service account creation step | `Zm9vCg==` | `null` | |
| 73 | +| `ADD_USERS` | Set to TRUE to add users to the github organisation | `TRUE` | `false` | |
| 74 | +| `REMOVE_USERS` | Set to TRUE to remove users from the github organisation | `TRUE` | `false` | |
| 75 | +| `EXIT_CODE_ON_MISMATCH` | Exit code to use when there's a mismatch, useful when combined with `ADD_USERS` and `REMOVE_USERS` to be used in a dry-run mode | `1` | `0` | |
| 76 | +| `GITHUB_ORG` | GitHub Organization | `chrisnstest` | `null` | |
| 77 | +| `GITHUB_APP_ID` | GitHub App ID | `106341` | `null` | |
| 78 | +| `GITHUB_INSTALLATION_ID` | Github App Installation ID | `15627551` | `null` | |
| 79 | +| `GITHUB_PRIVATE_KEY` | Base64'd private key as downloaded from github application registration step | `Zm9vCg==` | `null` | |
| 80 | +| `IGNORED_USERS` | Comma separated list of user ids to totally ignore always, useful for owners of an org you don't accidentally removed | `owner1,owner2` | `null` | |
0 commit comments