Manages who is in your GitHub organization based on a custom property in their Google Workspace profile, allowing for seamless JML (Joiner mover leaver) process, if allowed removing/disabling an account in the Google Workspace will remove the user from the GitHub; similarly adding a user also works the same way. If you don't want to run it in destructive mode it can be configured to exit with a non-zero exit code so that you know to go and manually make the changes.
Right now this only handles the organization membership, it does not touch team membership, or level of membership; the main focus is to draw alert when the configuration isn't as expected, these features could be added in future.
-
Add a custom attribute on the users
- Go to https://admin.google.com/ac/customschema
- Enter
- Category:
Accounts - Description:
Accounts held elsewhere to link in - Custom fields:
- name:
github - info type:
text - visibility:
Visible to the organisation - no. of values:
multi-value
- name:
- Category:
-
Add values to custom attributes for the users
- Go to https://admin.google.com/ac/users
- Click a user to edit them
- Click 'user information'
- Under Accounts, click
github - Add all the github accounts for that user
- Click Save
-
- Enable the Admin SDK API
- Create credentials
- Which API are you using?:
Admin SDK API - Are you planning to use this API with App Engine or Compute Engine:
no - Service account name:
githubusermanager - Role:
[none] - Key type:
JSON - Click
Continue, then confirmCREATE WITHOUT ROLE - Edit the user, Click
Enable G Suite domain-wide delegation - Product name for the consent screen:
githubusermanager
- https://admin.google.com/ac/owl/domainwidedelegation
- Client ID:
client id from user - OAuth scopes:
https://www.googleapis.com/auth/admin.directory.user.readonly
-
Register new GitHub App
- Click
Settingson your organization - Click
Developer settings - Click
GitHub Apps - Click
New GitHub App
- Enter:
- GitHub App name:
Google workspace github users - Homepage URL: github.com
- Webhook
- Active
uncheck
- Active
- Organization permissions
- Members:
Read-only, orRead-Writeif you want it to
- Members:
- Where can this GitHub App be installed?
Only on this account
- Click
Generate a private key(should download a .pem) - Click
Install App - Click
Install - Click
Install
- take node of the url, it'll look something like:
github.com/organizations/myorg/settings/installations/15627551, the installationId is the last number15627551
- Click
# ./.github/workflows/org-membership.yml
name: Github Org Membership
on:
schedule:
- cron: '*/5 * * * *'
jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Github Org Membership Manager
uses: reMarkable/githubUserManager@v1
with:
google-email-address: hello@example.com
google-credentials: ${{ secrets.GOOGLE_CREDENTIALS }}
add-users: 'false'
remove-users: 'false'
exit-code-on-mismatch: '1'
github-org: 'myorg'
github-app-id: 1234
github-installation-id: 12345
github-private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
ignored-users: user1,user2
sync-team: 'true'
team-slug: 'remarkable'Add a dependabot configuration to always get updates!
# ./.github/dependabot.yml
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: dailyThis action runs as a Docker container action:
GitHub builds the image from the Dockerfile at the exact ref you pin the
action to, so you can reference an immutable commit SHA and there is no
separately published image tag to bump before a release.
Inputs are read directly from the GitHub Action inputs (exposed by the runner
as INPUT_* environment variables). To run the container by hand, set the same
inputs with the INPUT_ prefix and the input name upper-cased, e.g.
INPUT_GITHUB-ORG, INPUT_ADD-USERS:
docker build -t githubusermanager .
docker run --rm \
-e INPUT_GOOGLE-EMAIL-ADDRESS=foo@example.com \
-e INPUT_GITHUB-ORG=myorg \
# ...the remaining inputs from the table below... \
githubusermanager- Clone this repo
go build -o githubusermanager ../githubusermanager(with theINPUT_*variables from the table below set)
Inputs use the action input names below; when running the container directly set
them as INPUT_<NAME> environment variables (upper-cased input name).
| Input | Description | Example | Default |
|---|---|---|---|
google-email-address |
Email address to assume to, needs to be an workspace admin | foo@example.com |
null |
google-credentials |
Base64'd json as downloaded from the google service account creation step | Zm9vCg== |
null |
add-users |
Set to TRUE to add users to the github organisation | TRUE |
false |
remove-users |
Set to TRUE to remove users from the github organisation | TRUE |
false |
remove-suspended_users |
Set to TRUE to remove users from the github organisation that are suspended in Google | TRUE |
false |
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 |
max-remove-users |
Safety limit on how many users may be removed in a single run | 100 |
100 |
github-org |
GitHub Organization | chrisnstest |
null |
github-app-id |
GitHub App ID | 106341 |
null |
github-installation-id |
Github App Installation ID | 15627551 |
null |
github-private-key |
Base64'd private key as downloaded from github application registration step | Zm9vCg== |
null |
ignored-users |
Comma separated list of user ids to totally ignore always, useful for owners of an org you don't want accidentally removed | owner1,owner2 |
null |
sync-team |
Set to TRUE to ensure every org member is added to the team named in team-slug |
TRUE |
false |
team-slug |
Slug of the team every org member should be added to, e.g. to grant PR rights to shared repos | remarkable |
null |
debug |
Set to TRUE to enable debug level logging | TRUE |
false |