LAB 08 – Securing SonarQube & handling security findings¶
Story: An auditor asks two questions: "Who can see your vulnerabilities?" and "What happens when SonarQube finds one?" Today the answer to the first one is "everybody with the admin password". Fix that, then build a triage routine for security issues.
| Duration | ~35 min |
| You use | SonarQube Administration (as admin) |
SonarQube holds a map of your weaknesses – protect it like production.
Step 1 – Baseline checks¶
Administration → Configuration → General Settings → Security
- Force user authentication – must be on (default). Verify:
curl -s -o /dev/null -w "%{http_code}\n" "http://localhost:9000/api/components/show?component=bookshelf-py" # 401
- Administration → Security → Users: is anyone still using a default password? (The startup log warns while
admin/adminis active.)
Step 2 – Groups, users and least privilege¶
- Administration → Security → Groups → Create
bookshelf-devs. - Users → Create: login
alice, name Alice Developer, passwordAlice-Training-2026!. Add her tobookshelf-devs. - Project
bookshelf-py→ Project Settings → Permissions - Visibility: Private.
bookshelf-devs: Browse, See Source Code, Administer Issues.- Remove Browse from the group
sonar-users(everybody). - Log in as
alicein a private browser window: she seesbookshelf-py– andbookshelf-javatoo. Why? New projects are public by default (Administration → Projects → Management → Default visibility), and even a private project keeps Browse forsonar-usersfrom the default permission template. Making a project private is not enough – remove the permission fromsonar-users, as you did forbookshelf-py, or use a template (Step 3). - Still as
alice: can she change the quality gate? Can she mark an issue False positive?
Step 3 – Permission templates¶
Manually setting permissions doesn't scale. Administration → Security → Permission Templates → Create
- Name
BookShelf projects, project key patternbookshelf-.* - Grant
bookshelf-devs: Browse, See Source Code, Administer Issues;sonar-administrators: Administer.
Every new project whose key matches the pattern gets these permissions automatically. Test: create a local project bookshelf-web and check its permissions.
Step 4 – Tokens done right¶
- As
admin: My Account → Security – list your tokens. Revokelab-laptopfrom LAB02 when you're done today. - Create a Project Analysis Token
py-ciforbookshelf-py(prefixsqp_). Verify it can only analyse that project:
SONAR_TOKEN=sqp_... ./bin/lab scan-py # works
SONAR_TOKEN=sqp_... ./bin/lab scan-java # Not authorized
- Administration → Security → Users → ⋯ → Tokens: admins can see and revoke any user's tokens. Policy question: how long may a CI token live, and who rotates it? (Enterprise editions can enforce a maximum token lifetime.)
Step 5 – Triage security findings¶
Open Issues for bookshelf-java, filter Software quality = Security.
For each finding decide and record:
| Issue | Exploitable here? | Decision |
|---|---|---|
Hard-coded DB password (BookRepository) |
fix: env var / secret store | |
| SQL built by concatenation | fix: PreparedStatement |
|
| MD5 for passwords | fix: bcrypt / Argon2 / PBKDF2 | |
java.util.Random for session tokens |
fix: SecureRandom |
Fix the token generator:
Commit, push, analyse. Use Accept (with a comment and a ticket number) only for risks the team consciously takes.
Step 6 – Hardening checklist (discussion)¶
- HTTPS: SonarQube behind a reverse proxy (NGINX, Traefik, cloud LB) with
sonar.core.serverBaseURLset. - SSO: delegate authentication (SAML, LDAP, GitHub, GitLab) – and keep local accounts to a minimum. Check which methods your edition supports.
- Database: dedicated user, network isolation, backups; SonarQube data = source code snippets.
- Keep up to date: Community Build releases monthly; Server has an LTA release each year.
- Audit: who changed which gate/profile? (Audit logs are an Enterprise feature – in Community Build keep profiles and gates as code via the Web API.)
Troubleshooting¶
| Symptom | Likely cause |
|---|---|
Alice still sees bookshelf-java |
the project is public, or sonar-users has Browse |
| template not applied | key doesn't match the regex, or the project existed before the template |
| analysis fails with a user token after permission change | the user lost Execute Analysis |
Files for this lab: Think-Cube/sonarqube-labs/labs/LAB08-security