Skip to content

feat(security): add CodeQL composites and integrate into pr-security-scan - #162

Merged
bedatty merged 14 commits into
developfrom
ci/add-self-codeql
Mar 24, 2026
Merged

feat(security): add CodeQL composites and integrate into pr-security-scan#162
bedatty merged 14 commits into
developfrom
ci/add-self-codeql

Conversation

@bedatty

@bedatty bedatty commented Mar 20, 2026

Copy link
Copy Markdown
Contributor
Lerian

GitHub Actions Shared Workflows


Description

Adds CodeQL static analysis as reusable composites and integrates it into the security scanning pipeline.

New composites:

  • src/security/codeql-init — wraps github/codeql-action/init with security-extended suite by default
  • src/security/codeql-analyze — wraps github/codeql-action/analyze and uploads SARIF results
  • src/security/codeql-reporter — reads CodeQL SARIF output and posts formatted findings as PR comments

Workflow changes:

  • pr-security-scan.yml — new optional inputs (enable_codeql, codeql_languages, codeql_queries) that add a parallel CodeQL analysis job. External repos can enable with enable_codeql: true and pass their language
  • self-pr-validation.yml — added CodeQL job for this repo (language: actions), running alongside existing linters

Usage by external repos:

uses: LerianStudio/github-actions-shared-workflows/.github/workflows/pr-security-scan.yml@v1.x.x
with:
  enable_codeql: true
  codeql_languages: go

Type of Change

  • feat: New workflow or new input/output/step in an existing workflow
  • fix: Bug fix in a workflow (incorrect behavior, broken step, wrong condition)
  • perf: Performance improvement (e.g. caching, parallelism, reduced steps)
  • refactor: Internal restructuring with no behavior change
  • docs: Documentation only (README, docs/, inline comments)
  • ci: Changes to self-CI (workflows under .github/workflows/ that run on this repo)
  • chore: Dependency bumps, config updates, maintenance
  • test: Adding or updating tests
  • BREAKING CHANGE: Callers must update their configuration after this PR

Breaking Changes

None. CodeQL is opt-in via enable_codeql: false (default).

Testing

  • YAML syntax validated locally
  • Triggered a real workflow run on a caller repository using @develop or the beta tag
  • Verified all existing inputs still work with default values
  • Confirmed no secrets or tokens are printed in logs
  • Checked that unrelated workflows are not affected

Caller repo / workflow run: N/A — self-CI will validate on this PR; external repos unaffected (opt-in)

Related Issues

Closes #

Summary by CodeRabbit

  • New Features

    • Introduces reusable CodeQL actions to generate a scoped config, initialize analysis, run scans, and report findings as PR comments; includes optional gating to fail on findings.
    • Adds a workflow job to run CodeQL on changed action files and post results.
  • Documentation

    • Added detailed docs for each new CodeQL action, usage examples, inputs/outputs, and required permissions.

@bedatty
bedatty requested a review from a team as a code owner March 20, 2026 20:57
@coderabbitai

coderabbitai Bot commented Mar 20, 2026

Copy link
Copy Markdown

Walkthrough

Adds four new composite GitHub Actions for CodeQL (config generator, init, analyze, reporter), documentation READMEs for each, and a codeql job in the PR validation workflow that wires these actions together for pull-request scans and reporting.

Changes

Cohort / File(s) Summary
CodeQL Config Generator
src/security/codeql-config/action.yml, src/security/codeql-config/README.md
New composite action that normalizes and deduplicates a comma/newline list of changed paths, emits skip when no paths, and writes a YAML CodeQL config file (output-file) when paths exist.
CodeQL Init Action
src/security/codeql-init/action.yml, src/security/codeql-init/README.md
New composite action wrapping github/codeql-action/init@v4 with inputs: languages (required), queries (default security-extended), and config-file (optional).
CodeQL Analyze Action
src/security/codeql-analyze/action.yml, src/security/codeql-analyze/README.md
New composite action wrapping github/codeql-action/analyze@v4 with inputs: category (required) and output (default ../results) to control SARIF output and deduplication category.
CodeQL Reporter
src/security/codeql-reporter/action.yml, src/security/codeql-reporter/README.md
New composite action that reads SARIF files from sarif-path, parses runs/results (robust to per-file JSON parse errors), builds an idempotent Markdown PR comment with severity counts and upserts it, exposes has-findings and findings-count, and can fail the job when configured.
Workflow Integration
.github/workflows/self-pr-validation.yml
Adds a codeql job that runs conditionally when action files changed: generates config for changed paths, conditionally runs codeql-init and codeql-analyze, and posts results using the reporter (reporting step runs under always()).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: addition of CodeQL composite actions and integration into the security scanning workflow.
Description check ✅ Passed The description includes all required template sections: clear description of changes, type of change marked (feat, ci), breaking changes addressed (none), testing checkboxes completed appropriately, and related issues noted.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/add-self-codeql

Comment @coderabbitai help to get the list of available commands and usage tips.

@lerian-studio lerian-studio added the size/XS PR changes < 50 lines label Mar 20, 2026
@github-actions github-actions Bot added workflow Changes to one or more reusable workflow files and removed size/XS PR changes < 50 lines labels Mar 20, 2026
@lerian-studio

lerian-studio commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

🔍 Lint Analysis

Check Files Scanned Status
YAML Lint 5 file(s) ✅ success
Action Lint 1 file(s) ✅ success
Pinned Actions 5 file(s) ✅ success
Markdown Link Check 4 file(s) ✅ success
Spelling Check 9 file(s) ✅ success
Shell Check 5 file(s) ✅ success
README Check 5 file(s) ✅ success
Composite Schema 4 file(s) ✅ success

🔍 View full scan logs

@bedatty bedatty self-assigned this Mar 20, 2026
coderabbitai[bot]
coderabbitai Bot previously requested changes Mar 20, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/self-codeql.yml:
- Around line 22-45: Replace the embedded CodeQL job logic in self-codeql.yml
(the "analyze" job with its runs-on, strategy/matrix and step list including
"Perform CodeQL Analysis") with a single delegation to the repository's reusable
CodeQL workflow: remove the job-level business logic (runs-on, matrix, and
steps) and instead add a job that calls the reusable workflow using uses: with
required inputs/parameters (e.g., language/category) so this self-* entrypoint
only invokes the reusable workflow and does not contain analysis steps itself.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b5d4914c-c979-4674-84ef-a40df3216660

📥 Commits

Reviewing files that changed from the base of the PR and between 1f9c77e and ea4ffca.

📒 Files selected for processing (1)
  • .github/workflows/self-codeql.yml

Comment thread .github/workflows/self-codeql.yml Outdated
@bedatty
bedatty dismissed coderabbitai[bot]’s stale review March 23, 2026 17:58

All comments addressed — single suggestion dismissed as not applicable (no reusable CodeQL workflow exists, and creating one for a 3-step self-CI would be over-engineering).

Extract init and analyze steps into reusable composite actions under
src/security/. Remove schedule trigger (moving to future schedule-job),
remove unnecessary matrix strategy, and add YAML path filters.

New composites:
- src/security/codeql-init — initializes CodeQL with security-extended suite
- src/security/codeql-analyze — performs analysis and uploads SARIF results
@lerian-studio lerian-studio added the size/S PR changes 50–199 lines label Mar 23, 2026
@bedatty bedatty changed the title ci(codeql): add CodeQL analysis workflow for this repository ci(codeql): extract CodeQL steps into composites and improve workflow Mar 23, 2026
coderabbitai[bot]
coderabbitai Bot previously requested changes Mar 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/security/codeql-analyze/README.md`:
- Around line 36-42: The permissions YAML in the README's "Permissions required"
section is missing actions: read; update the permissions block (the YAML under
the "Permissions required" header) to include actions: read alongside contents:
read and security-events: write so it matches the codeql-init README and
supports private repos/workflow calls.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 17f4502a-4325-487f-8f89-9c9660fef06b

📥 Commits

Reviewing files that changed from the base of the PR and between ea4ffca and 540b7db.

📒 Files selected for processing (5)
  • .github/workflows/self-codeql.yml
  • src/security/codeql-analyze/README.md
  • src/security/codeql-analyze/action.yml
  • src/security/codeql-init/README.md
  • src/security/codeql-init/action.yml

Comment thread src/security/codeql-analyze/README.md
…gger

Reuse existing changed-workflows composite for file detection instead of
inline git diff. CodeQL analysis now only runs when action/workflow YAML
files are changed in PRs. Full repo scan will move to a future schedule-job.
@lerian-studio lerian-studio added size/M PR changes 200–499 lines and removed size/S PR changes 50–199 lines labels Mar 23, 2026
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

coderabbitai[bot]
coderabbitai Bot previously requested changes Mar 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/self-codeql.yml:
- Around line 8-10: The workflow currently includes the glob pattern '**.yaml'
under the paths filter which violates the repo convention of using only .yml for
workflows; remove the '**.yaml' entry from the paths list in the self-codeql.yml
workflow so only '**.yml' remains (i.e., update the paths array and delete the
'**.yaml' pattern) to enforce the .yml-only policy.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 47f8c38a-5407-448e-bae7-3a8f8b10e331

📥 Commits

Reviewing files that changed from the base of the PR and between 540b7db and 63acc04.

📒 Files selected for processing (1)
  • .github/workflows/self-codeql.yml

Comment thread .github/workflows/self-codeql.yml Outdated
Align codeql-analyze README permissions with codeql-init for
consistency, since both composites are used together.
@bedatty
bedatty dismissed stale reviews from coderabbitai[bot] and coderabbitai[bot] March 24, 2026 12:14

All comments addressed — actions:read added to codeql-analyze README.

@lerian-studio lerian-studio added size/M PR changes 200–499 lines and removed size/M PR changes 200–499 lines labels Mar 24, 2026
coderabbitai[bot]
coderabbitai Bot previously requested changes Mar 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/security/codeql-analyze/README.md`:
- Line 8: Update the composite action README description to explicitly state
that this composite wraps the marketplace action github/codeql-action/analyze;
in the README header/first paragraph (the existing sentence describing the
composite), add a short clause like "this composite wraps
github/codeql-action/analyze" and optionally a one-line note about why
(transparency and abstraction), so readers know which upstream action is being
invoked by the codeql-analyze composite.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d6044653-0803-4d20-a023-6a0dab0fc39c

📥 Commits

Reviewing files that changed from the base of the PR and between 63acc04 and 138d109.

📒 Files selected for processing (1)
  • src/security/codeql-analyze/README.md

Comment thread src/security/codeql-analyze/README.md Outdated
@bedatty
bedatty dismissed coderabbitai[bot]’s stale review March 24, 2026 12:35

All comments addressed.

Add references to github/codeql-action/init and github/codeql-action/analyze
in composite README descriptions for transparency.
@lerian-studio lerian-studio added size/M PR changes 200–499 lines and removed size/M PR changes 200–499 lines labels Mar 24, 2026
@lerian-studio lerian-studio added size/L PR changes 500–999 lines and removed size/L PR changes 500–999 lines labels Mar 24, 2026
coderabbitai[bot]
coderabbitai Bot previously requested changes Mar 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/security/codeql-reporter/action.yml`:
- Around line 118-120: The catch block currently sets sarifAvailable = false on
any single SARIF parse error which suppresses other readable SARIF findings;
instead, stop flipping the global sarifAvailable flag in the catch, introduce a
separate boolean (e.g., hadParseErrors) and increment a parse-error counter
inside the catch, and only set sarifAvailable based on whether at least one
SARIF file was successfully parsed (e.g., set sarifAvailable = true when parse
succeeds in the parsing code path). Update the final gating logic that uses
has_findings and findings_count to also check hadParseErrors and either fail the
action on mixed results (hadParseErrors && findings_count > 0) or clearly
surface parse errors while still honoring readable findings; apply the same
change to both catch sites handling SARIF parsing.
- Around line 20-23: The output name is using a dash variant "has-findings"
while the composite internals use "has_findings"; rename the published output to
follow the repo convention by changing outputs.has-findings to
outputs.has_findings and ensure its value uses the string 'true' or 'false'
(i.e., set value to ${{ steps.parse-outputs.outputs.has_findings }} but
guarantee the upstream step/parse-outputs emits 'true'/'false' strings so the
action boundary exposes has_findings as the boolean-style string output).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7ea5fe3b-2ff4-4459-a81c-4d2cc44b7087

📥 Commits

Reviewing files that changed from the base of the PR and between 5089c6b and 816be6b.

📒 Files selected for processing (1)
  • src/security/codeql-reporter/action.yml

Comment thread src/security/codeql-reporter/action.yml
Comment thread src/security/codeql-reporter/action.yml
Track parse errors independently so a corrupt SARIF file does not
suppress findings from other valid SARIF files. Only show the
unavailable warning when no SARIF directory or files exist at all.
@bedatty
bedatty dismissed coderabbitai[bot]’s stale review March 24, 2026 14:56

All comments addressed.

@lerian-studio lerian-studio added size/L PR changes 500–999 lines and removed size/L PR changes 500–999 lines labels Mar 24, 2026
coderabbitai[bot]
coderabbitai Bot previously requested changes Mar 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/security/codeql-reporter/action.yml`:
- Around line 135-141: Update the SARIF-report message construction so that when
hadParseErrors is true AND findings.length > 0 you still append a warning about
incomplete results; specifically, inside the same conditional block that builds
the body (the code referencing sarifAvailable, hadParseErrors, findings and the
body string), add a branch or an extra append that inserts a warning line
(similar text to the existing parse-error messages) whenever hadParseErrors &&
findings.length > 0 so users see that some SARIF files failed to parse even
though findings were recovered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 56d009ec-bb88-48ce-ac96-4a45b8ca8858

📥 Commits

Reviewing files that changed from the base of the PR and between 816be6b and 79d40ae.

📒 Files selected for processing (1)
  • src/security/codeql-reporter/action.yml

Comment thread src/security/codeql-reporter/action.yml
Remove CodeQL integration from pr-security-scan.yml — will be added
in a separate PR with proper planning for external consumers.
@github-actions github-actions Bot removed the security Changes to security workflows or vulnerability reporting policy label Mar 24, 2026
@lerian-studio lerian-studio added size/L PR changes 500–999 lines and removed size/L PR changes 500–999 lines labels Mar 24, 2026
The dirname extraction was causing CodeQL to scan entire directories
(e.g., all of .github/workflows/) instead of only the changed files.
Now uses exact file paths in the config, ensuring CodeQL only analyzes
the specific files that were modified in the PR.
@lerian-studio lerian-studio added size/L PR changes 500–999 lines and removed size/L PR changes 500–999 lines labels Mar 24, 2026
coderabbitai[bot]
coderabbitai Bot previously requested changes Mar 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/security/codeql-config/action.yml`:
- Around line 12-15: The declared action input "path-mode" is unused: either
remove the input declaration "path-mode" and its corresponding env export
"PATH_MODE" in the env block, or implement logic that consumes PATH_MODE in the
action script to switch between file-based and dir-based changed-path
interpretation; locate the "path-mode" input in the inputs section and the
"PATH_MODE" env assignment in the env block and either delete both or wire
PATH_MODE into the changed-paths handling code so the script checks PATH_MODE
=== "dirs" to treat paths as directories and "files" for exact-file matching.
- Around line 21-23: Rename the boolean output currently named "skip" to follow
the has_<noun> convention and invert its semantics: change the output key "skip"
to "has-paths" (so it is 'true' when paths exist, 'false' when empty) and update
any producers/consumers accordingly; update the action output definition that
references steps.generate.outputs.skip to steps.generate.outputs.has-paths and
adjust any callers (e.g. replace checks like if: steps.config.outputs.skip !=
'true' with if: steps.config.outputs.has-paths == 'true') so all logic now uses
the new "has-paths" output with inverted truth value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d63eb9f2-336f-4d81-9fd0-b3b899894928

📥 Commits

Reviewing files that changed from the base of the PR and between 79d40ae and eab2c6e.

📒 Files selected for processing (1)
  • src/security/codeql-config/action.yml

Comment thread src/security/codeql-config/action.yml Outdated
Comment thread src/security/codeql-config/action.yml
Pre-filter the Security tab URL with pr:<number>+is:open so the link
opens directly to the findings for the current PR.
@lerian-studio lerian-studio added size/L PR changes 500–999 lines and removed size/L PR changes 500–999 lines labels Mar 24, 2026
… input

Add warning in codeql-reporter when findings exist but some SARIF files
failed to parse. Remove unused path-mode input and PATH_MODE env var
from codeql-config (became dead code after dirname removal).
@bedatty
bedatty dismissed stale reviews from coderabbitai[bot] and coderabbitai[bot] March 24, 2026 17:04

All comments addressed.

@lerian-studio lerian-studio added size/L PR changes 500–999 lines and removed size/L PR changes 500–999 lines labels Mar 24, 2026
coderabbitai[bot]
coderabbitai Bot previously requested changes Mar 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/security/codeql-config/action.yml`:
- Around line 33-37: The skip branch that sets "skip=true" when PATHS is empty
leaves the "config-file" output unset; modify the skip branches (the block
checking [ -z "$PATHS" ] and the similar block around lines 42-45) to also emit
an explicit empty "config-file" output so outputs remain deterministic (i.e.,
write a "config-file=" entry to GITHUB_OUTPUT alongside "skip=true" before
exiting).

In `@src/security/codeql-config/README.md`:
- Line 31: Replace the floating action tag "uses:
LerianStudio/github-actions-shared-workflows/src/security/codeql-config@v1.x.x"
with a concrete release tag or an explicit testing branch as required by policy;
update both occurrences (the exact string "uses:
LerianStudio/github-actions-shared-workflows/src/security/codeql-config@v1.x.x")
to either a pinned release like "@vX.Y.Z" for production docs or
"@develop"/"@feat/<branch>" for testing examples so the README examples comply
with the repository tagging guidelines.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9c04dd40-85ae-442f-8455-b9846bd22873

📥 Commits

Reviewing files that changed from the base of the PR and between eab2c6e and 9cdf3c0.

📒 Files selected for processing (3)
  • src/security/codeql-config/README.md
  • src/security/codeql-config/action.yml
  • src/security/codeql-reporter/action.yml

Comment thread src/security/codeql-config/action.yml
Comment thread src/security/codeql-config/README.md
@bedatty
bedatty dismissed coderabbitai[bot]’s stale review March 24, 2026 17:11

All comments addressed.

@bedatty
bedatty merged commit 19abf79 into develop Mar 24, 2026
2 checks passed
@github-actions
github-actions Bot deleted the ci/add-self-codeql branch March 24, 2026 17:45
@coderabbitai coderabbitai Bot mentioned this pull request Mar 24, 2026
14 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Apr 14, 2026
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L PR changes 500–999 lines workflow Changes to one or more reusable workflow files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants