This GitHub Action automates the revocation of unused Personal Access Tokens and SSH keys (credentials), enhancing organizational security by removing unused credentials that haven't been accessed within a specified timeframe. Proactively eliminating these credentials reduces the risk of security breaches and ensures compliance with the organization's security policies.
This action can only be used in organizations where Single Sign-On (SSO) is enabled.
The action utilizes a GitHub App to authenticate against the GitHub API. It retrieves all associated credentials for the organization and checks the last time they were used. If a credential has not been utilized for the specified number of days, and it is not expired, the action revokes it.
An increased attack surface results from having unused (but active) credentials within your organization. Revoking these credentials reduces the risk of unauthorized access to your organization. Furthermore, you only need to set it up once, and it will run automatically on a schedule you define, saving you time and effort.
- Create a GitHub App in the organization where you want to revoke credentials.
- Repository permissions:
metadata
: read-only
- Organization permissions:
administration
: read & writepersonal_access_token
: read & writemembers
: read-only
- Repository permissions:
- Generate a private key for the GitHub App.
- Install the GitHub App in the organization.
- Note the
App ID
,private key
, andinstallation ID
. - Encode the private key in
base64
format. - Store the App ID, encoded private key, and installation ID as
secrets
in the repository (update secret names as needed).
You just need to add the action to your workflow file. Here is an example:
- name: Revoke Unused Credentials
uses: tentwentyone/github-org-sso-auth-revoker@v1
with:
days: ${{github.event.inputs.days || 45}}
dry-run: ${{github.event.inputs.dry-run || true}}
whitelist: ${{github.event.inputs.whitelist || secrets.GH_CRED_REVOKER_WHITELIST }}
# GitHub App credentials
gh_app_id: ${{ secrets.GH_CRED_REVOKER_APP_ID }}
gh_pem_key: ${{ secrets.GH_CRED_REVOKER_PEM_KEY }}
gh_install_id: ${{ secrets.GH_CRED_REVOKER_INSTALL_ID }}
Here you can find a complete example workflow that runs the action every week and revokes 45 days innactive credentials.
dry-run
(boolean): Indicates whether the action should perform a dry run. Default istrue
when triggered manually andfalse
when triggered by a schedule.days
(number): Number of days to check for unused credentials. Default is45
.whitelist
(string): List of credential IDs to ignore (comma separated). If empty, theGH_WHITELIST
environment variable will be used.
the default values will be used when the trigger is a shedule
gh_app_id
(string): The GitHub App ID.gh_pem_key
(string): The GitHub App private key (base64 encoded).gh_install_id
(string): The GitHub App installation ID.
The results are added to the GitHub Actions summary.
- After setting up and running the action, you can run it manually with the
dry-run
input set totrue
and thedays
value set to0
. This will list all the credentials associated with the organization. - Gather all the credential IDs that you want to preserve for whitelisting.
- Set the
whitelist
input with a comma-separated list of the credential IDs (e.g.,123456, 123456789
).
The scripts and documentation in this project are released under the MIT License.
We welcome contributions! Please check our guidelines for details.
Please see our SECURITY.md for details on our security policy and reporting security vulnerabilities.