Skip to content

Commit

Permalink
Set finer-grain workflow permissions (#1163)
Browse files Browse the repository at this point in the history
* Set workflow read permissions and per-job write permissions.

* set pull-requests read at workflow level.

* Set contents read at job level.

* Explicitly set job-level read permissions.

* Add permissions to verify-devcontainers.
  • Loading branch information
jrhemstad authored Nov 29, 2023
1 parent 6ebff95 commit 72ab111
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build-and-test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ on:
container_image: {type: string, required: false}
run_tests: {type: boolean, required: false, default: true}

permissions:
contents: read

jobs:
build:
name: Build ${{inputs.test_name}}
permissions:
id-token: write
contents: read
uses: ./.github/workflows/run-as-coder.yml
with:
name: Build ${{inputs.test_name}}
Expand All @@ -27,6 +33,9 @@ jobs:
test:
needs: build
permissions:
id-token: write
contents: read
if: ${{ !cancelled() && ( needs.build.result == 'success' || needs.build.result == 'skipped' ) && inputs.run_tests}}
name: Test ${{inputs.test_name}}
uses: ./.github/workflows/run-as-coder.yml
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/dispatch-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ on:
devcontainer_version: {type: string, required: true}
is_windows: {type: boolean, required: true}

permissions:
contents: read

jobs:
# Using a matrix to dispatch to the build-and-test reusable workflow for each build configuration
# ensures that the build/test steps can overlap across different configurations. For example,
# the build step for CUDA 12.1 + gcc 9.3 can run at the same time as the test step for CUDA 11.0 + clang 11.
build_and_test_linux:
name: build and test linux
permissions:
id-token: write
contents: read
if: ${{ !inputs.is_windows }}
uses: ./.github/workflows/build-and-test-linux.yml
strategy:
Expand All @@ -30,6 +36,9 @@ jobs:

build_and_test_windows:
name: build and test windows
permissions:
id-token: write
contents: read
if: ${{ inputs.is_windows }}
uses: ./.github/workflows/build-and-test-windows.yml
strategy:
Expand Down
27 changes: 26 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ concurrency:
group: ${{ github.workflow }}-on-${{ github.event_name }}-from-${{ github.ref_name }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: read

jobs:
compute-matrix:
name: Compute matrix
Expand All @@ -53,6 +57,9 @@ jobs:
nvrtc:
name: NVRTC CUDA${{matrix.cuda}} C++${{matrix.std}}
permissions:
id-token: write
contents: read
needs: compute-matrix
if: ${{ !contains(github.event.head_commit.message, 'skip-tests') }}
uses: ./.github/workflows/run-as-coder.yml
Expand All @@ -69,6 +76,9 @@ jobs:
thrust:
name: Thrust CUDA${{ matrix.cuda_version }} ${{ matrix.compiler }}
permissions:
id-token: write
contents: read
needs: compute-matrix
uses: ./.github/workflows/dispatch-build-and-test.yml
strategy:
Expand All @@ -84,6 +94,9 @@ jobs:

cub:
name: CUB CUDA${{ matrix.cuda_version }} ${{ matrix.compiler }}
permissions:
id-token: write
contents: read
needs: compute-matrix
uses: ./.github/workflows/dispatch-build-and-test.yml
strategy:
Expand All @@ -99,6 +112,9 @@ jobs:

libcudacxx:
name: libcudacxx CUDA${{ matrix.cuda_version }} ${{ matrix.compiler }}
permissions:
id-token: write
contents: read
needs: compute-matrix
uses: ./.github/workflows/dispatch-build-and-test.yml
strategy:
Expand All @@ -114,6 +130,9 @@ jobs:

clang-cuda:
name: ${{matrix.lib}} ${{matrix.cpu}}/CTK${{matrix.cuda}}/clang-cuda
permissions:
id-token: write
contents: read
needs: compute-matrix
strategy:
fail-fast: false
Expand All @@ -129,6 +148,9 @@ jobs:
cccl-infra:
name: CCCL Infrastructure
permissions:
id-token: write
contents: read
needs: compute-matrix
if: ${{ !contains(github.event.head_commit.message, 'skip-tests') }}
strategy:
Expand All @@ -146,6 +168,9 @@ jobs:
verify-devcontainers:
name: Verify Dev Containers
permissions:
id-token: write
contents: read
uses: ./.github/workflows/verify-devcontainers.yml

# This job is the final job that runs after all other jobs and is used for branch protection status checks.
Expand All @@ -154,7 +179,7 @@ jobs:
ci:
runs-on: ubuntu-latest
name: CI
if: ${{ always() }} # need to use always() instead of !cancelled() because skipped jobs count as success
if: ${{ always() }} # need to use always() instead of !cancelled() because skipped jobs count as success
needs:
- clang-cuda
- cub
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/run-as-coder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ on:
command: {type: string, required: true}
env: { type: string, required: false, default: "" }

permissions:
contents: read

jobs:
run-as-coder:
name: ${{inputs.name}}
permissions:
id-token: write
contents: read
runs-on: ${{inputs.runner}}
container:
options: -u root
image: ${{inputs.image}}
env:
NVIDIA_VISIBLE_DEVICES: ${{ env.NVIDIA_VISIBLE_DEVICES }}
permissions:
id-token: write
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/verify-devcontainers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ defaults:
run:
shell: bash -euo pipefail {0}

permissions:
contents: read

jobs:
verify-make-devcontainers:
name: Verify devcontainer files are up-to-date
Expand Down

0 comments on commit 72ab111

Please sign in to comment.