enterprise-security-team
enterprise-security-team copied to clipboard
Manage a uniform team of security managers for every organization in your enterprise
Enterprise security management teams
This set of scripts provides some basics of organization governance to GitHub Enterprise (cloud or server) administrators. The scripts will give you a list of all organizations in the enterprise as a CSV to work with programmatically, add you to all organizations as an owner, and can create/manage a team with the security manager role to see all GitHub Advanced Security alerts throughout the entire enterprise without having admin rights to that code.
:information_source: This uses the security manager role and parts of the GraphQL API that is available in GitHub.com (free/pro/teams and enterprise), as well as GitHub Enterprise Server versions 3.5 and higher.
Scripts
org-admin-promote.pyreplaces some of the functionality ofghe-org-admin-promote(link), a built-in shell command on GHES that promotes an enterprise admin to own all organizations in the enterprise. It also outputs a CSV file similar to theall_organizations.csvreport, to better inventory organizations.manage-sec-team.pycreates a team in each organization, assigns it the security manager role, and then adds the people you want to that team (and removes the rest).org-admin-demote.pytakes the text file of orgs that the user wasn't already an owner of and "un-does" that promotion to org owner. The goal is to keep the admin account's notifications uncluttered, but running this is totally optional.
How to use it
You need to be an enterprise administrator to use these scripts!
-
Read :point_up: and decide what you want to do.
-
Create a personal access token (directions) with the
enterprise:adminscope. -
Clone this repository to a machine that has Python 3 installed.
-
Install the requirements.
python3 -m pip install --upgrade pip pip install -r requirements.txt -
Edit the inputs at the start of the script as follows:
- (for GHES) the API endpoint
- Create a file called
token.txtand save your token there to read it. - Add the enterprise slug, a string URL version of the enterprise identity. It's easily available in the enterprise admin url (for cloud and server), e.g.
https://github.com/enterprises/ENTERPRISE-SLUG-HERE. - (for the security manager team), the list of orgs output by
org-admin-promote.pyand the name of the security manager team and the team members to add.
-
Run them in the following order, deciding where to stop.
org-admin-promote.pyto add the enterprise admin to all organizations as an owner, creating a CSV of organizations.manage-sec-team.pyto create a security manager team on all organizations and manage the members.org-admin-demote.pywill remove the enterprise admin from all the organizations the previous script added them to.
Assumptions
- The security manager team isn't already an existing team that's using team sync for enterprise or for organizations. You may be able to edit the script a bit to make this work by adding an existing team to all orgs, but I wasn't going to dive deep into the weeds of identity management.
Any extra info?
This is what a successful run looks like. Here's the inputs:
- The enterprise admin is named
ghe-admin. - The security team is named
spy-stuffand has two membersluigiandhubot. - The organizations break down as such:
acmeorg was already configured correctly.testorg-00001needed the team created, withghe-adminremoved andluigiandhubotadded.testorg-00002was already created
$ ./manage-sec-team.py
Team spy-stuff updated as a security manager for acme!
Creating team spy-stuff
Team spy-stuff updated as a security manager for testorg-00001!
Removing ghe-admin from spy-stuff
Adding luigi to spy-stuff
Adding hubot to spy-stuff
Creating team spy-stuff
Team spy-stuff updated as a security manager for testorg-00002!
Removing ghe-admin from spy-stuff
Team spy-stuff updated as a security manager for testorg-00003!
Architecture Footnotes
- Scripts that do things are in the root directory.
- Functions that do small parts are in
/src, grouped roughly by what part of GitHub they work on. - All Python code is formatted with black because it's simple and beautiful and no one needs to think about style.
- Python dependencies are minimal by default. There are two, both kept up-to-date with Dependabot. You can check out the config file here if you'd like.
- requests is a simple and extremely popular HTTP library.
- defusedcsv is used over CSV to mitigate potential spreadsheet application exploitations based on how it processes user-generated data. OWASP has written much more about CSV injection attacks on their website here.
- The CSV files and TXT files are in the
.gitignorefile to not be accidentally committed into the repo.