From e41dbd973c24d499832ac575817ddb7cb279cc4e Mon Sep 17 00:00:00 2001 From: StepSecurity Bot Date: Mon, 28 Oct 2024 15:22:10 +0000 Subject: [PATCH] [StepSecurity] Apply security best practices Signed-off-by: StepSecurity Bot --- .github/dependabot.yml | 5 ++ .github/workflows/ci.yaml | 38 ++++++++- .github/workflows/codeql.yml | 78 +++++++++++++++++++ .github/workflows/db-performance-test.yaml | 25 ++++-- .github/workflows/dependency-review.yml | 27 +++++++ .github/workflows/nightly-release.yaml | 5 ++ .github/workflows/postmerge.yaml | 7 +- .github/workflows/release.yaml | 28 ++++++- .github/workflows/reusable-local-build.yaml | 12 ++- .github/workflows/scorecard.yml | 5 ++ .pre-commit-config.yaml | 18 +++++ pkg/assembler/backends/ent/migrate/Dockerfile | 2 +- 12 files changed, 233 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/dependency-review.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index df24d6ec42..0107e6fa02 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -11,3 +11,8 @@ updates: directory: "/" schedule: interval: "weekly" + + - package-ecosystem: docker + directory: /pkg/assembler/backends/ent/migrate + schedule: + interval: daily diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 81393f8f19..9793a2ab39 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,6 +35,11 @@ jobs: runs-on: ubuntu-latest name: CI for integration tests steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v3 - name: setup-go @@ -46,7 +51,7 @@ jobs: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - name: Install atlas - uses: ariga/setup-atlas@v0 + uses: ariga/setup-atlas@d52cd13fed38eca914fa57071155a4644fd6f820 # v0.2 - name: Setup the project run: go mod download - name: Run backends @@ -66,6 +71,11 @@ jobs: runs-on: ubuntu-latest name: CI for unit tests steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v3 - name: setup-go @@ -77,7 +87,7 @@ jobs: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - name: Install atlas - uses: ariga/setup-atlas@v0 + uses: ariga/setup-atlas@d52cd13fed38eca914fa57071155a4644fd6f820 # v0.2 - name: Setup the project run: go mod download - name: Run tests @@ -87,6 +97,11 @@ jobs: name: Static Analysis runs-on: ubuntu-latest steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v3 - name: setup-go @@ -94,7 +109,7 @@ jobs: with: go-version: '1.21' - name: Install atlas - uses: ariga/setup-atlas@v0 + uses: ariga/setup-atlas@d52cd13fed38eca914fa57071155a4644fd6f820 # v0.2 - name: Install formatter run: go install golang.org/x/tools/cmd/goimports@latest - name: Check format @@ -105,6 +120,11 @@ jobs: name: Lint runs-on: ubuntu-latest steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v3 - name: setup-go @@ -112,7 +132,7 @@ jobs: with: go-version: '1.21' - name: Install atlas - uses: ariga/setup-atlas@v0 + uses: ariga/setup-atlas@d52cd13fed38eca914fa57071155a4644fd6f820 # v0.2 - name: golangci-lint uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # tag=v3.2.0 with: @@ -143,6 +163,11 @@ jobs: --health-timeout 5s --health-retries 5 steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 with: @@ -183,6 +208,11 @@ jobs: labels: ubuntu-latest timeout-minutes: 30 steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Install tools shell: bash run: | diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000000..21487188bf --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,78 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + schedule: + - cron: "0 0 * * 1" + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["go"] + # CodeQL supports [ $supported-codeql-languages ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Autobuild attempts to build any compiled languages (C/C++, C#, 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@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0 + + # ℹī¸ 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 + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/db-performance-test.yaml b/.github/workflows/db-performance-test.yaml index 94020919fc..1b47082569 100644 --- a/.github/workflows/db-performance-test.yaml +++ b/.github/workflows/db-performance-test.yaml @@ -49,6 +49,11 @@ jobs: query_time: ${{ steps.query_test.outputs.elapsed_time }} name: performance test for backends DBs steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v3 - name: Checkout guac-data @@ -58,7 +63,7 @@ jobs: ref: 'main' path: 'guac-data' - name: Download artifact files - uses: actions/download-artifact@v4 + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 with: name: guac-artifacts path: ./bin @@ -108,7 +113,7 @@ jobs: printf "%-15s%-20s%-15s%s seconds\n" "Ingestion" "${{ matrix.database }}" "$elapsed_time" echo "elapsed_time=$elapsed_time" >> $GITHUB_OUTPUT ## Write for matrix outputs workaround - - uses: cloudposse/github-action-matrix-outputs-write@main + - uses: cloudposse/github-action-matrix-outputs-write@65a4012225eb616bb2a3c330f505c70182a8b2b3 # main id: out-ingestion with: matrix-step-name: run_test @@ -130,7 +135,7 @@ jobs: printf "%-15s%-20s%-15s%s seconds\n" "Query" "${{ matrix.database }}" "$query_time" echo "query_time=$query_time" >> $GITHUB_OUTPUT ## Write for matrix outputs workaround - - uses: cloudposse/github-action-matrix-outputs-write@main + - uses: cloudposse/github-action-matrix-outputs-write@65a4012225eb616bb2a3c330f505c70182a8b2b3 # main id: out-query with: matrix-step-name: query_test @@ -142,13 +147,18 @@ jobs: runs-on: ubuntu-latest needs: [db-performance] steps: - - uses: cloudposse/github-action-matrix-outputs-read@main + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + + - uses: cloudposse/github-action-matrix-outputs-read@67f4a3fe62553bdff3a5a4eb5e9ff4567b25d113 # main id: ingestion with: matrix-step-name: run_test - run: | echo "result: ${{ steps.ingestion.outputs.result }}" - - uses: cloudposse/github-action-matrix-outputs-read@main + - uses: cloudposse/github-action-matrix-outputs-read@67f4a3fe62553bdff3a5a4eb5e9ff4567b25d113 # main id: query with: matrix-step-name: query_test @@ -161,6 +171,11 @@ jobs: runs-on: ubuntu-latest needs: [read] steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - run: | echo -e "\n\n\n" printf "%-15s%-20s%s\n" "Test" "Deployment Env" "Time" diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 0000000000..7379300d3f --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,27 @@ +# 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: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + + - name: 'Checkout Repository' + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: 'Dependency Review' + uses: actions/dependency-review-action@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c # v4.3.4 diff --git a/.github/workflows/nightly-release.yaml b/.github/workflows/nightly-release.yaml index 607c63e855..d5000d8b6e 100644 --- a/.github/workflows/nightly-release.yaml +++ b/.github/workflows/nightly-release.yaml @@ -39,6 +39,11 @@ jobs: runs-on: ubuntu-latest name: trigger nightly build steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v3 diff --git a/.github/workflows/postmerge.yaml b/.github/workflows/postmerge.yaml index 972852e8c0..02acfe0129 100644 --- a/.github/workflows/postmerge.yaml +++ b/.github/workflows/postmerge.yaml @@ -25,6 +25,11 @@ jobs: runs-on: ubuntu-latest name: CI for Integration Merge Test steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v3 - name: setup-go @@ -38,7 +43,7 @@ jobs: - name: Setup the project run: go mod download - name: Install atlas - uses: ariga/setup-atlas@v0 + uses: ariga/setup-atlas@d52cd13fed38eca914fa57071155a4644fd6f820 # v0.2 - name: Run integration merge test env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index cf7c6943db..2b6ee429cd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -36,6 +36,11 @@ jobs: image: ${{ steps.hash.outputs.image }} digest: ${{ steps.hash.outputs.digest }} steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Checkout uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: @@ -104,21 +109,26 @@ jobs: runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Check out the code - uses: actions/checkout@v4 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 - name: Log in to GitHub Container Registry - uses: docker/login-action@v3 + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push the Docker image - uses: docker/build-push-action@v6 + uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0 with: context: ./pkg/assembler/backends/ent/migrate push: true @@ -134,6 +144,11 @@ jobs: needs: [goreleaser] if: startsWith(github.ref, 'refs/tags/') steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v3 - name: Login to GitHub Container Registry @@ -187,6 +202,11 @@ jobs: needs: [goreleaser] if: startsWith(github.ref, 'refs/tags/') steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v3 - name: Create and publish compose tarball diff --git a/.github/workflows/reusable-local-build.yaml b/.github/workflows/reusable-local-build.yaml index 21a55b74d1..1eaa8cd9c5 100644 --- a/.github/workflows/reusable-local-build.yaml +++ b/.github/workflows/reusable-local-build.yaml @@ -24,10 +24,18 @@ on: required: true type: string +permissions: + contents: read + jobs: build: runs-on: ubuntu-latest steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: repository: ${{ inputs.repository }} @@ -37,7 +45,7 @@ jobs: with: go-version: 'stable' - name: Install GoReleaser - uses: goreleaser/goreleaser-action@v6 + uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0 with: install-only: true - run: | @@ -53,7 +61,7 @@ jobs: docker tag ghcr.io/${{ github.repository }}:v0.0.0-local-organic-guac-amd64 local-organic-guac docker save -o ./bin/local-organic-guac.tar local-organic-guac shell: bash - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 with: name: guac-artifacts path: ./bin diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index a486fabb66..9fa52f1d21 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -31,6 +31,11 @@ jobs: # actions: read steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + - name: "Checkout code" uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..e8e938733c --- /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 diff --git a/pkg/assembler/backends/ent/migrate/Dockerfile b/pkg/assembler/backends/ent/migrate/Dockerfile index 280c0f5274..42c6b8f8a5 100644 --- a/pkg/assembler/backends/ent/migrate/Dockerfile +++ b/pkg/assembler/backends/ent/migrate/Dockerfile @@ -1,4 +1,4 @@ -FROM arigaio/atlas:latest-alpine +FROM arigaio/atlas:latest-alpine@sha256:0389cdd8e6d4a393c134e09a10b52724bc42b8a3fc0e7fa62bf810eb9b8a2e2b WORKDIR /app