Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: [StepSecurity] Apply security best practices #2726

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,31 @@ updates:
update-types:
- "version-update:semver-major"
- "version-update:semver-minor"

- package-ecosystem: "docker"
directory: /
schedule:
interval: "weekly"
commit-message:
prefix: "chore"

- package-ecosystem: "docker"
directory: "/build/tooling"
schedule:
interval: "weekly"
commit-message:
prefix: "chore"

- package-ecosystem: "docker"
directory: "/test/externaldata/dummy-provider"
schedule:
interval: "weekly"
commit-message:
prefix: "chore"

- package-ecosystem: "docker"
directory: "/test/image"
schedule:
interval: "weekly"
commit-message:
prefix: "chore"
16 changes: 12 additions & 4 deletions .github/workflows/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
issue_comment:
types: [created]

permissions:
contents: read

jobs:
benchmark:
name: "Benchmark"
Expand All @@ -13,29 +16,34 @@ jobs:
contents: write
pull-requests: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
with:
egress-policy: audit

- uses: izhangzhihao/delete-comment@98aa1ea5c6304048edf951c20b3114e03c785c79
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
delete_user_name: github-actions[bot]
issue_number: ${{ github.event.issue.number }}

- name: Update status
uses: peter-evans/create-or-update-comment@v3
uses: peter-evans/create-or-update-comment@3383acd359705b10cb1eeef05c0e88c056ea4666 # v3.0.0
with:
issue-number: ${{ github.event.issue.number }}
body: |
[Running benchmark here...](${{ github.server.url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- name: Check out base code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
ref: ${{ github.base_ref }}

- name: Run benchmarks on base ref
run: make benchmark-test BENCHMARK_FILE_NAME="../base_benchmarks.txt"

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: Run benchmark with incoming changes
run: make benchmark-test BENCHMARK_FILE_NAME="pr_benchmarks.txt"
Expand All @@ -53,7 +61,7 @@ jobs:
echo '$delimiter' >> $GITHUB_OUTPUT
- name: Create commit comment
uses: peter-evans/create-or-update-comment@v3
uses: peter-evans/create-or-update-comment@3383acd359705b10cb1eeef05c0e88c056ea4666 # v3.0.0
with:
issue-number: ${{ github.event.issue.number }}
body: |
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
security-events: write

steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
with:
egress-policy: audit

- name: Checkout repository
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c

Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -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@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
with:
egress-policy: audit

- name: 'Checkout Repository'
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: 'Dependency Review'
uses: actions/dependency-review-action@0efb1d1d84fc9633afcdaad14c485cbbc90ef46c # v2.5.1
12 changes: 10 additions & 2 deletions .github/workflows/license-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
- "go.sum"
- "vendor/**"

permissions:
contents: read

jobs:
license-lint:
name: "license-lint"
Expand All @@ -19,13 +22,18 @@ jobs:
permissions:
contents: read
steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
with:
egress-policy: audit

- name: Set up Go 1.20
uses: actions/setup-go@v4
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: "1.20"

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: license-lint
run: |
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
if: github.ref == 'refs/heads/master' && github.event_name == 'push' && github.repository == 'open-policy-agent/gatekeeper'
timeout-minutes: 30
steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
with:
egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c

Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/release-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ jobs:
create-release-pull-request:
runs-on: ubuntu-22.04
steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
with:
egress-policy: audit

- name: Set up Go 1.20
uses: actions/setup-go@v4
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: "1.20"

Expand Down Expand Up @@ -72,7 +77,7 @@ jobs:
run: make version-docs NEWVERSION=v${MAJOR_VERSION}.${MINOR_VERSION}.x

- name: Create release pull request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@5b4a9f6a9e2af26e5f02351490b90d01eb8ec1e5 # v5.0.0
with:
commit-message: "chore: Prepare ${{ env.NEWVERSION }} release"
title: "chore: Prepare ${{ env.NEWVERSION }} release"
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ env:
CRD_IMAGE_REPO: openpolicyagent/gatekeeper-crds
GATOR_IMAGE_REPO: openpolicyagent/gator

permissions:
contents: read

jobs:
tagged-release:
name: "Tagged Release"
Expand All @@ -18,11 +21,16 @@ jobs:
if: startsWith(github.ref, 'refs/tags/v') && github.repository == 'open-policy-agent/gatekeeper'
timeout-minutes: 45
steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
with:
egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c

- name: Set up Go 1.20
uses: actions/setup-go@v4
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: "1.20"

Expand Down Expand Up @@ -127,7 +135,7 @@ jobs:
PLATFORMS: "linux-amd64 linux-arm64 darwin-amd64 darwin-arm64"

- name: Create GitHub release
uses: "marvinpinto/[email protected]"
uses: "marvinpinto/action-automatic-releases@919008cf3f741b179569b7a6fb4d8860689ab7f0 # v1.2.1"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
Expand All @@ -136,7 +144,7 @@ jobs:
_dist/*.tar.gz
- name: Publish Helm chart
uses: stefanprodan/[email protected]
uses: stefanprodan/helm-gh-pages@0ad2bb377311d61ac04ad9eb6f252fb68e207260 # v1.7.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
charts_dir: charts
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
@@ -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: ["master"]

# 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@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
with:
egress-policy: audit

- name: "Checkout code"
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
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@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
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@8662eabe0e9f338a07350b7fd050732745f93848 # v2.3.1
with:
sarif_file: results.sarif
7 changes: 6 additions & 1 deletion .github/workflows/upgrade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ jobs:
matrix:
HELM_VERSION: ["3.7.2"]
steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
with:
egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c

Expand Down Expand Up @@ -94,7 +99,7 @@ jobs:
kubectl logs -n gatekeeper-system -l run=dummy-provider --tail=-1 > logs-${{ matrix.HELM_VERSION }}-dummy-provider-post-upgrade.json
- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
if: ${{ always() }}
with:
name: logs
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/website.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ jobs:
run:
working-directory: website
steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
with:
egress-policy: audit

- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: "16"

Expand All @@ -30,7 +35,7 @@ jobs:
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-website-${{ hashFiles('**/yarn.lock') }}
Expand All @@ -41,7 +46,7 @@ jobs:
- run: yarn build

- name: Deploy
uses: peaceiris/[email protected]
uses: peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847 # v3.9.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./website/build
Expand Down
Loading