|
| 1 | +--- |
| 2 | +title: How to generate the GitHub Personal Access Token for Infrastructure |
| 3 | +weight: 20 |
| 4 | +parent: /ways-of-working |
| 5 | +hide_in_navigation: true |
| 6 | +last_reviewed_on: 2023-11-20 |
| 7 | +review_in: 12 months |
| 8 | +--- |
| 9 | + |
| 10 | +# How to generate the GitHub Personal Access Token for Infrastructure |
| 11 | + |
| 12 | +<%= partial 'partials/_links' %> |
| 13 | + |
| 14 | +Personal access tokens (PATs) are a secure way to grant third-party applications access to your GitHub account. They are an alternative to using your GitHub password, which can be more secure as they can be limited to specific scopes and can be revoked if they are compromised. |
| 15 | + |
| 16 | +<div class="govuk-warning-text"> |
| 17 | + <span class="govuk-warning-text__icon" aria-hidden="true">!</span> |
| 18 | + <strong class="govuk-warning-text__text"> |
| 19 | + <span class="govuk-warning-text__assistive">Warning</span> |
| 20 | + Classic PATs are the older version of PATs and are still supported by GitHub. They have been deprecated in favor of fine-grained PATs, which offer more granular control over permissions. However, classic PATs are still a viable option for many users and used here. |
| 21 | + </strong> |
| 22 | +</div> |
| 23 | + |
| 24 | + |
| 25 | +In this document, we will describe how to generate a classic PAT in GitHub and add it as a secret to the three UKSA repositories. |
| 26 | + |
| 27 | +## Generating a Classic Personal Access Token |
| 28 | + |
| 29 | +1. __Navigate to your GitHub settings:__ Click on your profile picture in the top right corner of any GitHub page and select "Settings" from the dropdown menu. |
| 30 | + |
| 31 | +2. __Access Developer Settings:__ In the left sidebar, click on "Developer settings". |
| 32 | + |
| 33 | +3. __Generate a new token:__ Under the "Personal access tokens" section, click on "Generate new token". |
| 34 | + |
| 35 | + |
| 36 | +4. __Provide a descriptive name:__ In the "Note" field, give your token a descriptive name so you can easily identify it later, e.g. "Terraform PAT". |
| 37 | + |
| 38 | +5. __Set expiration:__ If you want your token to expire after a certain period, select "Expiration" and choose the desired expiration time. We expire after 30 days and regenerate. |
| 39 | + |
| 40 | +6. __Select permissions:__ Choose the permissions you want to grant to your token. We use the the token to access repositories, so select the "repo" scope. |
| 41 | + |
| 42 | + |
| 43 | +7. __Generate the token:__ Once you have selected the desired permissions, click on "Generate token". |
| 44 | + |
| 45 | +8. __Copy and save the token:__ Your newly generated token will be displayed on the screen. Copy and save this token securely, as it will be needed later. |
| 46 | + |
| 47 | + |
| 48 | +## Adding the Token as a Secret to Repositories |
| 49 | + |
| 50 | +<div class="govuk-warning-text"> |
| 51 | + <span class="govuk-warning-text__icon" aria-hidden="true">!</span> |
| 52 | + <strong class="govuk-warning-text__text"> |
| 53 | + <span class="govuk-warning-text__assistive">Warning</span> |
| 54 | + This will be done over three repositories. |
| 55 | + </strong> |
| 56 | +</div> |
| 57 | + |
| 58 | +1. __Navigate to the repository settings:__ Go to the page of the repository where you want to add the token as a secret. |
| 59 | + |
| 60 | +2. __Access settings:__ Click on "Settings" in the top right corner of the repository page. |
| 61 | + |
| 62 | +3. __Open Secrets section:__ In the left sidebar, click on "Secrets and Variables" and select "Actions". |
| 63 | + |
| 64 | +4. __Find the secret for the respective repo:__ Either `INFRA_REPO_TOKEN` (for sst-beta and sst-beta-python-backend) or `TF_GITHUB_TOKEN` (for sst-beta-infra) |
| 65 | + |
| 66 | +5. __Paste the token:__ In the "Value" field, paste the personal access token you generated earlier. |
| 67 | + |
| 68 | +6. __Save the secret:__ Click on "Update secret" to save the token as a secret for the repository. |
| 69 | + |
| 70 | +## Repeat for Additional Repositories |
| 71 | +Repeat the process of adding the token as a secret for each repository. |
| 72 | + |
| 73 | +* [Front-end](https://github.com/UKSpaceAgency/sst-beta/) |
| 74 | +* [Back-end](https://github.com/UKSpaceAgency/sst-beta-python-backend/) |
| 75 | +* [Infra](https://github.com/UKSpaceAgency/sst-beta-infra/) |
| 76 | + |
0 commit comments