Set permissions for Github Actions in CI (#312)

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 #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 <bjorn.a.svensson@est.tech>
This commit is contained in:
Björn Svensson 2024-04-12 17:24:22 +02:00 committed by GitHub
parent 7b58f080a8
commit 1c282a9306
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 23 additions and 2 deletions

View File

@ -2,6 +2,9 @@ name: CI
on: [push, pull_request] on: [push, pull_request]
permissions:
contents: read
jobs: jobs:
test-ubuntu-latest: test-ubuntu-latest:

View File

@ -6,11 +6,16 @@ on:
# run weekly new vulnerability was added to the database # run weekly new vulnerability was added to the database
- cron: '0 0 * * 0' - cron: '0 0 * * 0'
permissions:
contents: read
jobs: jobs:
analyze: analyze:
name: Analyze name: Analyze
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.event_name != 'schedule' || github.repository == 'valkey-io/valkey' if: github.event_name != 'schedule' || github.repository == 'valkey-io/valkey'
permissions:
security-events: write
strategy: strategy:
fail-fast: false fail-fast: false

View File

@ -6,6 +6,8 @@ on:
- cron: '0 0 * * *' - cron: '0 0 * * *'
# Support manual execution # Support manual execution
workflow_dispatch: workflow_dispatch:
permissions:
contents: read
jobs: jobs:
coverity: coverity:
if: github.repository == 'valkey-io/valkey' if: github.repository == 'valkey-io/valkey'

View File

@ -28,6 +28,8 @@ on:
description: 'git branch or sha to use' description: 'git branch or sha to use'
default: 'unstable' default: 'unstable'
permissions:
contents: read
jobs: jobs:

View File

@ -6,6 +6,9 @@ on:
schedule: schedule:
- cron: '0 0 * * *' - cron: '0 0 * * *'
permissions:
contents: read
jobs: jobs:
test-external-standalone: test-external-standalone:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -29,7 +32,7 @@ jobs:
if: ${{ failure() }} if: ${{ failure() }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: test-external-server-log name: test-external-standalone-log
path: external-server.log path: external-server.log
test-external-cluster: test-external-cluster:
@ -81,5 +84,5 @@ jobs:
if: ${{ failure() }} if: ${{ failure() }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: test-external-server-log name: test-external-nodebug-log
path: external-server.log path: external-server.log

View File

@ -8,6 +8,9 @@ on:
paths: paths:
- 'src/commands/*.json' - 'src/commands/*.json'
permissions:
contents: read
jobs: jobs:
reply-schemas-linter: reply-schemas-linter:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -9,6 +9,9 @@ on:
push: push:
pull_request: pull_request:
permissions:
contents: read
jobs: jobs:
build: build:
name: Spellcheck name: Spellcheck