From 92817efb58b2caf80cda8477812771dc940719ba Mon Sep 17 00:00:00 2001 From: Hironori Takahashi Date: Wed, 2 Dec 2026 11:59:00 +0900 Subject: [PATCH] ci: adopt the shared zizmor workflow and fix its findings Adds a job calling h13/.github ci-zizmor.yml (v3.1.0, SHA-pinned, default medium gate) and fixes every >=medium finding so the gate starts green. See the PR description for the finding-by-finding list. --- .github/workflows/cd.yml | 65 ++++++++++++++++++++++++++++++++--- .github/workflows/ci.yml | 6 ++++ .github/workflows/publish.yml | 4 ++- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 21bcf21..4c577cd 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,7 +1,9 @@ name: CD on: - workflow_run: + # Deploy runs after CI on push to dev/main only; the branches filter keeps + # fork/PR heads out of this privileged context. + workflow_run: # zizmor: ignore[dangerous-triggers] workflows: ['CI'] types: [completed] branches: [dev, main] @@ -13,10 +15,15 @@ jobs: github.event.workflow_run.event == 'push' && !github.event.repository.is_template runs-on: ubuntu-latest + permissions: + contents: read + id-token: write environment: ${{ github.event.workflow_run.head_branch == 'main' && 'production' || 'development' }} concurrency: group: deploy-${{ github.event.workflow_run.head_branch }} cancel-in-progress: ${{ github.event.workflow_run.head_branch != 'main' }} + env: + SCRIPT_PROPERTIES: ${{ secrets.SCRIPT_PROPERTIES }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -33,16 +40,64 @@ jobs: env: DEPLOY_ENV: ${{ github.event.workflow_run.head_branch == 'main' && 'production' || 'development' }} + # Secret Manager mode: direct WIF (no service-account impersonation). + # Requires org variables GCP_WIF_PROVIDER + CLASPRC_SECRET (docs/secret-manager.md). + - name: Authenticate to Google Cloud (WIF) + if: vars.GCP_WIF_PROVIDER != '' + uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0 + with: + workload_identity_provider: ${{ vars.GCP_WIF_PROVIDER }} + + - name: Fetch clasp credentials from Secret Manager + if: vars.GCP_WIF_PROVIDER != '' + id: gcp-secrets + uses: google-github-actions/get-secretmanager-secrets@bc9c54b29fdffb8a47776820a7d26e77b379d262 # v3.0.0 + with: + secrets: |- + clasprc:${{ vars.CLASPRC_SECRET }} + - name: Setup clasp credentials + env: + WIF_ENABLED: ${{ vars.GCP_WIF_PROVIDER != '' }} + CLASPRC_GCP: ${{ steps.gcp-secrets.outputs.clasprc }} + CLASPRC_LEGACY: ${{ secrets.CLASPRC_JSON }} + CLASP_JSON: ${{ secrets.CLASP_JSON }} run: | - echo '${{ secrets.CLASPRC_JSON }}' > ~/.clasprc.json - echo '${{ secrets.CLASP_JSON }}' > .clasp.json + if [ "$WIF_ENABLED" = "true" ]; then + # Secret Manager mode: never fall back to the legacy secret silently. + CLASPRC="$CLASPRC_GCP" + if [ -z "$CLASPRC" ]; then + echo "::error::GCP_WIF_PROVIDER is set but Secret Manager returned an empty payload. Check CLASPRC_SECRET and the secret's latest version." + exit 1 + fi + else + CLASPRC="$CLASPRC_LEGACY" + if [ -z "$CLASPRC" ]; then + echo "::error::No clasp credentials. Set org variables GCP_WIF_PROVIDER + CLASPRC_SECRET (Secret Manager), or org secret CLASPRC_JSON (legacy)." + exit 1 + fi + fi + if [ -z "$CLASP_JSON" ]; then + echo "::error::CLASP_JSON secret is not set for this environment." + exit 1 + fi + umask 077 + printf '%s' "$CLASPRC" > ~/.clasprc.json + printf '%s' "$CLASP_JSON" > .clasp.json - - name: Push to GAS + - name: Push to Apps Script run: pnpm exec clasp push -f - name: Deploy new version - run: pnpm exec clasp deploy -i "${{ vars.DEPLOYMENT_ID }}" --description "CD deploy from ${{ github.event.workflow_run.head_branch }}@${{ github.event.workflow_run.head_sha }}" + env: + DEPLOYMENT_ID: ${{ vars.DEPLOYMENT_ID }} + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + run: pnpm exec clasp deploy -i "$DEPLOYMENT_ID" --description "CD deploy from ${HEAD_BRANCH}@${HEAD_SHA}" + + - name: Set script properties + if: vars.GCP_PROJECT_NUMBER != '' && env.SCRIPT_PROPERTIES != '' + run: ./scripts/set-properties.sh --env SCRIPT_PROPERTIES - name: Post-deploy hook if: always() && hashFiles('.github/hooks/post-deploy.sh') != '' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f19a8a..71aba07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,9 @@ on: pull_request: branches: [main] +permissions: + contents: read + jobs: check: runs-on: ubuntu-latest @@ -62,3 +65,6 @@ jobs: actionlint: uses: h13/.github/.github/workflows/ci-actionlint.yml@c807de1510e8d223f352555ddcbf6a1a78fe51eb # v3.1.0 + + zizmor: + uses: h13/.github/.github/workflows/ci-zizmor.yml@c807de1510e8d223f352555ddcbf6a1a78fe51eb # v3.1.0 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6a38526..7682fe2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,10 +5,12 @@ on: tags: - v* +# publish-node needs contents: write (GitHub Release) and id-token: write +# (npm OIDC trusted publishing). It takes no secrets. permissions: contents: write + id-token: write jobs: publish: uses: h13/.github/.github/workflows/publish-node.yml@1e41d76a661e2835b0cf9df2c85d588f9f0308f7 # v3.0.0 - secrets: inherit