Skip to main content

sonar_diagnose_permissions

Diagnose token permissions and connectivity issues.

Description

Comprehensive diagnostic tool for troubleshooting SonarQube connection and permission issues. Especially helpful for resolving 403 Forbidden errors and understanding token capabilities.

Parameters

ParameterTypeRequiredDefaultDescription
verbosebooleanNotrueShow detailed diagnostic info

Usage

Full Diagnostics

Help me troubleshoot my SonarQube connection

Tool call:

{}

Quick Check

Quick permission check

Tool call:

{
"verbose": false
}

Response Format

Verbose Output

PERMISSION DIAGNOSTICS
━━━━━━━━━━━━━━━━━━━━━━

🔧 CONFIGURATION:

Config File: /Users/dev/myproject/bobthefixer.env
Server URL: http://localhost:9000
Project Key: myproject-a1b2c3d4
Token: squ_****...****

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🌐 CONNECTIVITY:

✓ Server reachable
✓ Port 9000 open
✓ HTTP response: 200 OK
✓ SonarQube version: 10.3.0
✓ API accessible

Response time: 45ms

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🔑 TOKEN VALIDATION:

✓ Token format valid
✓ Token not expired
✓ Token authenticates successfully

Token Type: Project Analysis Token
Created: 2024-01-10 09:15:00
Last Used: 2024-01-15 14:30:00

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📋 PERMISSIONS:

Project: myproject-a1b2c3d4

┌────────────────────────┬────────┬───────────┐
│ Permission │ Status │ Required │
├────────────────────────┼────────┼───────────┤
│ Browse │ ✅ │ Yes │
│ Execute Analysis │ ✅ │ Yes │
│ See Source Code │ ✅ │ No │
│ Administer Issues │ ❌ │ No │
│ Administer Project │ ❌ │ No │
│ Create Projects │ ✅ │ For setup │
└────────────────────────┴────────┴───────────┘

All required permissions: ✅ AVAILABLE

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📊 PROJECT STATUS:

✓ Project exists
✓ Last analysis: 2024-01-15 10:30:00
✓ Quality Gate: PASSED

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✅ DIAGNOSIS: ALL SYSTEMS OPERATIONAL

No issues detected. Your configuration is working correctly.

With Issues Detected

PERMISSION DIAGNOSTICS
━━━━━━━━━━━━━━━━━━━━━━

🔧 CONFIGURATION:

Config File: /Users/dev/myproject/bobthefixer.env
Server URL: http://localhost:9000
Project Key: myproject-a1b2c3d4
Token: squ_****...****

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🌐 CONNECTIVITY:

✓ Server reachable
✓ Port 9000 open
✓ HTTP response: 200 OK

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🔑 TOKEN VALIDATION:

✓ Token format valid
✗ Token authentication FAILED

Error: 403 Forbidden
Message: "Insufficient privileges"

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📋 PERMISSIONS:

⚠️ Cannot verify permissions - authentication failed

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

❌ DIAGNOSIS: AUTHENTICATION FAILURE

ISSUES FOUND:

1. Token authentication failed with 403 error
This usually means:
• Token has been revoked
• Token has expired
• Token was created for a different project

RECOMMENDED ACTIONS:

1. Check token in SonarQube UI:
Account → Security → Tokens

2. Generate a new token:
- Type: Project Analysis Token
- Project: myproject-a1b2c3d4

3. Update configuration:
Run: sonar_config_manager action="reset"
Then: sonar_auto_setup

4. If using Global token:
Ensure "Execute Analysis" permission is granted

Diagnostic Checks

CheckWhat It Tests
Server reachableNetwork connectivity
Port openFirewall/routing
HTTP responseServer running
API accessibleSonarQube functional
Token formatValid token structure
Token authCredentials work
PermissionsRequired access exists
Project existsProject on server

Permission Types

PermissionPurposeRequired
BrowseView project✅ Yes
Execute AnalysisRun scans✅ Yes
See Source CodeView codeOptional
Administer IssuesManage issuesOptional
Administer ProjectProject settingsOptional
Create ProjectsNew projectsFor setup

Examples

Example 1: 403 Error Investigation

Prompt:

I'm getting 403 errors, help me debug

Tool Call:

{
"verbose": true
}

Example 2: Quick Health Check

Prompt:

Is my SonarQube connection working?

Tool Call:

{
"verbose": false
}

Example 3: Pre-scan Verification

Prompt:

Verify everything before I run a scan

Tool Call:

{}

Common Issues

403 Forbidden

Symptoms:

Token authentication FAILED
Error: 403 Forbidden

Solutions:

  1. Regenerate token in SonarQube
  2. Verify token type matches project
  3. Check token hasn't expired

Connection Refused

Symptoms:

Server not reachable
Connection refused on port 9000

Solutions:

  1. Start SonarQube: docker start sonarqube
  2. Check correct URL
  3. Verify firewall settings

Project Not Found

Symptoms:

Project does not exist

Solutions:

  1. Verify project key is correct
  2. Check token has access to project
  3. Run sonar_auto_setup to create

Token Expired

Symptoms:

Token expired or revoked

Solutions:

  1. Generate new token
  2. Update bobthefixer.env
  3. Or run sonar_auto_setup

Best Practices

  1. Run before reporting issues - Provides diagnostic info
  2. Use verbose mode - More detail helps debugging
  3. Check after token changes - Verify new token works
  4. Regular health checks - Catch issues early