Skip to content

Commit

Permalink
Set permissions for Github Actions in CI (valkey-io#312)
Browse files Browse the repository at this point in the history
This sets the default permission for current CI workflows to only be
able to read from the repository (scope: "contents").
When a used Github Action require additional permissions (like CodeQL)
we grant that permission on job-level instead.

This means that a compromised action will not be able to modify the repo
or even steal secrets since all other permission-scopes are implicit set
to "none", i.e. not permitted. This is recommended by
[OpenSSF](https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions).

This PR includes a small fix for the possibility of missing server logs
artifacts, found while verifying the permission.
The `upload-artifact@v3` action will replace artifacts which already
exists. Since both CI-jobs `test-external-standalone` and
`test-external-nodebug` uses the same artifact name, when both jobs
fail, we only get logs from the last finished job. This can be avoided
by using unique artifact names.

This PR is part of valkey-io#211

More about permissions and scope can be found here:

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions

---------

Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv authored Apr 12, 2024
1 parent 7b58f08 commit 1c282a9
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: CI

on: [push, pull_request]

permissions:
contents: read

jobs:

test-ubuntu-latest:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ on:
# run weekly new vulnerability was added to the database
- cron: '0 0 * * 0'

permissions:
contents: read

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
if: github.event_name != 'schedule' || github.repository == 'valkey-io/valkey'
permissions:
security-events: write

strategy:
fail-fast: false
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
- cron: '0 0 * * *'
# Support manual execution
workflow_dispatch:
permissions:
contents: read
jobs:
coverity:
if: github.repository == 'valkey-io/valkey'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ on:
description: 'git branch or sha to use'
default: 'unstable'

permissions:
contents: read

jobs:

Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/external.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
schedule:
- cron: '0 0 * * *'

permissions:
contents: read

jobs:
test-external-standalone:
runs-on: ubuntu-latest
Expand All @@ -29,7 +32,7 @@ jobs:
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: test-external-server-log
name: test-external-standalone-log
path: external-server.log

test-external-cluster:
Expand Down Expand Up @@ -81,5 +84,5 @@ jobs:
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: test-external-server-log
name: test-external-nodebug-log
path: external-server.log
3 changes: 3 additions & 0 deletions .github/workflows/reply-schemas-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
paths:
- 'src/commands/*.json'

permissions:
contents: read

jobs:
reply-schemas-linter:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/spell-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
push:
pull_request:

permissions:
contents: read

jobs:
build:
name: Spellcheck
Expand Down

0 comments on commit 1c282a9

Please sign in to comment.