Two Factor Authentication
More Info:
Ensures multi-factor authentication is enabled for the default user account. GitHub MFA provides additional account security by requiring an additional login device or code. All accounts should have MFA enabled.
Risk Level
High
Address
Security
Compliance Standards
Remediation
Using Console
To remediate the misconfiguration of not having Two Factor Authentication enabled for GitHub using the GitHub console, follow these steps:
- Log in to your GitHub account using your credentials.
- Click on your profile picture in the top right corner and select “Settings” from the dropdown menu.
- In the left-hand menu, click on “Security” and then scroll down to the “Two-factor authentication” section.
- Click on the “Set up two-factor authentication” button.
- Select the authentication method you would like to use (SMS or an authentication app) and follow the prompts to set it up.
- Once you have set up two-factor authentication, you will see a green checkmark next to “Two-factor authentication” in the Security section of your GitHub settings.
Congratulations, you have successfully remediated the misconfiguration of not having Two Factor Authentication enabled for GitHub using the GitHub console.
Using CLI
To remediate the misconfiguration of not having two-factor authentication enabled for GitHub using GitHub CLI, follow these steps:
- Install the GitHub CLI on your local machine.
- Open your terminal and run the command
gh auth login
to authenticate with your GitHub account. - Once you are authenticated, run the command
gh auth status
to confirm that you are logged in. - Next, run the command
gh auth 2fa status
to check the status of your two-factor authentication. - If two-factor authentication is not enabled, run the command
gh auth 2fa enable
to enable it. - Follow the prompts to set up two-factor authentication for your GitHub account.
- Once two-factor authentication is enabled, run the command
gh auth 2fa status
again to confirm that it is enabled.
By following these steps, you will have successfully remediated the misconfiguration of not having two-factor authentication enabled for GitHub using GitHub CLI.
Using Python
To remediate the misconfiguration of not having two-factor authentication enabled for GitHub, you can use the PyGithub library in Python to programmatically enable two-factor authentication for the GitHub user account. Here are the steps to follow:
- Install the PyGithub library using pip:
- Import the necessary modules:
- Create an instance of the Github class and authenticate with a personal access token:
- Get the authenticated user:
- Check if two-factor authentication is enabled:
- If two-factor authentication is not enabled, create a new personal access token with the “admin:org” scope:
- Create a new OTP (one-time password) device:
- Get the OTP secret:
- Prompt the user to scan the QR code with their mobile device:
- Prompt the user to enter the current OTP code:
- Verify the OTP code:
- Commit the changes to the user’s account:
By following these steps, you will be able to programmatically enable two-factor authentication for a GitHub user account using Python and the PyGithub library.