Repository navigation
ci: add CodeQL + SonarQube Cloud security scanning - #1
Conversation
Adds the AMMOS scanning pipeline already running on astria_ui: CodeQL -> nasa-scrub translate_results -> fix_sarif_paths.py -> SonarQube Cloud fix_sarif_paths.py is copied verbatim from astria_ui; it repairs the file paths and rule metadata that nasa-scrub degrades, without which every finding imports unlocated and at MEDIUM severity. CodeQL runs with build-mode: none and SonarQube's Java analyzer runs without bytecode, because this project's gov.nasa.jpl.ammos.ids dependencies live in JPL Artifactory and cannot be resolved from a public runner. Both still produce findings, with reduced precision on anything needing resolved types. While the pipeline is validated, the workflow triggers on a push to this branch and pins -Dsonar.branch.name=main, so test runs land on main's analysis instead of creating a second branch in the SonarQube project. Both are flagged in-file for removal once the results look right. Claude-Session: https://claude.ai/code/session_011WeGYwtRQbXf1wJE7YzvYW
Brings this workflow in line with the MMGIS security-scan setup and retires the bootstrap triggers used to validate the pipeline: - push now triggers on main only, not on the feature branch - pull_request triggers on any PR targeting main, from any source branch - concurrency group per ref, cancelling superseded in-progress PR runs but never cancelling a run on main - the job is skipped for PRs from forks, which have no SONAR_TOKEN and would otherwise fail red for a reason the contributor cannot fix Branch attribution is now left to the scanner's GitHub Actions auto-detection: a push to main analyzes as main, and a PR analyzes as a SonarQube pull request, which expires with the PR rather than becoming a long-lived branch in the project. Only workflow_dispatch still pins -Dsonar.branch.name=main, so validating the pipeline by hand cannot leave a stray branch behind. Claude-Session: https://claude.ai/code/session_011WeGYwtRQbXf1wJE7YzvYW
martyvona
left a comment
There was a problem hiding this comment.
all the comments I left for NASA-AMMOS/tile_service#1 also apply here
…t of the Maven job Ports tile_service#1's Security-Scan changes: - Probe pom.xml dependencies against public repositories. If they all resolve, CodeQL runs with build-mode manual and the project is compiled; otherwise fall back to build-mode none as before. - Split into a codeql job (probe, build, analyze, repair SARIF; no secrets) and a sonarqube job that only downloads the SARIF and any compiled classes and runs the scanner. - Drop the JPL Artifactory references and stop naming a specific dependency as the build blocker. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Devin Review found 2 potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| if force_level or 'level' not in result: | ||
| level = (rules[index].get('defaultConfiguration') or {}).get('level') | ||
| if level: | ||
| result['level'] = level |
There was a problem hiding this comment.
🟡 Explicit finding severity lost during repair
When a CodeQL finding overrides its rule's default, apply_rules assigns the default instead of the finding's original level. The finding imports with the wrong severity.
Learn more
A SARIF result can set its own level, independently of its rule's defaultConfiguration.level. Scrub flattens levels in the processed report, so restoring the rule default fixes only results that originally inherited it. The original result levels remain available in the reference report loaded by fix_sarif, but restore_rules passes only its rules to apply_rules. An explicitly overridden result therefore loses its severity.
Example: The reference rule defaults to warning, but its result explicitly says error. Scrub writes warning; repair writes warning again instead of restoring error.
Recommended fix: Match each processed result to its original result using a reliable stable identifier or preserved ordering, and restore an explicit reference level when present. Apply the rule default only when the reference result has no explicit level; add a test covering both cases.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Deferring this one, same as on tile_service#1. nasa-scrub writes the same flat level for every result, so force_level=True puts back the rule default deliberately. To also keep per-result overrides, each scrubbed result has to be matched to its original reliably. This script is shared verbatim with astria_ui and tile_service, so that fix (with tests) should go into all three repos together rather than only this PR.
| if: >- | ||
| github.event_name != 'pull_request' || | ||
| github.event.pull_request.head.repo.full_name == github.repository |
There was a problem hiding this comment.
Correct: fork PRs skip both jobs, and the split doesn't change that. codeql doesn't need secrets, but a fork PR's GITHUB_TOKEN is read-only. That means security-events: write isn't granted, so CodeQL's upload to code scanning would fail. Without SONAR_TOKEN, sonarqube can't run either. Fork changes are still scanned once merged, on the push to main.
Scanning forks before merge would mean running codeql with upload: never for forks and keeping the SARIF as an artifact only. tile_service#1 merged with the same behavior, so if we want that, it should be a follow-up across the repos.
|



What
Adds the AMMOS code vulnerability scanning pipeline:
Following the AMMOS scanning guide.
.github/workflows/security-scan.yml.github/codeql/codeql-config.yml.github/scripts/fix_sarif_paths.pynasa-scrubdegrades.github/scripts/test_fix_sarif_paths.pysonar-project.propertiesWhy the SARIF repair step exists
nasa-scrub'stranslate_resultsis the step the AMMOS guide prescribes, and it is kept for compliance, but it is lossy. It rewrites CodeQL's workspace-relative URIs to absolute paths and writes the absolute source root intouriBaseId, which stops SonarQube mapping findings to files. It also deletestool.extensions— where CodeQL keeps its real rule metadata — and rebuildstool.driver.rulesas id-only stubs, so every finding imports as MEDIUM regardless of its true severity.fix_sarif_paths.pyrestores both from the pre-scrub report. It is shared verbatim acrossastria_ui,mis_rest_serviceandtile_service— fix it in one, copy to all.Triggers
main— analyzed asmainmain, from any source branch — analyzed as a SonarQube pull request, which expires with the PR and never becomes a long-lived branch in the projectworkflow_dispatch— pins-Dsonar.branch.name=mainso validating the pipeline by hand cannot leave a stray branch behindPRs from forks are skipped: they run without repository secrets, so
SONAR_TOKENwould be empty and the scan would fail red for a reason the contributor cannot fix.A concurrency group per ref supersedes in-progress PR runs when new commits arrive, and never cancels a run on
main.Build mode is chosen per run
Each run first asks Maven to resolve every dependency in
pom.xml(mvn -B -q dependency:resolve):While a dependency is not yet publicly available, scans run source-only with reduced precision on anything needing resolved types. Once every dependency is published, scans switch to the full build on their own; nothing in the workflow or
sonar-project.propertiesneeds to change. After that, a genuine compile failure turns the check red. Any resolution failure (including a network error or Maven Central rate limit) also falls back to source-only.SONAR_TOKENnever shares a job with MavenThe workflow is two jobs, so PR-controlled build code (plugins, dependencies) never runs alongside the token:
codeql(no secrets): probe, optional build, CodeQL,nasa-scrub,fix_sarif_paths.py; uploads the processed SARIF and, if built,target/classesas artifacts.sonarqube(needs: codeql): checks out, reads the version frompom.xmlwithsed, downloads the artifacts, runs the scanner. Never runs Maven.Same structure as tile_service#1; the workflow differs only in repo-name comments.
Verified
A scan of this branch pinned to
mainran green and imported cleanly:external_CodeQL(notexternal_java) —driver.namerestoredmainonlyThe two-job workflow (
755c585) also ran green on this PR in source-only mode.Link to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/86093dc594e44c788862ddb10afd3903
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/86093dc594e44c788862ddb10afd3903?variant=devin
Requested by: @jl-0