diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000000..bb8a8c53e7 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,41 @@ +name: CodeQL + +# Advanced setup so CodeQL also runs on pull requests (including from forks), +# surfacing findings before merge instead of only after a change lands on dev. +on: + push: + branches: [dev, main] + pull_request: + branches: [dev] + schedule: + - cron: "17 3 * * 1" + +permissions: + contents: read + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + runs-on: ubuntu-latest + permissions: + security-events: write + actions: read + contents: read + strategy: + fail-fast: false + matrix: + language: [actions, javascript-typescript, python] + steps: + - name: Checkout + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + persist-credentials: false + - name: Initialize CodeQL + uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2 + with: + languages: ${{ matrix.language }} + build-mode: none + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2 + with: + category: "/language:${{ matrix.language }}" diff --git a/docs/security-ci.md b/docs/security-ci.md index f21643de53..8cceea2580 100644 --- a/docs/security-ci.md +++ b/docs/security-ci.md @@ -7,10 +7,9 @@ benefit. ## What runs, and why -Most checks live in files under `.github/workflows/`. CodeQL is configured -through GitHub's code scanning default setup, so it appears as a dynamic GitHub -workflow instead of a checked-in workflow file. They run automatically; you do -not start them. +Most checks live in files under `.github/workflows/`. CodeQL uses the +checked-in advanced configuration in `.github/workflows/codeql.yml`. They run +automatically; you do not start them. | Check | What it protects against | Blocks a merge? | |---|---|---| @@ -90,14 +89,9 @@ let the workflows run on one pull request first, then add them here. 2. Turn on **Dependency graph** (usually on by default for public repos) -- this powers Dependency review and Dependabot. 3. Turn on **Dependabot alerts** and **Dependabot security updates**. -4. Under **Code scanning**, use **Set up -> Default** for CodeQL. GitHub then - runs CodeQL as a dynamic workflow without the fork-token limitations that - affect checked-in advanced workflows. - - Do not also add a checked-in CodeQL workflow while default setup is enabled: - GitHub rejects advanced CodeQL uploads when default setup is active. If the - project later needs an advanced CodeQL workflow, disable default setup first - and keep only one CodeQL publishing path active. +4. Under **Code scanning**, keep **Default setup** disabled. CodeQL is + configured by `.github/workflows/codeql.yml`; enabling default setup at the + same time causes GitHub to reject uploads from the checked-in workflow. ## Keeping it current