Browse Source

chore: restrict GitHub workflow permissions - future-proof (#1873)

See https://github.com/swiftlang/github-workflows/issues/167 for
additional context

This approach aligns with security best practices, as detailed in the
following documentation:

-
https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions
-
https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#defining-access-for-the-github_token-scopes
-
https://openssf.org/blog/2024/08/12/mitigating-attack-vectors-in-github-workflows/


The default GITHUB_TOKEN permissions are defined at the repository
level. This PR modifies the workflow-level overrides to conform to
OpenSSF best practices -> defense in depth.

Allow me to quote OpenSSF:

https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions

> The highest score is awarded when the permissions definitions in each
workflow's yaml file are set as read-only at the top level and the
required write permissions are declared at the run-level.”

> Remediation steps
> - Set top-level permissions as read-all or contents: read as described
in GitHub's documentation.
> - Set any required write permissions at the job-level. Only set the
permissions required for that job; do not set permissions: write-all at
the job level.


Compare to the LLVM project:

Top-level: contents read, e.g.
https://github.com/swiftlang/llvm-project/blob/next/.github/workflows/build-ci-container-windows.yml#L3-L4
-> this makes it future-proof

Job-level: Allow write permissions as needed, e.g.
https://github.com/swiftlang/llvm-project/blob/next/.github/workflows/build-ci-container-windows.yml#L53-L58

Signed-off-by: Melissa Kilby <mkilby@apple.com>
Melissa Kilby 5 tháng trước cách đây
mục cha
commit
60facae26c

+ 2 - 0
.github/workflows/build.yml

@@ -2,6 +2,8 @@ name: Build and Test
 
 # NOTE: If making changes to most of the steps, please also look to update
 # regular_conformance.yml also.
+permissions:
+  contents: read
 
 on:
   push:

+ 3 - 0
.github/workflows/check_upstream_protos.yml

@@ -1,5 +1,8 @@
 name: Check Upstream Proto Files
 
+permissions:
+  contents: read
+
 on:
   schedule:
     # Every Sunday at 4am.

+ 3 - 0
.github/workflows/draft_release_protoc_artifactbundle.yml

@@ -1,5 +1,8 @@
 name: Draft release protoc artifactbundle
 
+permissions:
+  contents: read
+
 on:
   workflow_dispatch:
 

+ 3 - 0
.github/workflows/pull_request_label.yml

@@ -1,5 +1,8 @@
 name: PR label
 
+permissions:
+  contents: read
+
 on:
   pull_request:
     types: [labeled, unlabeled, opened, reopened, synchronize]

+ 2 - 0
.github/workflows/regular_conformance.yml

@@ -12,6 +12,8 @@ name: Run Conformance Tests
 
 # NOTE: If making changes to most of the steps, please also look to update
 # build.yml also.
+permissions:
+  contents: read
 
 on:
   schedule: