Users, Groups, Permissions, Tokens, Authentication, and Authorization: Guided Hands-On Workflow
Create two disposable teams on a local Community Build instance, apply project permission templates, prove allow/deny behavior, use narrow credentials, revoke them, and verify failure after revocation.
Learning objectives
- Build two disposable users/groups/projects on a local Community Build instance.
- Preserve and safely change the default global Execute Analysis grant so project-level isolation is measurable.
- Apply a project-key permission template and prove cross-team allow/deny behavior.
- Create a project-analysis token for scanning and a limited user token for read-only API evidence.
- Revoke both token types and prove the dependent actions fail afterward.
- Restore the original global permission and clean up only the lab resources.
1. Lab contract and safety boundary
| Item | Lab value |
|---|---|
| SonarQube |
Community Build 26.9.0.129388 at
http://localhost:9000
|
| Scanner | SonarScanner CLI 8.1.0.6389 |
| Projects |
sq-ch21-alpha-app,
sq-ch21-beta-app
|
| Users |
sq21-alpha, sq21-beta (local
disposable accounts)
|
| Groups |
sq-ch21-alpha-devs,
sq-ch21-beta-devs
|
| Visibility | Private for both projects |
| Credentials | Project-analysis tokens for scanners; limited user tokens for API verification |
2. Preflight: capture the starting authorization state
Before changing anything, record the server/scanner versions and capture screenshots or exported notes for:
-
Administration → Security → Global Permissions,
especially the
sonar-usersExecute Analysis grant. - Administration → Security → Groups and Users.
- Administration → Security → Permission Templates.
- Administration → Projects → Management and the default visibility.
export SONAR_HOST_URL="http://localhost:9000"
sonar-scanner --version
git --version
curl -fsS "$SONAR_HOST_URL/api/system/status" | tee evidence-system-status.json
sonar-users retains
global Execute Analysis, a newly authenticated Alpha user can still
analyze Beta despite having no Beta project grant. Record this
before the corrective step.
3. Create two synthetic source fixtures
mkdir -p sq-ch21-rbac/{alpha,beta}
for team in alpha beta; do
cd "sq-ch21-rbac/$team"
git init
git config user.email "learner@example.invalid"
git config user.name "SQ Chapter 21"
cat > app.py <<'PY'
def hello(name: str) -> str:
return f"hello {name}"
PY
cat > sonar-project.properties <<EOF
sonar.projectKey=sq-ch21-${team}-app
sonar.projectName=SQ Chapter 21 ${team^} App
sonar.sources=.
sonar.exclusions=.git/**,.scannerwork/**
sonar.sourceEncoding=UTF-8
EOF
git add .
git commit -m "chapter21 ${team} baseline"
git rev-parse HEAD > "../${team}-revision.txt"
cd ../..
done
These revisions remain fixed through the permission experiment. Authorization results must not be confounded with source changes.
4. Create disposable users and groups
Using a local administrator account, create users
sq21-alpha and sq21-beta under
Administration → Security → Users. Use temporary
local-only passwords that are not written into the repository or
evidence packet. Then create groups:
-
sq-ch21-alpha-devscontaining onlysq21-alpha. -
sq-ch21-beta-devscontaining onlysq21-beta.
Capture membership evidence. Do not add either user to
sonar-administrators.
5. Preserve, then narrow the default global Execute Analysis grant
In Administration → Security → Global Permissions,
confirm whether sonar-users has Execute Analysis. If it
does, record the original state and then remove that one global
grant for the duration of this disposable lab.
Immediately record the new state and the planned rollback: restore
Execute Analysis to sonar-users if that was the
original state.
6. Create and apply project permission templates
Create two templates before creating the projects:
Template: SQ21 Alpha
Pattern: ^sq-ch21-alpha-.*
Group sq-ch21-alpha-devs:
Browse Project
See Source Code
Execute Analysis on project
Template: SQ21 Beta
Pattern: ^sq-ch21-beta-.*
Group sq-ch21-beta-devs:
Browse Project
See Source Code
Execute Analysis on project
Create sq-ch21-alpha-app and
sq-ch21-beta-app as private projects.
Verify that the appropriate template was applied. If a project was
created before the template, use the documented project
administration flow to apply the intended template and record that
action.
7. Create two credential types per team
Log in as each disposable user rather than generating routine credentials under the administrator account.
- Create a project-analysis token for the user’s own project. Choose a short explicit expiration.
- Create a separate user token for read-only API verification, also with a short expiration.
- Copy each value once into an environment variable; never store it in Git, screenshots, or the evidence packet.
# Example names only. Enter actual temporary values interactively.
read -rsp "Alpha project-analysis token: " SQ_ALPHA_ANALYSIS_TOKEN; echo
read -rsp "Alpha limited user token: " SQ_ALPHA_USER_TOKEN; echo
export SQ_ALPHA_ANALYSIS_TOKEN SQ_ALPHA_USER_TOKEN
The user token is not intrinsically “read only”; its practical
authority is bounded by the sq21-alpha user’s
permissions. This is why service-user design matters.
8. Prove an allowed Alpha analysis
cd sq-ch21-rbac/alpha
export SONAR_TOKEN="$SQ_ALPHA_ANALYSIS_TOKEN"
mkdir -p evidence/alpha-allowed
sonar-scanner -X 2>&1 | tee evidence/alpha-allowed/scanner.log
cp .scannerwork/report-task.txt evidence/alpha-allowed/report-task.txt
ALPHA_TASK="$(sed -n 's/^ceTaskId=//p' .scannerwork/report-task.txt)"
printf '%s\n' "$ALPHA_TASK" > evidence/alpha-allowed/ceTaskId.txt
curl -fsS -H "Authorization: Bearer $SQ_ALPHA_USER_TOKEN" \
"$SONAR_HOST_URL/api/ce/task?id=$ALPHA_TASK" \
> evidence/alpha-allowed/ce-task.json
Wait for terminal Compute Engine state. Preserve scanner success,
ceTaskId, CE success, project visibility, and gate
state separately.
9. Prove cross-team denial without changing the project key
Now use Alpha’s project-analysis token against the Beta project configuration. Do not solve the failure by creating another project key.
cd ../beta
export SONAR_TOKEN="$SQ_ALPHA_ANALYSIS_TOKEN"
set +e
sonar-scanner -X 2>&1 | tee evidence-alpha-denied-on-beta.log
STATUS=${PIPESTATUS[0]}
set -e
printf 'scanner_exit=%s\n' "$STATUS" | tee evidence-alpha-denied-exit.txt
test "$STATUS" -ne 0
The exact server/scanner wording may vary, but the invariant is that an authenticated Alpha project-analysis credential must not be allowed to push an analysis to Beta.
10. Read-only API allow/deny evidence
# Alpha can read its own private project.
curl -sS -o evidence-alpha-own.json -w '%{http_code}\n' \
-H "Authorization: Bearer $SQ_ALPHA_USER_TOKEN" \
"$SONAR_HOST_URL/api/measures/component?component=sq-ch21-alpha-app&metricKeys=ncloc" \
| tee evidence-alpha-own-status.txt
# Alpha tries to read Beta. Preserve the real status/body.
curl -sS -o evidence-alpha-beta.json -w '%{http_code}\n' \
-H "Authorization: Bearer $SQ_ALPHA_USER_TOKEN" \
"$SONAR_HOST_URL/api/measures/component?component=sq-ch21-beta-app&metricKeys=ncloc" \
| tee evidence-alpha-beta-status.txt
Depending on endpoint/privacy behavior, a server may expose a permission denial or deliberately hide a private resource. Record the actual response. Do not infer “project absent” until authorization has been checked.
11. Revoke and prove failure
Revoke Alpha’s project-analysis token under My Account → Security. Then rerun the smallest equivalent Alpha scan at the same revision:
cd ../alpha
export SONAR_TOKEN="$SQ_ALPHA_ANALYSIS_TOKEN" # value is now revoked server-side
set +e
sonar-scanner 2>&1 | tee evidence-revoked-analysis.log
REVOKED_SCAN=${PIPESTATUS[0]}
set -e
printf 'revoked_scan_exit=%s\n' "$REVOKED_SCAN" | tee evidence-revoked-analysis-exit.txt
test "$REVOKED_SCAN" -ne 0
Then revoke Alpha’s user token and retry the read-only API request. Preserve the actual invalid/revoked-authentication response. This proves credential lifecycle cleanup rather than merely documenting that somebody clicked “Revoke.”
12. Cleanup and rollback
- Revoke all Chapter 21 tokens.
-
Restore
sonar-usersglobal Execute Analysis only if it was present before the lab. - Delete only the two disposable projects, users, groups, and templates created for this lab after evidence export.
- Do not delete shared users/groups, change global profiles/gates, touch database/search state, or purge unrelated Docker resources.
-
Unset shell variables:
unset SQ_ALPHA_ANALYSIS_TOKEN SQ_ALPHA_USER_TOKEN SONAR_TOKEN.
13. Challenge: choose the correct layer
Beta’s scanner token suddenly stops working after a group cleanup even though the token has not expired. What should you inspect?
Check the token owner’s effective Execute Analysis permission first. Current project/global analysis tokens depend on the owner retaining the corresponding Execute Analysis permission; a still-unexpired token can become unusable when its owner loses authority.
Knowledge check
Why did the lab remove global Execute Analysis from
sonar-users temporarily?
To make project-level isolation observable. Otherwise both users inherit global analysis rights and the cross-team denial test is invalid.
Why use a separate project-analysis token and user token?
The scanner needs only project analysis authority, while Web API calls use a user token that inherits the limited user’s permissions. Separating them bounds compromise and clarifies consumers.
Does revoking a token require deleting the project?
No. Token state and project state are independent. Revoke the credential and prove the dependent action fails.
Alpha sees a denial for Beta. Should you retry with the administrator token?
No. First diagnose the intended RBAC policy. Using admin would mask the authorization design being tested.
Why record the original global permission before changing it?
Rollback must restore the exact prior state rather than assume a default.
Official references and version notes
-
Managing permissions — Community Build
— current global/project permissions, default
sonar-usersExecute Analysis grant, visibility, and permission templates. - Managing groups — additive direct/group permission model and built-in groups.
- Managing your tokens — user/project/global analysis token types, expiration, revocation, and owner-permission dependency.
- Administering tokens — administrator generation/revocation responsibilities.
- User accounts — built-in/delegated authentication and forced-authentication guidance.
- Web API — bearer authentication, token-expiration response header, form-data guidance, and Web API V2 transition.
- Current SonarQube downloads — Community Build 26.9.0.129388 baseline.
- SonarScanner CLI 8.1.0.6389 — scanner baseline used by the local analysis proofs.
Rechecked 2026-09-08. Mandatory exercises target
Community Build 26.9.0.129388 and
SonarScanner CLI 8.1.0.6389. Current Community
Build documentation says permissions are additive across direct
grants and group membership; sonar-users receives
global Execute Analysis by default on a fresh installation, so the
disposable RBAC lab temporarily removes that grant only after
preserving it and restores it during cleanup. Project-analysis
tokens are encouraged for one-project scanning. User tokens
inherit all permissions of their owner and are the recommended
bearer credential for Web API operations; project/global analysis
token validity depends on the owner retaining the corresponding
Execute Analysis permission. Token expiration can be selected by
users; enforcing an instance-wide maximum token lifetime for newly
generated tokens is Enterprise edition and above. New projects are
public by default in current documentation; the lab uses private
projects to make Browse/See Source Code boundaries observable. If
an external authentication/provisioning method synchronizes
users/groups/permissions, manual changes may be unavailable and
the external source of truth owns the change. Web API V2 is
gradually replacing older endpoints, so write automation must be
checked against the current in-instance API documentation.
SonarQube product names, editions, release trains, scanner runtimes, APIs, authentication options, and platform prerequisites can change independently. Re-check the linked SonarSource primary documentation for the exact target release before applying version-sensitive commands or operational guidance outside the disposable course environment.
report-task.txt/ceTaskId, CE result,
gate result, and revocation test separately. Never place token values
in the evidence packet.
Keep the academy open
Support free, practical DevOps education.
Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this
address.