Skip to content

Commit 597960e

Browse files
authored
📖 Update README to accept fine-grained tokens (#1175)
* Update README for fine-grained tokens - Removed "Personal Access Token (PAT) Requirements and Risks" section, which doesn't apply to fine-grained tokens - In "Authentication with PAT (Optional)" - Updated settings for fine-grained permissions - Removed comment about SAML SSO, which doesn't apply to fine-grained tokens - In "Troubleshooting", removed items on private repositories and SAML SSO. - Updated "Workflow example" Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> * Add info on classic PATs and risks of Administration Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> * Remove comment on deploy keys Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> * Permissions only used for branch protection and webhooks Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> --------- Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]>
1 parent 8808ed2 commit 597960e

File tree

2 files changed

+51
-43
lines changed

2 files changed

+51
-43
lines changed

README.md

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ OIDC token which verifies the authenticity of the result when publishing it. See
1414

1515
If publishing results, scorecard-action:v2 also imposes new requirements on both the workflow and the job running the `ossf/scorecard-action` step. For full details see [here](#workflow-restrictions).
1616
________
17-
[Personal Access Token (PAT) Requirements and Risks](#personal-access-token-pat-requirements-and-risks)
18-
1917
[Installation](#installation)
2018
- [Workflow Setup](#workflow-setup-required)
21-
- [Authentication](#authentication-with-pat-optional)
19+
- [Authentication](#authentication-with-fine-grained-pat-optional)
2220

2321
[View Results](#view-results)
2422
- [REST API](#rest-api)
@@ -33,6 +31,8 @@ ________
3331
- [Workflow Restrictions](#workflow-restrictions)
3432
- [Uploading Artifacts](#uploading-artifacts)
3533
- [Workflow Example](#workflow-example)
34+
35+
["Classic" PAT Requirements and Risks](#classic-personal-access-token-pat-requirements-and-risks)
3636
________
3737

3838
The following GitHub triggers are supported: `push`, `schedule` (default branch only).
@@ -43,27 +43,6 @@ Running the Scorecard action on a fork repository is not supported.
4343

4444
GitHub Enterprise repositories are not supported.
4545

46-
## Personal Access Token (PAT) Requirements and Risks
47-
48-
Certain features require a Personal Access Token (PAT).
49-
50-
- Public repositories need a PAT to enable the
51-
[Branch-Protection](https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection)
52-
check. Without a PAT, Scorecards will run all checks except the
53-
Branch-Protection check
54-
- Private repositories need a PAT to use any Scorecard Action functions
55-
56-
Using a PAT introduces risks, however. Due to a limitation of the GitHub
57-
permission model, the PAT needs
58-
[write permission to the repository](https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes)
59-
through the `repo` scope. **The PAT will be stored as a
60-
[GitHub encrypted secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets)
61-
and be accessible by all the workflows and maintainers of a repository.**
62-
This means another maintainer on your project could potentially use the token to impersonate you. If there is an exploitable bug in a workflow with write permissions, an external contributor could potentially exploit it to extract the PAT.
63-
64-
We recommend that you **do not use a PAT** unless you feel that the
65-
risks introduced are outweighed by the functionalities they support.
66-
6746
## Installation
6847

6948
### Workflow Setup (Required)
@@ -87,27 +66,43 @@ risks introduced are outweighed by the functionalities they support.
8766

8867
![image](/images/install05.png)
8968

90-
### Authentication with PAT (optional)
91-
Create a Personal Access Token (PAT) for authentication and save the token value as a repository secret. Review [Personal Access Token (PAT) Requirements and Risks](#personal-access-token-pat-requirements-and-risks) before using a PAT.
69+
### Authentication with Fine-grained PAT (optional)
70+
Scorecard can run successfully with the workflow's default `GITHUB_TOKEN`.
71+
However, the `Branch-Protection` and (experimental) `Webhooks` checks require additional data that isn't accessible with that token.
9272

93-
1. [Create a Personal Access Token](https://github.com/settings/tokens/new?scopes=public_repo,read:org,read:repo_hook,read:discussion) with the following read permissions:
94-
- Note: `Token for OSSF Scorecard Action - myorg/myrepo` (Note: replace `myorg/myrepo` with the names of your organization and repository so you can keep track of your tokens.)
95-
- Expiration: `No expiration`
96-
- Scopes:
97-
* `repo > public_repo` Required to read [Branch-Protection](https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection) settings. **Note**: for private repositories, you need scope `repo`.
98-
* `admin:org > read:org` Optional: not used in current implementation.
99-
* `admin:repo_hook > read:repo_hook` Optional: needed for the experimental [Webhook](https://github.com/ossf/scorecard/blob/main/docs/checks.md#webhooks) check.
100-
* `write:discussion > read:discussion` Optional: not used in current implementation.
73+
We therefore suggest you create a fine-grained Personal Access Token (PAT) that Scorecard may use for authentication.
10174

102-
![image](/images/tokenscopes.png)
75+
1. [Create a fine-grained Personal Access Token](https://github.com/settings/personal-access-tokens/new) with the following settings:
76+
- Token name: `OpenSSF Scorecard Action - $USER_NAME/$REPO_NAME>`
77+
(Note: replace `$USER_NAME/$REPO_NAME` with the names of your organization and repository so you can keep track of your tokens.)
78+
- Expiration: Set `Custom` and then set the date to exactly a year in the future (the maximum allowed)
79+
- Repository Access: `Only select repositories` and select the desired repository.
80+
Alternatively, set `All repositories` if you wish to use the same token for all your repositories.
81+
- Repository Permissions:
82+
* `Administration: Read-only`: Required to read [Branch-Protection](https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection) settings.
83+
* `Metadata: Read-only` will be automatically set when you set `Administration`
84+
* `Webhooks: Read-only`: (Optional) required for the experimental [Webhook](https://github.com/ossf/scorecard/blob/main/docs/checks.md#webhooks) check.
85+
86+
**Disclaimer:** Scorecard uses these permissions solely to learn about the project's branch protection rules and webhooks.
87+
However, the token can read many of the project's settings
88+
(for a full list, see the queries marked `(read)` in [GitHub's documentation](https://docs.github.com/en/rest/overview/permissions-required-for-fine-grained-personal-access-tokens?apiVersion=2022-11-28#administration)).
89+
90+
"Classic" tokens with `repo` scope also work.
91+
However, these carry significantly higher risks compared to fine-grained PATs
92+
(see ["Classic" Personal Access Token (PAT) Requirements and Risks](#classic-personal-access-token-pat-requirements-and-risks))
93+
and are therefore strongly discouraged.
94+
95+
![image](/images/tokenscopes.png)
10396

10497
2. Copy the token value.
10598

10699
3. [Create a new repository secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) with the following settings (**Warning:** [GitHub encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) are accessible by all the workflows and maintainers of a repository.):
107100
- Name: `SCORECARD_TOKEN`
108101
- Value: the value of the token created in step 1 above.
109102

110-
4. (Optional) If you install Scorecard on a repository owned by an organization that uses [SAML SSO](https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/about-authentication-with-saml-single-sign-on), be sure to [enable SSO](https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on) for your PAT token.
103+
Note that fine-grained tokens expire after one year. You'll receive an email from GitHub when your token is about to expire, at which point you must regenerate it. Make sure to update the token string in your repository's secrets.
104+
105+
4. When you call the `ossf/scorecard-action` in your workflow, pass the token as `repo-token: ${{ secrets.SCORECARD_TOKEN }}`.
111106

112107
## View Results
113108

@@ -142,11 +137,9 @@ To verify that the Action is running successfully, click the repository's Action
142137
![image](/images/actionconfirm.png)
143138

144139
### Troubleshooting
145-
If the run has failed, the most likely reason is an authentication failure. If you are running Scorecards on a private repository, confirm that the Personal Access Token is saved as an encrypted secret within the same repository (see [Authentication](#authentication)). In addition, provide the `repo` scope to your PAT. (The `repo > public_repo` scope only provides access to public repositories).
140+
If the run has failed, the most likely reason is an authentication failure. Confirm that the Personal Access Token is saved as an encrypted secret within the same repository (see [Authentication](#authentication)). Also confirm that the PAT is still valid and hasn't expired or been revoked.
146141

147-
If you install Scorecards on a repository owned by an organization that uses [SAML SSO](https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/about-authentication-with-saml-single-sign-on) or if you see `403 Resource protected by organization SAML enforcement` in the logs, be sure to [enable SSO](https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on) for your PAT token (see [Authentication](#authentication)).
148-
149-
If you use a PAT saved as an encrypted secret and the run is still failing, confirm that you have not made any changes to the workflow yaml file that affected the syntax. Review the [workflow example](#workflow-example) and reset to the default values if necessary.
142+
If you have a valid PAT saved as an encrypted secret and the run is still failing, confirm that you have not made any changes to the workflow yaml file that affected the syntax. Review the [workflow example](#workflow-example) and reset to the default values if necessary.
150143

151144
## Manual Action Setup
152145

@@ -237,10 +230,9 @@ jobs:
237230
with:
238231
results_file: results.sarif
239232
results_format: sarif
240-
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
233+
# (Optional) fine-grained personal access token. Uncomment the `repo_token` line below if:
241234
# - you want to enable the Branch-Protection check on a *public* repository, or
242-
# - you are installing Scorecards on a *private* repository
243-
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
235+
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-fine-grained-pat-optional.
244236
# repo_token: ${{ secrets.SCORECARD_TOKEN }}
245237

246238
# Publish the results for public repositories to enable scorecard badges. For more details, see
@@ -264,3 +256,19 @@ jobs:
264256
with:
265257
sarif_file: results.sarif
266258
```
259+
260+
## "Classic" Personal Access Token (PAT) Requirements and Risks
261+
Certain features require a Personal Access Token (PAT).
262+
We recommend you use a fine-grained token as described in [Authentication](#authentication-with-fine-grained-pat-optional).
263+
A "classic" PAT also works, but we strongly discourage its use.
264+
265+
Due to a limitation of the "classic" tokens' permission model,
266+
the PAT needs [write permission to the repository](https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes) through the `repo` scope.
267+
**The PAT will be stored as a [GitHub encrypted secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets)
268+
and be accessible by all of the repository's workflows and maintainers.**
269+
This means another maintainer on your project could potentially use the token to impersonate you.
270+
If there is an exploitable bug in a workflow with write permissions,
271+
an external contributor could potentially exploit it to extract the PAT.
272+
273+
The only benefit of a "classic" PAT is that it can be set to never expire.
274+
However, we believe this does not outweigh the significantly higher risk of "classic" PATs compared to fine-grained PATs.

images/tokenscopes.png

249 KB
Loading

0 commit comments

Comments
 (0)