Skip to content

Commit

Permalink
GitHub Workflows security hardening (#1071)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebookincubator/velox#6969

This PR adds explicit [permissions section](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions) to workflows. This is a security best practice because by default workflows run with [extended set of permissions](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token) (except from `on: pull_request` [from external forks](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)). By specifying any permission explicitly all others are set to none. By using the principle of least privilege the damage a compromised workflow can do (because of an [injection](https://securitylab.github.com/research/github-actions-untrusted-input/) or compromised third party tool or action) is restricted.
It is recommended to have [most strict permissions on the top level](https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions) and grant write permissions on [job level](https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs) case by case.

Pull Request resolved: #1071

Reviewed By: xavierd

Differential Revision: D50095358

Pulled By: genevievehelsel

fbshipit-source-id: 4fc80c6b7c48df08207f68420b48a90ffcfddf27
  • Loading branch information
sashashura authored and facebook-github-bot committed Oct 11, 2023
1 parent 1e79219 commit 5be84ab
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/getdeps_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
branches:
- main

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
build:
runs-on: ubuntu-20.04
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/getdeps_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
branches:
- main

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
build:
runs-on: macOS-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/getdeps_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
branches:
- main

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
build:
runs-on: windows-2019
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ name: release
push:
tags:
- v*

permissions:
contents: write # to create a release

jobs:
prepare:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
tags:
- v*

permissions:
contents: write # to create a release

jobs:
prepare:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions build/fbcode_builder/getdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,9 @@ def write_job_for_platform(self, platform, args): # noqa: C901
on:{run_on}
permissions:
contents: read # to fetch code (actions/checkout)
jobs:
"""
)
Expand Down

0 comments on commit 5be84ab

Please sign in to comment.