diff --git a/.betterleaks.toml b/.betterleaks.toml new file mode 100644 index 0000000..c03aa89 --- /dev/null +++ b/.betterleaks.toml @@ -0,0 +1,18 @@ +# Betterleaks: secret scanning in CI's lint job and the pre-commit hook. The default rules, minus this repository's +# placeholders. Add an exception only for something that is not a secret, with the reason. +[extend] +useDefault = true + +[[allowlists]] +description = "Example and reference files hold placeholders (REPLACE_ME, changeme, dckr_pat_example), never real values" +paths = [ + '''\.example$''', + '''\.example\.ya?ml$''', + '''^reference/deployment\.yml$''', + '''^kubernetes/docspring-enterprise/ci/check-values\.yaml$''', +] + +[[allowlists]] +description = "The connection URL's shape in docs and error messages: postgres://USER:PASSWORD@HOST" +regexTarget = "line" +regexes = ['''postgres://USER:PASSWORD@''', '''random_password\.db'''] diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..ae71d97 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +# GitHub Actions updates, a week after each release (the cooldown), so a bad or hijacked release has time to be +# pulled first. Dependabot keeps the commit SHA pins and their version comments. +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + cooldown: + default-days: 7 + groups: + actions: + patterns: ['*'] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de1b2fb..7592892 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,11 +9,28 @@ permissions: contents: read jobs: + # The workflows themselves (actionlint, zizmor: actions must be pinned to commit SHAs), spelling and secrets. + # The same versions as mise.toml. + lint: + name: Workflows, spelling and secrets + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: jdx/mise-action@5228313ee0372e111a38da051671ca30fc5a96db # v3.6.3 + - run: actionlint + - run: zizmor .github/workflows + - run: typos + - run: betterleaks dir --redact --no-banner -c .betterleaks.toml . + contract: name: Every folder matches reference/deployment.yml runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - uses: azure/setup-helm@2f5e7bc67f1f9972ab16657bb795f36d8f04de0e # v5.1.0 - run: scripts/check_deployments @@ -24,10 +41,12 @@ jobs: working-directory: docker-compose steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Compose file run: ./setup.sh > /dev/null && docker compose config --quiet && rm .env - name: Shell scripts - run: shellcheck *.sh + run: shellcheck ./*.sh kubernetes: runs-on: ubuntu-latest @@ -36,6 +55,8 @@ jobs: working-directory: kubernetes steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - uses: azure/setup-helm@2f5e7bc67f1f9972ab16657bb795f36d8f04de0e # v5.1.0 - name: Install kubeconform run: | @@ -52,9 +73,11 @@ jobs: working-directory: aws-ecs steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - uses: hashicorp/setup-terraform@dfe3c3f87815947d99a8997f908cb6525fc44e9e # v4.0.1 - uses: terraform-linters/setup-tflint@6ffdbaa3be476b3431f7275c26966ef32ff60337 # v6.3.2 - - run: terraform fmt -check -recursive + # No format check: the pre-commit hook (lefthook.yml) runs terraform fmt and stages the result - working-directory: aws-ecs/example run: terraform init -backend=false -input=false && terraform validate # tflint --init downloads its rulesets from GitHub, which rate-limits a runner's anonymous requests @@ -70,11 +93,13 @@ jobs: working-directory: convox steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - uses: ruby/setup-ruby@4e97ecde5048e1e0816923020652678063ffbf65 # v1.339.0 with: ruby-version: '3.4' - run: ruby -c install.rb - - run: shellcheck *.sh + - run: shellcheck ./*.sh aptible: runs-on: ubuntu-latest @@ -83,6 +108,8 @@ jobs: working-directory: aptible steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: The crontab parses run: | docker run --rm -v "$PWD/crontab:/crontab:ro" --entrypoint sh alpine:3.22 -c \ diff --git a/.github/workflows/publish-chart.yml b/.github/workflows/publish-chart.yml index f4640ba..8a239a2 100644 --- a/.github/workflows/publish-chart.yml +++ b/.github/workflows/publish-chart.yml @@ -17,14 +17,17 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - uses: azure/setup-helm@2f5e7bc67f1f9972ab16657bb795f36d8f04de0e # v5.1.0 - name: Push the chart unless its version is already published env: GH_TOKEN: ${{ github.token }} + ACTOR: ${{ github.actor }} run: | set -euo pipefail version="$(sed -n 's/^version: *//p' kubernetes/docspring-enterprise/Chart.yaml | tr -d '"')" - echo "$GH_TOKEN" | helm registry login ghcr.io --username "${{ github.actor }}" --password-stdin + echo "$GH_TOKEN" | helm registry login ghcr.io --username "$ACTOR" --password-stdin if helm show chart oci://ghcr.io/docspring/charts/docspring-enterprise --version "$version" > /dev/null 2>&1; then echo "Chart $version is already published" exit 0 diff --git a/AGENTS.md b/AGENTS.md index c7a2da7..688ea8b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,3 +56,7 @@ runs all of them (`.github/workflows/ci.yml`). - Plain English in READMEs and comments. Say what a thing does and why, not that it's powerful or easy. - No customer names, hostnames or secrets anywhere. Example domain: `docspring.example.com`. - Shell scripts: `set -euo pipefail`, shellcheck clean. Terraform: `terraform fmt`. YAML: two spaces. +- `mise install && lefthook install` sets up the pre-commit hook: it runs `terraform fmt` and stages the result (CI + has no format check), shellcheck, actionlint and zizmor on the workflows, typos and Betterleaks. CI's `lint` job + runs the same linters. zizmor fails on an action that isn't pinned to a commit SHA. Exceptions live in + `_typos.toml` and `.betterleaks.toml`, each with its reason. diff --git a/_typos.toml b/_typos.toml new file mode 100644 index 0000000..158d3ec --- /dev/null +++ b/_typos.toml @@ -0,0 +1,4 @@ +# typos: the spelling check in CI's lint job and the pre-commit hook. +[default.extend-words] +# Azure Kubernetes Service +AKS = "AKS" diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000..4ca3175 --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,19 @@ +# Git hooks that mirror CI. Install with: mise install && lefthook install +pre-commit: + commands: + terraform-fmt: + glob: '*.{tf,tfvars}' + run: terraform fmt {staged_files} + stage_fixed: true + shellcheck: + glob: '*.sh' + run: shellcheck {staged_files} + workflows: + glob: '.github/workflows/*.yml' + run: actionlint && zizmor .github/workflows + # Fixes a misspelling with one correction and stages it; fails on one with several + typos: + run: typos -w {staged_files} + stage_fixed: true + betterleaks: + run: betterleaks git --staged --redact --no-banner -c .betterleaks.toml . diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..094885d --- /dev/null +++ b/mise.toml @@ -0,0 +1,8 @@ +# The linters CI's lint job and the pre-commit hook run. Install with: mise install +[tools] +actionlint = "1.7.12" +zizmor = "1.33.1" +shellcheck = "0.11.0" +typos = "1.52.2" +betterleaks = "1.10.1" +lefthook = "2.1.14"