-
Notifications
You must be signed in to change notification settings - Fork 0
Decommission GitHub management script #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,112 +1,10 @@ | ||
| # OpenSAFELY Sysadmin Tools | ||
|
|
||
| This repository contains the documentation and scripts used to manage | ||
| the OpenSAFELY Github organisation's users, teams, repos and | ||
| permissions. | ||
| A collection of sysadmin things. | ||
|
|
||
| Github's organisation features are somewhat limited. Repositories are | ||
| flat, no grouping, so each repo needs explicitly adding to a team, at an | ||
| explicit permissions level. This makes managing this via the UI | ||
| laborious and and error prone. | ||
|
|
||
| This repo include config and scripts to manage the teams and repos via | ||
| the Github API. | ||
|
|
||
| The high level goal to protect against injection of code via github into | ||
| any part of the OpenSAFELY systems. To reduce risk, we to separate the | ||
| sensitive infrastructure repos out from the ever-growing list of | ||
| study repos, and restrict write access to the senstive repos to a | ||
| smaller technical team. As there is no repository grouping, this is | ||
| done via explicit config stored in this repo. | ||
|
|
||
| There are two teams. Researchers have admin access to all study repos. | ||
| Developers have admin access to all protected infrastructure repos, and | ||
| are also in Researchers team. | ||
|
|
||
| All master/main branches are protected, even for admins. This disables | ||
| force-pushes from anywhere. | ||
|
|
||
| Additionally, protected repos require code review, and signing. This | ||
| prevents pushes to master/main without a review. | ||
|
|
||
| # Readonly Classic PATs | ||
|
|
||
| At the time this system was implemented, Github only had classic PATs. And | ||
| whilst these supported a readonly scope for public repos, if you wanted private | ||
| repo access, you *had* to have write access too. However, it was not acceptable | ||
| for job-server or job-runner to have write access. | ||
|
|
||
| So, in order to acheive a readonly opensafely org PAT, we: | ||
|
|
||
| a) lowered the base permissions for the opensafely org to read (they were admin!) | ||
| b) added the machinery described above to elevate approved users permissions to be able to *write*. | ||
| c) created an opensafely-readonly bot account, that was *not* included in the machinery above | ||
| c) use this bot use to create PATs for job-server and job-runner. | ||
|
|
||
| Over time, this readonly user has also been used to create issues in various | ||
| private repo, so is also a collaborator on specific repos in ebmdatalab org as well. | ||
|
|
||
| # System prerequisites | ||
|
|
||
| ## Just | ||
|
|
||
| We use [`just`](https://github.com/casey/just) as our command runner. It's | ||
| a single file binary available for many platforms so should be easy to | ||
| install. | ||
|
|
||
| ```sh | ||
| # macOS | ||
| brew install just | ||
|
|
||
| # Linux | ||
| # Install from https://github.com/casey/just/releases | ||
|
|
||
| # Add completion for your shell. E.g. for bash: | ||
| source <(just --completions bash) | ||
|
|
||
| # Show all available commands | ||
| just # shortcut for just --list | ||
| ``` | ||
|
|
||
| ## uv | ||
|
|
||
| Follow installation instructions from the [uv documentation](https://docs.astral.sh/uv/getting-started/installation/) for your OS. | ||
|
|
||
| ## Python | ||
|
|
||
| You'll need an appropriate version of Python on your PATH. Check the | ||
| `.python-version` file for the required version. | ||
|
|
||
| # Setup | ||
|
|
||
| Create virtual environment, .env file and install requirements. | ||
| ``` | ||
| just devenv | ||
| ``` | ||
|
|
||
| * Create a GitHub personal access token with admin:org permissions, and update | ||
| it the `ORG_TOKEN` variable in the `.env` file. | ||
|
|
||
|
|
||
| # Run | ||
|
|
||
| Ensure you have a GH PAT with org admin permissions in `.env` | ||
|
|
||
| `just manage-github` will run the command in dryrun mode, printing changes it would have made | ||
|
|
||
| `just manage-github --exec` will actually apply the changes. | ||
|
|
||
|
|
||
| # Cron Job | ||
|
|
||
| The management script is designed to run periodically. However, it uses a very | ||
| privileged secret, so it currently runs from Simon's home machine. | ||
|
|
||
| Run set up a cronjob yourself, you can use `cronjob.sh`. First, edit the `tokenfile` variable to | ||
| point a file with a GH PAT that has admin org permissions. | ||
|
|
||
| Then, set it to run every hour at n minutes past the hour via `crontab -e` or similar. | ||
| e.g. to run at 17m past each hour: | ||
|
|
||
| `17 * * * * /path/to/cronjob.sh >> /path/to/logfile.log 2>&1` | ||
| This contains: | ||
|
|
||
| * documentation in `adr/` | ||
| * `repoupdater` a utility to help manage multiple repositories in | ||
| `repoupdater/` | ||
| * configuration for small services in `services/` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: This isn't checking the
services/otel-gateway/ directory for updates, but there's no change as/` didn't either.