From a6824d85cf30a2cff39ed982e9279e32e7ecfb03 Mon Sep 17 00:00:00 2001 From: StepSecurity Bot Date: Mon, 5 Feb 2024 20:47:24 -0800 Subject: [PATCH] [StepSecurity] Apply security best practices (#404) * [StepSecurity] Apply security best practices Signed-off-by: StepSecurity Bot * remove Harden Runner from the PR. --------- Signed-off-by: StepSecurity Bot Co-authored-by: Tatsat Mishra --- .github/dependabot.yml | 5 ++ .github/workflows/build.yml | 11 ++-- .github/workflows/codeql-analysis.yml | 13 +++-- .github/workflows/dependency-review.yml | 22 ++++++++ .github/workflows/golangci-lint.yml | 6 +-- .github/workflows/release.yml | 33 ++++++------ .github/workflows/scorecards.yml | 71 +++++++++++++++++++++++++ .github/workflows/website.yaml | 4 +- .pre-commit-config.yaml | 18 +++++++ 9 files changed, 154 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/dependency-review.yml 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 bf494703..a1837753 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,3 +9,8 @@ updates: directory: "/" # Location of package manifests schedule: interval: "daily" + +- package-ecosystem: github-actions + directory: / + schedule: + interval: daily diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c004faf..fc7b5d19 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,6 +11,9 @@ on: - docs/** - README.md +permissions: + contents: read + jobs: build: name: Build @@ -24,10 +27,10 @@ jobs: GO111MODULE: on steps: - name: Check out code into the Go module directory - uses: actions/checkout@v4 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 with: go-version-file: "go.mod" cache: false @@ -83,8 +86,8 @@ jobs: run: make - name: Snap Build - uses: snapcore/action-build@v1 + uses: snapcore/action-build@2096990827aa966f773676c8a53793c723b6b40f # v1.2.0 id: snapbuild - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ed1e0e7c..49095b4c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -26,6 +26,9 @@ on: schedule: - cron: '40 10 * * 5' +permissions: + contents: read + jobs: analyze: name: Analyze @@ -46,18 +49,18 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 # NOTE: this is a workaround for codeql go toolchain setup # ref: https://github.com/github/codeql-action/issues/1842#issuecomment-1704398087 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 with: go-version-file: go.mod # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@2f93e4319b2f04a2efc38fa7f78bd681bc3f7b2f # v2.23.2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -71,7 +74,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@2f93e4319b2f04a2efc38fa7f78bd681bc3f7b2f # v2.23.2 # ℹī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun @@ -84,6 +87,6 @@ jobs: # ./location_of_script_within_repo/buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@2f93e4319b2f04a2efc38fa7f78bd681bc3f7b2f # v2.23.2 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 00000000..a5252162 --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,22 @@ +# Dependency Review Action +# +# This Action will scan dependency manifest files that change as part of a Pull Request, +# surfacing known-vulnerable versions of the packages declared or updated in the PR. +# Once installed, if the workflow run is marked as required, +# PRs introducing known-vulnerable packages will be blocked from merging. +# +# Source repository: https://github.com/actions/dependency-review-action +name: 'Dependency Review' +on: [pull_request] + +permissions: + contents: read + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: 'Checkout Repository' + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - name: 'Dependency Review' + uses: actions/dependency-review-action@0efb1d1d84fc9633afcdaad14c485cbbc90ef46c # v2.5.1 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 2aedb6ac..33f7df5c 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -26,13 +26,13 @@ jobs: deployments: read packages: none steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 with: go-version-file: "go.mod" cache: false - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version version: v1.54 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b40b0333..bfc5fe22 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,6 +2,9 @@ name: Release on: workflow_dispatch: +permissions: + contents: read + jobs: build: name: Build @@ -15,10 +18,10 @@ jobs: GO111MODULE: on steps: - name: Check out code into the Go module directory - uses: actions/checkout@v4 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 with: go-version-file: "go.mod" cache: false @@ -27,7 +30,7 @@ jobs: # Read changelog and read versions etc. - name: Check version is mentioned in Changelog.md id: changelog_reader - uses: mindsers/changelog-reader-action@v2 + uses: mindsers/changelog-reader-action@b97ce03a10d9bdbb07beb491c76a5a01d78cd3ef # v2.2.2 with: validation_depth: 10 path: "CHANGELOG.md" @@ -43,7 +46,7 @@ jobs: - name: Create Kubelogin Release id: create_release if: ${{ steps.check-tag-exists.outputs.exists == 'false'}} - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -99,46 +102,46 @@ jobs: run: make - name: Snap Build - uses: snapcore/action-build@v1 + uses: snapcore/action-build@2096990827aa966f773676c8a53793c723b6b40f # v1.2.0 id: snapbuild - name: Zip - uses: montudor/action-zip@v1 + uses: montudor/action-zip@a8e75c9faefcd80fac3baf53ef40b9b119d5b702 # v1 with: args: zip -qq -r kubelogin.zip bin - name: Zip (win-amd64) - uses: montudor/action-zip@v1 + uses: montudor/action-zip@a8e75c9faefcd80fac3baf53ef40b9b119d5b702 # v1 with: args: zip -qq kubelogin-win-amd64.zip bin/windows_amd64/kubelogin.exe - name: Zip (win-arm64) - uses: montudor/action-zip@v1 + uses: montudor/action-zip@a8e75c9faefcd80fac3baf53ef40b9b119d5b702 # v1 with: args: zip -qq kubelogin-win-arm64.zip bin/windows_arm64/kubelogin.exe - name: Zip (darwin-amd64) - uses: montudor/action-zip@v1 + uses: montudor/action-zip@a8e75c9faefcd80fac3baf53ef40b9b119d5b702 # v1 with: args: zip -qq kubelogin-darwin-amd64.zip bin/darwin_amd64/kubelogin - name: Zip (darwin-arm64) - uses: montudor/action-zip@v1 + uses: montudor/action-zip@a8e75c9faefcd80fac3baf53ef40b9b119d5b702 # v1 with: args: zip -qq kubelogin-darwin-arm64.zip bin/darwin_arm64/kubelogin - name: Zip (linux-amd64) - uses: montudor/action-zip@v1 + uses: montudor/action-zip@a8e75c9faefcd80fac3baf53ef40b9b119d5b702 # v1 with: args: zip -qq kubelogin-linux-amd64.zip bin/linux_amd64/kubelogin - name: Zip (linux-arm64) - uses: montudor/action-zip@v1 + uses: montudor/action-zip@a8e75c9faefcd80fac3baf53ef40b9b119d5b702 # v1 with: args: zip -qq kubelogin-linux-arm64.zip bin/linux_arm64/kubelogin - name: Zip (linux-armv7) - uses: montudor/action-zip@v1 + uses: montudor/action-zip@a8e75c9faefcd80fac3baf53ef40b9b119d5b702 # v1 with: args: zip -qq kubelogin-linux-armv7.zip bin/linux_armv7/kubelogin @@ -154,7 +157,7 @@ jobs: sha256sum kubelogin-linux-armv7.zip > kubelogin-linux-armv7.zip.sha256 - name: Publish - uses: skx/github-action-publish-binaries@master + uses: skx/github-action-publish-binaries@44887b225ceca96efd8a912d39c09ad70312af31 # master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -162,7 +165,7 @@ jobs: releaseId: ${{ steps.create_release.outputs.id }} - name: Publish to Snap Store - uses: snapcore/action-publish@v1 + uses: snapcore/action-publish@214b86e5ca036ead1668c79afb81e550e6c54d40 # v1.2.0 env: SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPSTORE_LOGIN }} with: diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml new file mode 100644 index 00000000..47fccef6 --- /dev/null +++ b/.github/workflows/scorecards.yml @@ -0,0 +1,71 @@ +# 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: "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@2f93e4319b2f04a2efc38fa7f78bd681bc3f7b2f # v2.23.2 + with: + sarif_file: results.sarif diff --git a/.github/workflows/website.yaml b/.github/workflows/website.yaml index 8de6632f..5679bf7d 100644 --- a/.github/workflows/website.yaml +++ b/.github/workflows/website.yaml @@ -15,7 +15,7 @@ jobs: deploy: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 with: submodules: true fetch-depth: 0 @@ -30,7 +30,7 @@ jobs: run: make -C docs/book build - name: Deploy - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847 # v3.9.3 if: ${{ github.ref == 'refs/heads/main' }} with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..e8e93873 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +repos: +- repo: https://github.com/gitleaks/gitleaks + rev: v8.16.3 + hooks: + - id: gitleaks +- repo: https://github.com/golangci/golangci-lint + rev: v1.52.2 + hooks: + - id: golangci-lint +- repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: shellcheck +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace