Skip to content

AAP-81136 - Add workflow for SonarCloud reporting - #45

Open
jessicamack wants to merge 7 commits into
ansible:develfrom
jessicamack:add-sonarcloud
Open

AAP-81136 - Add workflow for SonarCloud reporting#45
jessicamack wants to merge 7 commits into
ansible:develfrom
jessicamack:add-sonarcloud

Conversation

@jessicamack

@jessicamack jessicamack commented Jul 15, 2026

Copy link
Copy Markdown
Member

JIRA: https://redhat.atlassian.net/browse/AAP-81136

Add workflow for automatic SonarCloud code analysis.

Summary by CodeRabbit

  • Chores
    • Added SonarCloud code-quality scanning for pull requests, running automatically after successful CI.
    • Added SonarCloud branch analysis for successful pushes.
    • Automatically incorporates CI-generated coverage reports into analyses when available.
    • Improves pull request targeting by using PR metadata and running a focused scan on changed files when possible; falls back to a full scan if changed files can’t be retrieved.
  • Configuration
    • Added SonarCloud analysis configuration for the project, including source/test scope, report paths, and rule/exclusion settings.

@jessicamack
jessicamack requested a review from thedoubl3j July 15, 2026 15:35
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adds SonarCloud project configuration and a post-CI GitHub Actions workflow for pull request and branch analysis, including coverage discovery, repository metadata, changed-file inclusions, and commit-specific scanning.

Changes

SonarCloud analysis

Layer / File(s) Summary
Analysis configuration
sonar-project.properties
Defines project identity, source and test scopes, report paths, new-code settings, and analysis exclusions.
Pull request analysis
.github/workflows/sonarcloud_pr.yml
Runs after successful pull request CI, retrieves metadata and changed files, discovers coverage reports, checks out the tested commit, and invokes the PR scan.
Branch analysis
.github/workflows/sonarcloud_pr.yml
Runs after successful push CI, checks out the workflow commit, discovers optional coverage reports, and invokes the branch scan with branch metadata.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CI
  participant SonarWorkflow
  participant GitHubAPI
  participant SonarCloud
  CI->>SonarWorkflow: Complete successfully
  SonarWorkflow->>GitHubAPI: Fetch PR refs and changed files
  GitHubAPI-->>SonarWorkflow: Return PR metadata
  SonarWorkflow->>SonarCloud: Run PR scan with revision and inclusions
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding SonarCloud reporting workflow support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/sonarcloud_pr.yml:
- Around line 47-49: Add persist-credentials: false to both actions/checkout@v4
steps in the workflow, including the checkout near the coverage artifact
download and the later checkout around line 210. Keep the existing checkout
behavior unchanged otherwise.
- Around line 84-137: The PR-number handling is contradictory: the fatal exit
before the changed-files logic makes the “PR Number not available” fallback
unreachable. Update the PR metadata flow around the PR_NUMBER validation and
changed-files conditional so missing PR_NUMBER follows the existing full-scan
fallback, or remove that fallback if missing PR numbers must remain fatal;
ensure only the intended behavior remains and avoid exporting or using an
unavailable PR number.
- Line 37: Replace the workflow-wide permissions: read-all declaration with an
explicit least-privilege permissions block. Grant only the scopes required by
the workflow, such as contents: read, actions: read for artifact downloads, and
pull-requests: read, while preserving any permissions needed by the jobs.
- Around line 193-199: Update the SonarCloud pull-request workflow args to
conditionally add -Dsonar.python.coverage.reportPaths only when
env.COVERAGE_PATHS is non-empty, matching the existing branch-job behavior;
preserve the other scanner arguments unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 5b1c0c76-5a84-4e00-b8dd-256ad695d4a7

📥 Commits

Reviewing files that changed from the base of the PR and between b52a9f8 and c5d8985.

📒 Files selected for processing (1)
  • .github/workflows/sonarcloud_pr.yml

Comment thread .github/workflows/sonarcloud_pr.yml Outdated
Comment thread .github/workflows/sonarcloud_pr.yml Outdated
Comment thread .github/workflows/sonarcloud_pr.yml
Comment thread .github/workflows/sonarcloud_pr.yml Outdated

@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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/sonarcloud_pr.yml:
- Around line 37-40: Update the top-level permissions block to replace the
invalid pull_requests scope with the valid pull-requests scope, preserving the
existing contents and actions permissions.
- Around line 55-61: Update the “Download coverage artifacts” step using
dawidd6/action-download-artifact so missing api-test-artifacts do not fail the
workflow; enable continue-on-error or configure if_no_artifact_found to a
non-failing mode, while preserving the existing artifact selection and later
fallback behavior.
- Around line 175-181: Update the “Add base branch” workflow step to validate
PR_NUMBER as numeric before using it and pass the validated value quoted to
GitHub CLI/API commands. Pin checkout to github.event.workflow_run.head_sha
instead of the PR’s current head, ensuring SonarCloud analyzes the exact
CI-tested commit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 3361eed7-30eb-4eb3-a28f-8269591a2ce4

📥 Commits

Reviewing files that changed from the base of the PR and between c5d8985 and c2dc2c2.

📒 Files selected for processing (1)
  • .github/workflows/sonarcloud_pr.yml

Comment thread .github/workflows/sonarcloud_pr.yml Outdated
Comment thread .github/workflows/sonarcloud_pr.yml Outdated
Comment thread .github/workflows/sonarcloud_pr.yml Outdated
@djulich

djulich commented Jul 17, 2026

Copy link
Copy Markdown

Summary

This PR adds a single GitHub Actions workflow file (.github/workflows/sonarcloud_pr.yml, 245 lines) that runs SonarCloud analysis after CI completion. It uses the workflow_run trigger pattern with two jobs:

  • sonar-pr-analysis -- runs on PR CI completion, scans changed files with coverage
  • sonar-branch-analysis -- runs on push CI completion (devel), scans full codebase

Overall Assessment

The workflow_run trigger is the correct pattern for analyzing fork PRs that need access to secrets (like SONAR_TOKEN). Permissions are scoped to read-only, third-party actions are SHA-pinned, and a repo guard prevents execution on forks. The structure is sound.

There are several issues to address -- some already flagged by CodeRabbit (see cross-references below), and some additional ones.

SonarCloud Onboarding -- only partially addressed

The ticket describes 3 steps:

  1. Create a new SonarCloud project -- Not verifiable from this PR. Presumably done out-of-band in the SonarCloud UI.
  2. Configure automatic analysis or GitHub Actions-based scanning -- This is what the PR delivers.
  3. Verify the quality gate is passing and metrics are being reported -- Cannot be verified until the workflow runs successfully.

Gap: No sonar-project.properties

The ticket references the existing AWX SonarCloud project as a model. The ansible/awx repo has a sonar-project.properties that configures the project key, organization, source paths, and exclusions. This PR's workflow comments reference that file (line 24: "see sonar-project.properties"), but the file does not exist in the repo. Without it, SonarCloud will use defaults which may not reflect the intended configuration. This should either be added in this PR or confirmed as intentionally deferred.

Open CodeRabbit Issues (not yet addressed)

The first CodeRabbit review round (on c5d8985) raised 4 issues, all marked as addressed in commit c2dc2c2. A second review round found 3 new issues, all of which remain open:

CR-1: Invalid permission scope pull_requests (line 40)

CodeRabbit: Critical -- pull_requests is not a valid GitHub Actions permission scope. The correct form is pull-requests (hyphenated). An invalid key in the top-level permissions: block can cause the workflow to be rejected entirely, silently blocking all SonarCloud analysis.

My take: Agree, this is a blocker. The gh api calls later in the job depend on pull-request read permissions.

 permissions:
   contents: read
   actions: read
-  pull_requests: read
+  pull-requests: read

CR-2: PR artifact download should tolerate missing artifacts (line 55-61)

CodeRabbit: Major -- dawidd6/action-download-artifact defaults to failing when no artifact matches the pattern. Docs-only PRs (or PRs where CI produced no coverage artifacts) will fail here before reaching the "PR number not found" fallback. The branch analysis job already uses continue-on-error: true for this step.

My take: Agree. Add continue-on-error: true or use the action's if_no_artifact_found: ignore option to match the branch job's behavior.

CR-3: Validate PR_NUMBER as numeric and pin checkout to tested SHA (lines 175-181)

CodeRabbit: Critical -- PR_NUMBER is extracted from downloaded coverage data and used unquoted in gh commands. It should be validated as numeric. Additionally, gh pr checkout follows the PR's current head, not the SHA that CI actually tested (github.event.workflow_run.head_sha), creating a TOCTOU (time-of-check/time-of-use) gap.

My take: Partially agree. The numeric validation is a good hardening step. The TOCTOU concern about gh pr checkout vs pinning to the tested SHA is worth considering, though in practice the window is small and SonarCloud uses -Dsonar.scm.revision to identify the exact commit. The bigger risk is that gh pr checkout pulls code from a fork into a job that has access to SONAR_TOKEN -- see my additional finding below.

Additional Findings

A-1: actions/checkout@v4 not SHA-pinned (lines 48, 179)

The two third-party actions (dawidd6/action-download-artifact, SonarSource/sonarqube-scan-action) are pinned to specific commit SHAs. actions/checkout@v4 uses a mutable tag. For consistency and supply-chain hardening, pin it to a SHA.

Severity: Low -- GitHub's own actions are well-maintained, but consistency with the rest of the file matters.

A-2: PR number extraction from coverage.xml is fragile (lines 80-82)

The workflow extracts PR_NUMBER by parsing a comment embedded in coverage.xml:

PR_NUMBER=$(grep -m 1 '<!-- PR' "$first_coverage" | awk '{print $3}' || echo "")

This creates a tight coupling between this workflow and the CI workflow's coverage output format. If the CI workflow changes how it emits the coverage file, this breaks silently.

Recommendation: Use the canonical workflow_run API instead:

github.event.workflow_run.pull_requests[0].number

This is the standard GitHub mechanism for getting the PR number from a workflow_run event and removes the dependency on artifact content. Note: for cross-fork PRs, pull_requests may be empty -- in that case the coverage.xml fallback could serve as a secondary lookup, but shouldn't be the primary path.

A-3: Duplicate summary block (lines 83-88 and 97-104)

The "SonarCloud Analysis Decision Summary" header and initial lines are printed twice -- once before the PR_NUMBER validation and again after the API call. The first block always runs and gets buried by the second. Remove the first one.

A-4: gh pr checkout checks out fork code with access to secrets (lines 159-162)

The gh pr checkout step replaces the workspace with the fork's code. The SonarCloud scan then runs on this code in a job that has access to SONAR_TOKEN and GITHUB_TOKEN. If the fork includes a modified sonar-project.properties, it could alter scan behavior (e.g., change the project key, modify exclusions, or redirect results).

Mitigation options:

  • Back up sonar-project.properties before checkout and restore it after
  • Use actions/checkout with explicit ref and repository instead of gh pr checkout
  • At minimum, document this as an accepted risk

This connects to CodeRabbit's CR-3 (pin to tested SHA) -- both are about controlling what code ends up in the workspace.

A-5: Missing sonar-project.properties file

The workflow comments reference sonar-project.properties for exclusion configuration (line 24: "see sonar-project.properties"), but this file does not exist in the repository on either add-sonarcloud or devel. The SonarCloud scan will use its defaults, which may not match the documented behavior. Either add it in this PR or remove the references.

A-6: Hardcoded .coveragerc exclusion patterns will drift (lines 142-144)

filtered_files=$(echo "$files" | grep -v "settings/.*_defaults\.py$" \
  | grep -v "settings/defaults\.py$" | grep -v "main/migrations/")

These patterns duplicate what's presumably in .coveragerc. If .coveragerc changes, this will silently drift. Consider parsing .coveragerc directly, or at minimum add a comment pointing maintainers to keep both in sync.

A-7: COMMIT_SHA written to $GITHUB_ENV redundantly (line 110)

COMMIT_SHA is already set as a step-level env variable (line 71). Writing it again to $GITHUB_ENV (line 110) is redundant for the current step but does make it available to subsequent steps. This is fine functionally but adds noise -- a comment clarifying this is intentional for cross-step access would help.

Summary Table

# Source Severity Status Description
CR-1 CodeRabbit Critical Open pull_requests -> pull-requests (invalid scope)
CR-2 CodeRabbit Major Open Artifact download should tolerate missing artifacts
CR-3 CodeRabbit Critical Open Validate PR_NUMBER + pin checkout to tested SHA
A-1 This review Low New actions/checkout@v4 not SHA-pinned
A-2 This review Major New PR number extraction from coverage.xml is fragile
A-3 This review Low New Duplicate summary block
A-4 This review Medium New Fork code checked out with access to secrets
A-5 This review Medium New Missing sonar-project.properties file
A-6 This review Low New Hardcoded .coveragerc patterns will drift
A-7 This review Low New Redundant COMMIT_SHA env export

Recommendation: Address CR-1 (blocker -- invalid permission scope), CR-2, A-2, and A-5 before merge. The rest are improvements that can be addressed in a follow-up.

@tvo318 tvo318 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code Review - made possible by Claude Qodo PR Review Skill

The workflow structure is solid — using workflow_run for fork-safe SonarCloud analysis with pinned action SHAs is the right approach. Found a few items worth addressing, mostly around API pagination, checkout configuration, and log accuracy.

Comment thread .github/workflows/sonarcloud_pr.yml Outdated
Comment thread .github/workflows/sonarcloud_pr.yml Outdated
Comment thread .github/workflows/sonarcloud_pr.yml Outdated
Comment thread .github/workflows/sonarcloud_pr.yml Outdated
Comment thread .github/workflows/sonarcloud_pr.yml Outdated
Comment thread .github/workflows/sonarcloud_pr.yml Outdated

@thedoubl3j thedoubl3j left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar to Dirk's review, a project properties file is needed as part of this. That can also be lifted from AWX and changed appropriately for this repo.

@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

🧹 Nitpick comments (2)
sonar-project.properties (2)

106-108: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Comment doesn't match the rule it describes.

python:S1192 flags duplicated string literals, not "should be a variable in migrations." The stale/incorrect comment could confuse future maintainers about why this rule is suppressed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sonar-project.properties` around lines 106 - 108, Update the comment above
sonar.issue.ignore.multicriteria.e1.ruleKey to accurately describe that
python:S1192 suppresses duplicated string literal findings, removing the
incorrect “should be a variable in migrations” description while leaving the
rule configuration unchanged.

70-99: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Exclusion patterns duplicated across config and workflow.

sonar.exclusions/sonar.coverage.exclusions here overlap with the coverage-omit filtering logic hardcoded in the workflow (.github/workflows/sonarcloud_pr.yml), which independently greps for settings/.*_defaults\.py, main/migrations/, etc. Keeping both in sync manually risks drift; consider deriving the workflow's exclusion list from this file (or .coveragerc) instead of hardcoding it separately.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sonar-project.properties` around lines 70 - 99, Centralize SonarCloud
exclusion handling by updating the workflow’s coverage-omit filtering to derive
patterns from the existing sonar-project.properties or .coveragerc configuration
instead of maintaining a separate hardcoded list. Preserve the current
exclusions, including settings defaults and migrations, while removing the
duplicated workflow-specific pattern definitions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sonar-project.properties`:
- Around line 55-56: Update the sonar.python.xunit.reportPath setting to use the
same project-relative path format as sonar.python.coverage.reportPaths by
removing the leading slash from the JUnit report path.

---

Nitpick comments:
In `@sonar-project.properties`:
- Around line 106-108: Update the comment above
sonar.issue.ignore.multicriteria.e1.ruleKey to accurately describe that
python:S1192 suppresses duplicated string literal findings, removing the
incorrect “should be a variable in migrations” description while leaving the
rule configuration unchanged.
- Around line 70-99: Centralize SonarCloud exclusion handling by updating the
workflow’s coverage-omit filtering to derive patterns from the existing
sonar-project.properties or .coveragerc configuration instead of maintaining a
separate hardcoded list. Preserve the current exclusions, including settings
defaults and migrations, while removing the duplicated workflow-specific pattern
definitions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 46faf938-26fa-45f1-b8fb-1c7b8e8029d6

📥 Commits

Reviewing files that changed from the base of the PR and between c2dc2c2 and f15ac64.

📒 Files selected for processing (2)
  • .github/workflows/sonarcloud_pr.yml
  • sonar-project.properties
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/sonarcloud_pr.yml

Comment thread sonar-project.properties Outdated

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/workflows/sonarcloud_pr.yml (1)

51-54: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

PR job checkout never actually fetches the tested commit — git checkout "$COMMIT_SHA" will fail.

The initial checkout (Lines 51-54) has no ref:, so it checks out the default branch (the workflow_run context always resolves to the default branch unless ref: is set — exactly why the branch job at Line 198 was fixed to use ref: ${{ github.event.workflow_run.head_sha }}). Later, Lines 163-168 try to compensate by running git fetch origin "$PR_BASE" then git checkout "$COMMIT_SHA". Fetching the base branch by name does not bring the PR head commit into the local repo — that commit lives on a different branch (and for fork PRs, isn't even a branch of origin at all). Unless $COMMIT_SHA happens to already be an ancestor of the default branch (e.g., already merged), this checkout will fail with fatal: reference is not a tree, breaking the PR analysis job for essentially every open PR.

Mirror the branch job's fix: pin ref: on the initial checkout to the tested commit. GitHub allows fetching arbitrary reachable SHAs (this is exactly how the branch job's ref: head_sha pattern already works for fork-triggered workflow_run).

🐛 Proposed fix
       - uses: actions/checkout@v4
         with:
+          ref: ${{ github.event.workflow_run.head_sha }}
           fetch-depth: 0
           persist-credentials: false
           # Fetch the PR branch for SonarCloud PR analysis comparison
           git fetch origin "$PR_BASE"
-
-          # Checkout the exact commit that CI tested, not the current PR head
-          # This ensures SonarCloud analyzes the same code that CI validated
-          git checkout "$COMMIT_SHA"
+          # Already checked out at $COMMIT_SHA via the initial checkout step's `ref:`.

Also applies to: 163-168

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/sonarcloud_pr.yml around lines 51 - 54, Pin the initial PR
checkout in the workflow’s actions/checkout@v4 step to the tested workflow_run
head commit by adding the appropriate ref value, matching the existing
branch-job pattern. Ensure the later git checkout of COMMIT_SHA can resolve the
PR head, including commits from forked repositories, without relying on fetching
PR_BASE.
🧹 Nitpick comments (2)
.github/workflows/sonarcloud_pr.yml (2)

51-54: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Pin actions/checkout to a commit SHA for consistency with the other pinned actions in this workflow.

dawidd6/action-download-artifact and SonarSource/sonarqube-scan-action are already pinned to commit SHAs, but both actions/checkout@v4 uses (Line 51, Line 196) still use a mutable tag. For supply-chain consistency and to avoid a compromised tag silently swapping in different behavior.

uses: actions/checkout@<pinned-sha> # v4

Also applies to: 196-200

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/sonarcloud_pr.yml around lines 51 - 54, Pin both
actions/checkout usages in the workflow, including the steps around the existing
fetch-depth settings, to an immutable commit SHA while retaining the v4 version
comment. Do not change the checkout configuration or the other already-pinned
actions.

172-184: 🔒 Security & Privacy | 🔵 Trivial

Scanning PR/fork code with access to org secrets deserves an explicit mitigation note.

This workflow runs via workflow_run, so it executes with base-repo permissions and has access to SONAR_TOKEN/GITHUB_TOKEN while operating on code checked out from the PR (potentially a fork, once the checkout fix above is applied to actually pull the PR's commit). This is the classic "pwn request" pattern: if anything in the scan pipeline (custom Sonar plugins, build hooks invoked by the scanner, etc.) executes attacker-controlled repo content, secrets could be exfiltrated. Worth documenting the trust boundary explicitly (e.g., confirm the SonarCloud scanner action doesn't execute repo-provided build/config scripts, and that SONAR_TOKEN/GITHUB_TOKEN scopes are minimal) since this is called out as an open concern in the PR objectives.

Also applies to: 229-238

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/sonarcloud_pr.yml around lines 172 - 184, Document the
workflow_run trust boundary near the SonarCloud Scan step, explicitly noting
that PR or fork code is scanned with base-repository GITHUB_TOKEN and
SONAR_TOKEN access. Record the required mitigations: verify the scanner does not
execute repository-controlled build/config scripts, and ensure both token
permissions and SonarCloud token scope are minimal.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In @.github/workflows/sonarcloud_pr.yml:
- Around line 51-54: Pin the initial PR checkout in the workflow’s
actions/checkout@v4 step to the tested workflow_run head commit by adding the
appropriate ref value, matching the existing branch-job pattern. Ensure the
later git checkout of COMMIT_SHA can resolve the PR head, including commits from
forked repositories, without relying on fetching PR_BASE.

---

Nitpick comments:
In @.github/workflows/sonarcloud_pr.yml:
- Around line 51-54: Pin both actions/checkout usages in the workflow, including
the steps around the existing fetch-depth settings, to an immutable commit SHA
while retaining the v4 version comment. Do not change the checkout configuration
or the other already-pinned actions.
- Around line 172-184: Document the workflow_run trust boundary near the
SonarCloud Scan step, explicitly noting that PR or fork code is scanned with
base-repository GITHUB_TOKEN and SONAR_TOKEN access. Record the required
mitigations: verify the scanner does not execute repository-controlled
build/config scripts, and ensure both token permissions and SonarCloud token
scope are minimal.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2eb299ae-6171-4701-beff-c496fa8bfda8

📥 Commits

Reviewing files that changed from the base of the PR and between f15ac64 and 51dc554.

📒 Files selected for processing (2)
  • .github/workflows/sonarcloud_pr.yml
  • sonar-project.properties
🚧 Files skipped from review as they are similar to previous changes (1)
  • sonar-project.properties

@jessicamack
jessicamack requested review from thedoubl3j and tvo318 July 28, 2026 13:51
Comment thread .github/workflows/sonarcloud_pr.yml Outdated

@webknjaz webknjaz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(drive-by notes)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(personal request, preexisting convention)

Could you use kebab-case style name for this file?

Comment thread .github/workflows/sonarcloud_pr.yml
Comment thread .github/workflows/sonarcloud_pr.yml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This piece of automation doesn't seem unique enough to be attached to the project — I'd maybe look into having a composite action or a reusable workflow in a shared repository rather than here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While I agree that it should be, the ask to implement sonar has been quick and delivery wants to be quick. I do think its something that we could look into but I think that would need to be at an org level.

# 7363/32
name: SonarCloud
on:
workflow_run: # This is triggered by CI being completed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another approach could be having "modules" of form reusable-*.yml plugged into ci-cd.yml.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do you have an example of what this would look like? Would they be a job that uses the reusable-*yml like https://github.com/ansible/awx_plugins.interfaces/blob/devel/.github/workflows/ci-cd.yml#L336? Do we want them stored under /reusable or in the potential new shared repo for these workflows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants