Skip to content

Commit

Permalink
Add permissions to example workflows, restrict permissions in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed May 1, 2022
1 parent 3bf80f8 commit 0389cb5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
schedule:
- cron: '0 16 * * *'
workflow_dispatch:
permissions: {}

jobs:
test:
Expand Down Expand Up @@ -122,6 +123,9 @@ jobs:
github.event.sender.login != 'dependabot[bot]' &&
( github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository )
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write

steps:
- name: Checkout
Expand Down Expand Up @@ -152,6 +156,10 @@ jobs:
github.event.sender.login != 'dependabot[bot]' &&
( github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository )
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
security-events: write

steps:
- name: Checkout
Expand Down Expand Up @@ -213,6 +221,10 @@ jobs:
github.event.sender.login != 'dependabot[bot]' &&
( github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository )
runs-on: ${{ matrix.os }}
permissions:
checks: write
pull-requests: write

strategy:
fail-fast: false
max-parallel: 3
Expand Down Expand Up @@ -291,6 +303,9 @@ jobs:
github.event.sender.login != 'dependabot[bot]' &&
( github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository )
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write

steps:
- name: Checkout
Expand Down Expand Up @@ -332,6 +347,9 @@ jobs:
github.event.sender.login != 'dependabot[bot]' &&
( github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository )
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write

steps:
- name: Checkout
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/unit-test-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ on:
workflows: ["CI/CD"]
types:
- completed
permissions: {}

jobs:
debug:
name: Debug
runs-on: ubuntu-latest

steps:
- name: Debug Action
uses: hmarr/debug-action@v2.0.1

unit-test-results:
name: Unit Test Results (reference)
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'skipped'
runs-on: ubuntu-latest
permissions:
actions: read
checks: write
pull-requests: write

steps:
- name: Download and Extract Artifacts
Expand Down
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ The following permissions are required in **private** GitHub repos:

```yaml
permissions:
checks: write
contents: read
issues: read
checks: write
pull-requests: write
```

Expand Down Expand Up @@ -266,6 +266,7 @@ are then all downloaded by your publish job.
name: CI
on: [push]
permissions: {}
jobs:
build-and-test:
Expand Down Expand Up @@ -300,6 +301,17 @@ jobs:
name: "Publish Unit Tests Results"
needs: build-and-test
runs-on: ubuntu-latest
permissions:
checks: write
# only needed unless run with comment_mode: off
pull-requests: write
# only needed for private repository
contents: read
# only needed for private repository
issues: read
if: always()
steps:
Expand Down Expand Up @@ -382,11 +394,24 @@ on:
workflows: ["CI"]
types:
- completed
permissions: {}
jobs:
unit-test-results:
name: Unit Test Results
runs-on: ubuntu-latest
permissions:
actions: read
checks: write
# only needed unless run with comment_mode: off
pull-requests: write
# only needed for private repository
contents: read
# only needed for private repository
issues: read
if: github.event.workflow_run.conclusion != 'skipped'
steps:
Expand Down

0 comments on commit 0389cb5

Please sign in to comment.