Skip to content

Commit bfa3f0d

Browse files
📖 Document the GitHub action workflow restrictions when publishing results. (#1156)
* Update example workflow. Signed-off-by: Spencer Schrock <[email protected]> * Add section on workflow restrictions. Signed-off-by: Spencer Schrock <[email protected]> --------- Signed-off-by: Spencer Schrock <[email protected]>
1 parent a5c2880 commit bfa3f0d

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

README.md

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,9 @@ The Scorecards GitHub Action is free for all public repositories. Private reposi
1010

1111
Starting from scorecard-action:v2, `GITHUB_TOKEN` permissions or job permissions needs to include
1212
`id-token: write` for `publish_results: true`. This is needed to access GitHub's
13-
OIDC token which verifies the authenticity of the result when publishing it.
13+
OIDC token which verifies the authenticity of the result when publishing it. See details [here](#publishing-results)
1414

15-
scorecard-action:v2 has a new requirement for the job running the ossf/scorecard-action step. The steps running in this job must belong to this approved list of GitHub actions:
16-
- "actions/checkout"
17-
- "actions/upload-artifact"
18-
- "github/codeql-action/upload-sarif"
19-
- "ossf/scorecard-action"
20-
21-
If you are using custom steps in the job, it may fail.
22-
We understand that this is restrictive, but currently it's necessary to ensure the integrity of the results that we publish, since GitHub workflow steps run in the same environment as the job they belong to.
23-
If possible, we will work on making this feature more flexible so we can drop this requirement in the future.
15+
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).
2416
________
2517
[Personal Access Token (PAT) Requirements and Risks](#personal-access-token-pat-requirements-and-risks)
2618

@@ -38,6 +30,7 @@ ________
3830
[Manual Action Setup](#manual-action-setup)
3931
- [Inputs](#inputs)
4032
- [Publishing Results](#publishing-results)
33+
- [Workflow Restrictions](#workflow-restrictions)
4134
- [Uploading Artifacts](#uploading-artifacts)
4235
- [Workflow Example](#workflow-example)
4336
________
@@ -169,15 +162,38 @@ First, [create a new file](https://docs.github.com/en/repositories/working-with-
169162
| `result_file` | yes | The file that contains the results. |
170163
| `result_format` | yes | The format in which to store the results [json \| sarif]. For GitHub's scanning dashboard, select `sarif`. |
171164
| `repo_token` | no | PAT token with write repository access. Follow [these steps](#authentication-with-pat) to create it. |
172-
| `publish_results` | recommended | This will allow you to display a badge on your repository to show off your hard work (release scheduled for Q2'22). See details [here](#publishing-results).|
165+
| `publish_results` | recommended | This will allow you to display a badge on your repository to show off your hard work. See details [here](#publishing-results).|
173166

174167
### Publishing Results
175168
The Scorecard team runs a weekly scan of public GitHub repositories in order to track
176169
the overall security health of the open source ecosystem. The results of the scans are [publicly
177170
available](https://github.com/ossf/scorecard#public-data).
178171
Setting `publish_results: true` replaces the results of the team's weekly scans with your own scan results,
179172
helping us scale by cutting down on repeated workflows and GitHub API requests.
180-
This option is also needed to enable badges on the repository (release scheduled for Q2'22).
173+
This option is also needed to enable badges on the repository.
174+
175+
### Workflow Restrictions
176+
177+
If [publishing results](#publishing-results), our API [enforces certain rules](https://github.com/ossf/scorecard-webapp/blob/9c2f66d5f6ff56ca4a4ac2fba6ec8dcc5379d31c/app/server/post_results.go#L184-L187) on the producing workflow, which may reject the results and cause the Scorecard Action run to fail.
178+
We understand that this is restrictive, but currently it's necessary to ensure the integrity of our API dataset, since GitHub workflow steps run in the same environment as the job they belong to.
179+
If possible, we will work on making this feature more flexible so we can drop this requirement in the future.
180+
181+
#### Global workflow restrictions
182+
183+
* The workflow can't contain top level env vars or defaults.
184+
* No workflow level write permissions.
185+
* Only the job with `ossf/scorecard-action` can use `id-token: write` permissions.
186+
187+
#### Restrictions on the job containing `ossf/scorecard-action`
188+
* No job level env vars or defaults.
189+
* No containers or services
190+
* The job should run on one of the [Ubuntu hosted runners](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners)
191+
* The steps running in this job must belong to this approved list of GitHub actions.
192+
* "actions/checkout"
193+
* "actions/upload-artifact"
194+
* "github/codeql-action/upload-sarif"
195+
* "ossf/scorecard-action"
196+
* "step-security/harden-runner"
181197

182198
### Uploading Artifacts
183199
The Scorecards Action uses the [artifact uploader action](https://github.com/actions/upload-artifact) to upload results in SARIF format to the Actions tab. These results are available to anybody for five days after the run to help with debugging. To disable the upload, comment out the `Upload Artifact` value in the Workflow Example.
@@ -187,7 +203,7 @@ Note: if you disable this option, the results of the Scorecards Action run will
187203
### Workflow Example
188204

189205
```yml
190-
name: Scorecards supply-chain security
206+
name: Scorecard analysis workflow
191207
on:
192208
# Only the default branch is supported.
193209
branch_protection_rule:
@@ -202,24 +218,22 @@ permissions: read-all
202218

203219
jobs:
204220
analysis:
205-
name: Scorecards analysis
221+
name: Scorecard analysis
206222
runs-on: ubuntu-latest
207223
permissions:
208-
# Needed to upload the results to code-scanning dashboard.
224+
# Needed if using Code scanning alerts
209225
security-events: write
210-
# Used to receive a badge. (Upcoming feature)
226+
# Needed for GitHub OIDC token if publish_results is true
211227
id-token: write
212-
actions: read
213-
contents: read
214228

215229
steps:
216230
- name: "Checkout code"
217-
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
231+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
218232
with:
219233
persist-credentials: false
220234

221235
- name: "Run analysis"
222-
uses: ossf/scorecard-action@3e15ea8318eee9b333819ec77a36aca8d39df13e # tag=v1.1.1
236+
uses: ossf/scorecard-action@80e868c13c90f172d68d1f4501dee99e2479f7af # v2.1.3
223237
with:
224238
results_file: results.sarif
225239
results_format: sarif
@@ -238,15 +252,15 @@ jobs:
238252
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
239253
# format to the repository Actions tab.
240254
- name: "Upload artifact"
241-
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # tag=v3.0.0
255+
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
242256
with:
243257
name: SARIF file
244258
path: results.sarif
245259
retention-days: 5
246260

247-
# Upload the results to GitHub's code scanning dashboard.
248-
- name: "Upload to code-scanning"
249-
uses: github/codeql-action/upload-sarif@5f532563584d71fdef14ee64d17bafb34f751ce5 # tag=v1.0.26
261+
# required for Code scanning alerts
262+
- name: "Upload SARIF results to code scanning"
263+
uses: github/codeql-action/upload-sarif@83f0fe6c4988d98a455712a27f0255212bba9bd4 # v2.3.6
250264
with:
251265
sarif_file: results.sarif
252266
```

0 commit comments

Comments
 (0)