From acc4095ed8e848a68ff0c54680b577e3e709df03 Mon Sep 17 00:00:00 2001 From: StepSecurity Bot Date: Thu, 14 Mar 2024 22:56:12 -0700 Subject: [PATCH] chore: ci security hardening (#16) Signed-off-by: StepSecurity Bot Signed-off-by: Sam Gammon --- .github/dependabot.yml | 26 ++------ .github/workflows/ci.build-test.yml | 4 +- .github/workflows/ci.dependency-graph.yml | 2 +- .github/workflows/deploy.site.yml | 24 +++++-- .github/workflows/scorecards.yml | 76 +++++++++++++++++++++++ .pre-commit-config.yaml | 19 ++++++ 6 files changed, 121 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/scorecards.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 01dfde6d..87942533 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -24,26 +24,8 @@ updates: schedule: interval: daily - ## Gradle for tooling projects. - - package-ecosystem: gradle - directory: /tools - schedule: - interval: daily - - ## Maven for tooling projects. - - package-ecosystem: maven - directory: /tools - schedule: - interval: daily - - ## Gradle for sample projects. - - package-ecosystem: gradle - directory: /samples - schedule: - interval: daily - - ## Maven for sample projects. - - package-ecosystem: maven - directory: /samples + ## Jekyll dependencies. + - package-ecosystem: bundler + directory: / schedule: - interval: daily + interval: weekly diff --git a/.github/workflows/ci.build-test.yml b/.github/workflows/ci.build-test.yml index ff96076a..d05a9b45 100644 --- a/.github/workflows/ci.build-test.yml +++ b/.github/workflows/ci.build-test.yml @@ -28,14 +28,14 @@ jobs: persist-credentials: false submodules: true - name: "Setup: Java 21" - uses: actions/setup-java@v4 + uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: java-version: '21' distribution: 'zulu' - name: "Setup: Bazelisk" uses: bazelbuild/setup-bazelisk@b39c379c82683a5f25d34f0d062761f62693e0b2 # v3.0.0 - name: "Setup: Cache" - uses: actions/cache@v4 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1 with: path: | jdk diff --git a/.github/workflows/ci.dependency-graph.yml b/.github/workflows/ci.dependency-graph.yml index 601c2f29..0a606a57 100644 --- a/.github/workflows/ci.dependency-graph.yml +++ b/.github/workflows/ci.dependency-graph.yml @@ -31,7 +31,7 @@ jobs: with: persist-credentials: false - name: "Setup: Java 21" - uses: actions/setup-java@v4 + uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: java-version: '21' distribution: 'zulu' diff --git a/.github/workflows/deploy.site.yml b/.github/workflows/deploy.site.yml index be7634ed..162a316e 100644 --- a/.github/workflows/deploy.site.yml +++ b/.github/workflows/deploy.site.yml @@ -21,9 +21,14 @@ jobs: - name: Harden Runner uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 with: - egress-policy: audit + disable-sudo: true + egress-policy: block + allowed-endpoints: > + api.github.com:443 + github.com:443 + index.rubygems.org:443 - name: "Setup: Checkout" - uses: actions/checkout@v4 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: persist-credentials: false - name: "Setup: Ruby" @@ -34,13 +39,13 @@ jobs: cache-version: 0 - name: "Setup: Pages" id: pages - uses: actions/configure-pages@v4 + uses: actions/configure-pages@1f0c5cde4bc74cd7e1254d0cb4de8d49e9068c7d # v4.0.0 - name: "Build: Jekyll" run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}" env: JEKYLL_ENV: production - name: "Artifact: Site" - uses: actions/upload-pages-artifact@v3 + uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1 deploy: name: "Deploy Site" @@ -50,6 +55,15 @@ jobs: runs-on: ubuntu-latest needs: build steps: + - name: Harden Runner + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + with: + disable-sudo: true + egress-policy: block + allowed-endpoints: > + api.github.com:443 + github.com:443 + index.rubygems.org:443 - name: "Deploy: Pages" id: deployment - uses: actions/deploy-pages@v4 + uses: actions/deploy-pages@decdde0ac072f6dcbe43649d82d9c635fff5b4e4 # v4.0.4 diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml new file mode 100644 index 00000000..68752b28 --- /dev/null +++ b/.github/workflows/scorecards.yml @@ -0,0 +1,76 @@ +# This workflow uses actions that are not certified by GitHub. They are provided +# by a third-party and are governed by separate terms of service, privacy +# policy, and support documentation. + +name: Scorecard supply-chain security +on: + # For Branch-Protection check. Only the default branch is supported. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection + branch_protection_rule: + # To guarantee Maintained check is occasionally updated. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained + schedule: + - cron: '20 7 * * 2' + push: + branches: ["main"] + +# Declare default permissions as read only. +permissions: read-all + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + permissions: + # Needed to upload the results to code-scanning dashboard. + security-events: write + # Needed to publish results and get a badge (see publish_results below). + id-token: write + contents: read + actions: read + + steps: + - name: Harden Runner + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + with: + egress-policy: audit + + - name: "Checkout code" + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # v2.0.6 + with: + results_file: results.sarif + results_format: sarif + # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: + # - you want to enable the Branch-Protection check on a *public* repository, or + # - you are installing Scorecards on a *private* repository + # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. + # repo_token: ${{ secrets.SCORECARD_TOKEN }} + + # Public repositories: + # - Publish results to OpenSSF REST API for easy access by consumers + # - Allows the repository to include the Scorecard badge. + # - See https://github.com/ossf/scorecard-action#publishing-results. + # For private repositories: + # - `publish_results` will always be set to `false`, regardless + # of the value entered here. + publish_results: true + + # 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@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard. + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@e56cfd0877b4826be144d11aa31e6c64a55828e9 # v2.24.7 + with: + sarif_file: results.sarif diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..99648ea8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +repos: +- repo: https://github.com/gherynos/pre-commit-java + rev: v0.2.4 + hooks: + - id: Checkstyle +- repo: https://github.com/gitleaks/gitleaks + rev: v8.16.3 + hooks: + - id: gitleaks +- repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: RuboCop + - id: shellcheck +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace