`sonar-scanner` fails with `Not authorized. Please check the user token in the property 'sonar.token' or the environment variable 'SONAR_TOKEN'`
BeginnerTroubleshootingSAST, SCA and secrets scanning in CI
Answer
Likely causes → Token expired or revoked, secret not exposed to the job (forks do not get secrets), wrong host URL, or the token lacks "Execute Analysis" on that project.
Diagnose →
curl -su "$SONAR_TOKEN:" "$SONAR_HOST_URL/api/authentication/validate"
# {"valid":false} means a bad token
Fix → Generate a project analysis token, store it as SONAR_TOKEN in CI secrets, and confirm the job actually receives it ([ -n "$SONAR_TOKEN" ] || exit 1).
Prevent → Use project-scoped tokens with an expiry and a calendar reminder; alert when analyses stop arriving.
More on SAST, SCA and secrets scanning in CI
gitleaks fails the PR on `tests/fixtures/fake_rsa.pem` and `testdata/aws_creds.json`, which only contain dummy valuesBeginnergitleaks passes locally but the CI job reports 40 old leaks nobody touched in this PRIntermediate`fatal: ambiguous argument 'origin/main..HEAD': unknown revision` in the secrets-scan stepBeginnerSemgrep flags `subprocess.run(cmd, shell=True)` in a script where `cmd` is a hard-coded constantBeginnerSemgrep in CI reports findings in `node_modules/`, `vendor/` and minified `dist/*.js`BeginnerSemgrep job takes 35 minutes and gets killed with `exit code 137`Intermediate