Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing SCA / SAST scans to CI #196

Merged
merged 1 commit into from
May 30, 2024
Merged

Conversation

ChrisBAshton
Copy link
Contributor

@ChrisBAshton ChrisBAshton commented Apr 29, 2024

This will resolve the alert at https://gds.slack.com/archives/C02L13S214K/p1714381348726429.

NB, this took a bit of effort! We were seeing an error with the default code analysis:

Extracting javascript
Extracting ruby
Finalizing javascript
Finalizing ruby
  /opt/hostedtoolcache/CodeQL/2.17.1/x64/codeql/codeql database finalize --finalize-dataset --threads=4 --ram=14567 /home/runner/work/_temp/codeql_databases/ruby
  CodeQL detected code written in JavaScript/TypeScript, but not any written in Ruby. Confirm that there is some source code for Ruby in the project. For more information, review our troubleshooting guide at https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build .
  Error: Encountered a fatal error while running "/opt/hostedtoolcache/CodeQL/2.17.1/x64/codeql/codeql database finalize --finalize-dataset --threads=4 --ram=14567 /home/runner/work/_temp/codeql_databases/ruby". Exit code was 32 and last log line was: CodeQL detected code written in JavaScript/TypeScript, but not any written in Ruby. Confirm that there is some source code for Ruby in the project. For more information, review our troubleshooting guide at https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build . See the logs for more details.

We explored configuring the reusable workflow to take a languages input, but there doesn't seem to be a way of defaulting to 'undefined' if the parameter isn't passed, meaning we'd have to set a default of, say, 'ruby'. This would break the workflow for repos that may already be working with both Ruby and JS, where they'd be forced to pass the languages parameter now.

We also explored setting up CodeQL directly within the GitHub UI and explicitly opting out of Ruby to have JS only, but the reusable workflow still does a language detection and runs both JS and Ruby scans (the "JS only" scan appears as a separate job called "CodeQL / Analyze (javascript-typescript) (dynamic)"):

Screenshot 2024-05-29 at 09 50 26

Eventually, on closer inspection, we found that the only ruby in this project was a disused Rakefile, so we removed it in #198. Now the CodeQL scan passes.

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@ChrisBAshton ChrisBAshton force-pushed the ChrisBAshton-patch-1 branch 2 times, most recently from fa0ab2a to 993ea59 Compare May 29, 2024 08:57
@ChrisBAshton ChrisBAshton changed the title Add missing Snyk / SCA / SAST scans to CI Add missing SCA / SAST scans to CI May 29, 2024
@ChrisBAshton ChrisBAshton force-pushed the ChrisBAshton-patch-1 branch from 993ea59 to ffbfaeb Compare May 29, 2024 09:59
ChrisBAshton added a commit that referenced this pull request May 29, 2024
The build script has been replaced by
https://github.com/alphagov/govuk-browser-extension/blob/9a5ae779e126b09fd303147d91c616c0fa527462/build.sh#L1

And the jasmine test script has been replaced by NPM:
https://github.com/alphagov/govuk-browser-extension/blob/7913847c4aa8b366826ada973264798cdb113ed2/.github/workflows/ci.yml#L36-L37

The presence of the Rakefile is causing issues for our CodeQL
integration in #196, which is detecting Ruby but then failing to
run the scan. It is hoped that removing the Rakefile will resolve
this.
@ChrisBAshton ChrisBAshton force-pushed the ChrisBAshton-patch-1 branch 2 times, most recently from 17fa475 to 424ff00 Compare May 29, 2024 14:32
@ChrisBAshton ChrisBAshton marked this pull request as ready for review May 29, 2024 14:33
This will resolve the alert at https://gds.slack.com/archives/C02L13S214K/p1714381348726429.

NB, this took a bit of effort! We were [seeing](https://github.com/alphagov/govuk-browser-extension/actions/runs/9283183060/job/25542847886?pr=196) an error with the default code analysis:

```
Extracting javascript
Extracting ruby
Finalizing javascript
Finalizing ruby
  /opt/hostedtoolcache/CodeQL/2.17.1/x64/codeql/codeql database finalize --finalize-dataset --threads=4 --ram=14567 /home/runner/work/_temp/codeql_databases/ruby
  CodeQL detected code written in JavaScript/TypeScript, but not any written in Ruby. Confirm that there is some source code for Ruby in the project. For more information, review our troubleshooting guide at https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build .
  Error: Encountered a fatal error while running "/opt/hostedtoolcache/CodeQL/2.17.1/x64/codeql/codeql database finalize --finalize-dataset --threads=4 --ram=14567 /home/runner/work/_temp/codeql_databases/ruby". Exit code was 32 and last log line was: CodeQL detected code written in JavaScript/TypeScript, but not any written in Ruby. Confirm that there is some source code for Ruby in the project. For more information, review our troubleshooting guide at https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build . See the logs for more details.
```

We explored configuring the [reusable workflow](https://github.com/alphagov/govuk-infrastructure/blob/main/.github/workflows/codeql-analysis.yml) to take a `languages` input, but there [doesn't seem to be a way of defaulting to 'undefined'](actions/runner#924) if the parameter isn't passed, meaning we'd have to set a default of, say, 'ruby'. This would break the workflow for repos that may already be working with both Ruby and JS, where they'd be forced to pass the `languages` parameter now.

We also explored setting up CodeQL directly within the GitHub UI and explicitly opting out of Ruby to have JS only, but the reusable workflow still does a language detection and runs both JS and Ruby scans (the "JS only" scan appears as a separate job called "CodeQL / Analyze (javascript-typescript) (dynamic)"):

![Screenshot 2024-05-29 at 09 50 26](https://github.com/alphagov/govuk-browser-extension/assets/5111927/114bb17b-ac2e-4f42-8560-a0df69a49178)

Eventually, on closer inspection, we found that only ruby in this
project was a disused Rakefile, so we removed it in #198. Now the
CodeQL scan passes.
@ChrisBAshton ChrisBAshton force-pushed the ChrisBAshton-patch-1 branch from 424ff00 to c7667e9 Compare May 29, 2024 14:36
@ChrisBAshton ChrisBAshton merged commit 54c6d14 into main May 30, 2024
5 checks passed
@ChrisBAshton ChrisBAshton deleted the ChrisBAshton-patch-1 branch May 30, 2024 08:30
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.

2 participants