Skip to content

Fix the Sonar quality gate failures in CI - #198

Open
anderslindho wants to merge 8 commits into
ChannelFinder:masterfrom
anderslindho:ci/sonar-security
Open

anderslindho wants to merge 8 commits into
ChannelFinder:masterfrom
anderslindho:ci/sonar-security

Conversation

@anderslindho

Copy link
Copy Markdown
Contributor

The Sonar quality gate fails on the security rating and on unreviewed security hotspots. All of it comes from how CI installs dependencies and pins actions, not from the recCeiver code.

The integration and container jobs now install from a hashed lockfile, like the unit job already did, and third-party actions are pinned to commit SHAs. Dependabot keeps those pins up to date. It covers GitHub Actions only, because it checks Python packages against 3.10 and newer (#194).

Sonar never read server/sonar-project.properties, because automatic analysis only reads .sonarcloud.properties at the repository root. The settings now live there, with the Python versions we test (3.6 to 3.14) and server/tests marked as tests. This removes both analysis warnings.

Two smaller CI fixes are included. The workflow token is read-only, and server.yml now runs on pushes to branches with a slash in the name.

Some findings cannot be fixed in code and will be accepted in Sonar: building recceiver and pyCFClient from source in CI (see #197), and the missing lock file for pyproject.toml, since one lock file cannot cover every Python version we support.

Comment thread .github/workflows/server.yml Fixed
Comment thread .github/workflows/server.yml Fixed
The integration and container jobs resolved their dependencies at
install time, so a new upstream release could change what we test
against without any change here. Sonar flags each of these installs,
and they are most of why the quality gate fails.

`requirements-ci-py39.txt` is now generated from
`requirements-ci-py39.in`, so regenerate it rather than edit it.
A tag can be moved after we have reviewed what it points at, and the
Docker actions run with a token that can push our images. Sonar raises
each tag pin as a security hotspot.
Automatic analysis only reads `.sonarcloud.properties` at the
repository root, so `server/sonar-project.properties` was ignored.
Sonar analysed the code as Python 3.10 and newer, and could not tell
the tests from the code.
Neither workflow writes to the repository, so their token should not be
able to. Without `permissions`, it gets the repository default, which
can include write access.
`*` does not match `/`, so a push to a branch such as `ci/foo` was not
tested until a pull request was opened.
Nobody will update commit SHA pins by hand.

Python packages are left out. Dependabot only checks them against
Python 3.10 and newer, so it proposes versions we cannot install.
We still test on 3.6 and keep it working, even though `requires-python`
starts at 3.7.
pip only checks hashes when the file has them. With the flag, the
install fails instead if the file is ever regenerated without them.
@sonarqubecloud

Copy link
Copy Markdown

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