From 8e01cedd743e1da2c747d6c077cf4d77a5e1e27c Mon Sep 17 00:00:00 2001 From: Carlos Gonzalez Date: Tue, 28 May 2024 13:26:04 +0100 Subject: [PATCH] [CP-Sec] Remediate OpenSSF flagged issues * Add top-level permissions to CodeQL workflow * Add top-level permissions to CI workflow * Pin docker image by hash * Pin github actions by hash --- .github/workflows/ci.yml | 23 +++++++++++++---------- .github/workflows/codeql.yml | 8 +++++--- .github/workflows/scorecard.yml | 2 +- ci/Dockerfile | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a56a99..bf1d829 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,9 @@ name: Continuous Integration on: [push, pull_request] +permissions: + contents: read + env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} @@ -12,10 +15,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - name: clang-format - uses: jidicula/clang-format-action@v4.13.0 + uses: jidicula/clang-format-action@c74383674bf5f7c69f60ce562019c1c94bc1421a # v4.13.0 with: clang-format-version: '17' check-path: 'src' @@ -30,10 +33,10 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - name: Path filter - uses: dorny/paths-filter@v3 + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 id: changes with: filters: | @@ -42,11 +45,11 @@ jobs: - name: Set up Docker Buildx if: steps.changes.outputs.container == 'true' - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0 - name: Log in to the Container registry if: steps.changes.outputs.container == 'true' - uses: docker/login-action@v3 + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -54,7 +57,7 @@ jobs: - name: Extract metadata id: meta - uses: docker/metadata-action@v5 + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | @@ -65,7 +68,7 @@ jobs: - name: Build and push if: steps.changes.outputs.container == 'true' - uses: docker/build-push-action@v5 + uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 with: context: '{{defaultContext}}:ci' push: true @@ -92,7 +95,7 @@ jobs: password: ${{ secrets.github_token }} steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 with: submodules: "recursive" @@ -118,7 +121,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - name: Configure CMake (no graphics) run: > diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 6c94ce6..967c673 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -22,6 +22,8 @@ on: env: BUILD_TYPE: Release +permissions: {} + jobs: analyze: name: Analyze (${{ matrix.language }}) @@ -63,7 +65,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 # Handle git 'dubious ownership/safe.directory' container warnings (reduces related CodeQL verbosity) - name: Add safe Git directory @@ -72,7 +74,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v3 + uses: github/codeql-action/init@9fdb3e49720b44c48891d036bb502feb25684276 # v3.25.6 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} @@ -107,6 +109,6 @@ jobs: run: cmake --build ${{github.workspace}}/build -- -k -j - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 + uses: github/codeql-action/analyze@9fdb3e49720b44c48891d036bb502feb25684276 # v3.25.6 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index fe40cb4..31d7007 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -39,7 +39,7 @@ jobs: # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF # format to the repository Actions tab. - name: "Upload artifact" - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 with: name: SARIF file path: results.sarif diff --git a/ci/Dockerfile b/ci/Dockerfile index 9ae0d05..a59043d 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 +FROM ubuntu:24.04@sha256:3f85b7caad41a95462cf5b787d8a04604c8262cdcdf9a472b8c52ef83375fe15 # Get basic dependencies from Ubuntu repositories RUN apt update && apt -y install wget gpg git cmake ninja-build \