GPG Keys rotations
More Info:
GitHub GPG keys are used to cryptographically sign code commits and should be rotated every 180 days.
Risk Level
High
Address
Security
Compliance Standards
Remediation
Using Console
To remediate GPG Keys rotations for GitHub using the GitHub console, please follow the below steps:
-
Login to your GitHub account and navigate to the repository where the GPG key rotation needs to be performed.
-
Click on the “Settings” tab on the right-hand side of the repository.
-
In the settings menu, select “Secrets” from the left-hand side navigation menu.
-
Click on the “New repository secret” button to create a new secret.
-
In the “Name” field, type “GPG_PRIVATE_KEY” and in the “Value” field, paste your GPG private key.
-
Click on the “Add secret” button to save the new secret.
-
Next, you need to update your workflows to use the new GPG key. To do this, navigate to the “.github/workflows” directory in your repository.
-
Open the workflow file that needs to be updated and add the following lines at the beginning of the file:
-
Save the workflow file and commit the changes to your repository.
-
Your GPG key rotation is now complete and your workflows will use the new GPG key for signing commits and tags.
Note: It’s important to keep your GPG key secure and rotate it regularly to ensure the security of your code.
Using CLI
To remediate the GPG Keys rotation issue for GitHub using GitHub CLI, follow these steps:
-
Open your terminal and ensure that you have the latest version of GitHub CLI installed.
-
Login to your GitHub account using the command:
-
Once you are logged in, navigate to the repository where you want to remediate the GPG Keys rotation issue.
-
Generate a new GPG key using the command:
Follow the prompts to create a new GPG key. Make sure to use the same email address associated with your GitHub account.
-
List your GPG keys using the command:
This will display a list of your GPG keys, including the key ID for your new key.
-
Export your public key using the command:
Replace
<KEY_ID>
with the key ID for your new key. -
Copy the output of the command and navigate to your GitHub account settings.
-
Click on “SSH and GPG keys” and then click “New GPG key”.
-
Paste the output of the command into the “Key” field and click “Add GPG key”.
-
Finally, update your Git configuration to use your new GPG key for signing commits using the command:
Replace
<KEY_ID>
with the key ID for your new key.
That’s it! You have successfully remediated the GPG Keys rotation issue for GitHub using GitHub CLI.
Using Python
To remediate the GPG Keys rotation misconfiguration for GitHub using Python, you can follow these steps:
-
Install the
PyGithub
library, which allows you to interact with the GitHub API using Python. You can install it using pip by runningpip install PyGithub
. -
Create a personal access token in your GitHub account with the
admin:public_key
scope. -
Use the
Github
class from thePyGithub
library to authenticate with your GitHub account using the personal access token.
- Get a list of all the GPG keys in your GitHub account using the
get_gpg_keys()
method of the authenticatedGithub
object.
- Check the expiration date of each GPG key using the
expiration_date
attribute of theGithub.GPGKey
object. If the key has already expired or will expire soon, delete it using thedelete()
method.
- If any keys were deleted, generate a new GPG key using the
create_gpg_key()
method of the authenticatedGithub
object. You can specify the key type, key length, and expiration date using thekey_type
,key_length
, andexpiration_date
parameters.
- Commit and push the changes to your GitHub account using the
commit()
andpush()
methods of theGithub.Git.Commit
object.
These steps will remediate the GPG Keys rotation misconfiguration for GitHub using Python.