|
| 1 | +# Permission Filtering System |
| 2 | + |
| 3 | +The SonarQube MCP server includes a comprehensive permission filtering system that ensures users only see data they're authorized to access based on their groups and roles from the OAuth token. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The permission system provides: |
| 8 | + |
| 9 | +- **Group-based access control**: Map OAuth token groups/roles to permissions |
| 10 | +- **Project filtering**: Control access to projects using regex patterns |
| 11 | +- **Tool authorization**: Allow/deny access to specific MCP tools |
| 12 | +- **Issue filtering**: Filter issues by severity and status |
| 13 | +- **Sensitive data redaction**: Hide author/assignee information when needed |
| 14 | +- **Write operation control**: Separate read and write permissions |
| 15 | +- **Performance optimization**: Built-in caching for permission checks |
| 16 | + |
| 17 | +## Configuration |
| 18 | + |
| 19 | +### Environment Variable |
| 20 | + |
| 21 | +Set the path to your permission configuration file: |
| 22 | + |
| 23 | +```bash |
| 24 | +export MCP_PERMISSION_CONFIG_PATH=/path/to/permissions.json |
| 25 | +``` |
| 26 | + |
| 27 | +### Configuration File Format |
| 28 | + |
| 29 | +The permission configuration is a JSON file with the following structure: |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "rules": [ |
| 34 | + { |
| 35 | + "groups": ["admin", "sonarqube-admin"], |
| 36 | + "allowedProjects": [".*"], |
| 37 | + "allowedTools": [ |
| 38 | + "projects", "metrics", "issues", "markIssueFalsePositive", |
| 39 | + "markIssueWontFix", "markIssuesFalsePositive", "markIssuesWontFix", |
| 40 | + "addCommentToIssue", "assignIssue", "confirmIssue", "unconfirmIssue", |
| 41 | + "resolveIssue", "reopenIssue", "system_health", "system_status", |
| 42 | + "system_ping", "measures_component", "measures_components", |
| 43 | + "measures_history", "quality_gates", "quality_gate", |
| 44 | + "quality_gate_status", "source_code", "scm_blame", |
| 45 | + "hotspots", "hotspot", "update_hotspot_status", "components" |
| 46 | + ], |
| 47 | + "readonly": false, |
| 48 | + "priority": 100 |
| 49 | + }, |
| 50 | + { |
| 51 | + "groups": ["developer", "dev"], |
| 52 | + "allowedProjects": ["^(dev-|feature-|test-).*"], |
| 53 | + "allowedTools": [ |
| 54 | + "projects", "metrics", "issues", "markIssueFalsePositive", |
| 55 | + "markIssueWontFix", "addCommentToIssue", "assignIssue", |
| 56 | + "confirmIssue", "unconfirmIssue", "measures_component", |
| 57 | + "measures_components", "measures_history", "quality_gate_status", |
| 58 | + "source_code", "scm_blame", "components" |
| 59 | + ], |
| 60 | + "deniedTools": ["system_health", "system_status"], |
| 61 | + "readonly": false, |
| 62 | + "maxSeverity": "CRITICAL", |
| 63 | + "priority": 50 |
| 64 | + }, |
| 65 | + { |
| 66 | + "groups": ["qa", "quality-assurance"], |
| 67 | + "allowedProjects": [".*"], |
| 68 | + "allowedTools": [ |
| 69 | + "projects", "metrics", "issues", "measures_component", |
| 70 | + "measures_components", "measures_history", "quality_gates", |
| 71 | + "quality_gate", "quality_gate_status", "source_code", |
| 72 | + "hotspots", "hotspot", "components" |
| 73 | + ], |
| 74 | + "readonly": true, |
| 75 | + "priority": 40 |
| 76 | + }, |
| 77 | + { |
| 78 | + "groups": ["guest", "viewer"], |
| 79 | + "allowedProjects": ["^public-.*"], |
| 80 | + "allowedTools": [ |
| 81 | + "projects", "metrics", "issues", "quality_gate_status" |
| 82 | + ], |
| 83 | + "readonly": true, |
| 84 | + "maxSeverity": "MAJOR", |
| 85 | + "hideSensitiveData": true, |
| 86 | + "priority": 10 |
| 87 | + } |
| 88 | + ], |
| 89 | + "defaultRule": { |
| 90 | + "allowedProjects": [], |
| 91 | + "allowedTools": [], |
| 92 | + "readonly": true |
| 93 | + }, |
| 94 | + "enableCaching": true, |
| 95 | + "cacheTtl": 300, |
| 96 | + "enableAudit": false |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +## Permission Rule Properties |
| 101 | + |
| 102 | +### Required Properties |
| 103 | + |
| 104 | +- **`allowedProjects`** (string[]): Array of regex patterns for allowed projects |
| 105 | + - Use `[".*"]` to allow all projects |
| 106 | + - Use `["^prefix-.*"]` to allow projects starting with "prefix-" |
| 107 | + - Empty array `[]` means no projects allowed |
| 108 | + |
| 109 | +- **`allowedTools`** (string[]): Array of allowed MCP tool names |
| 110 | + - See "Available Tools" section for complete list |
| 111 | + - Empty array means no tools allowed |
| 112 | + |
| 113 | +- **`readonly`** (boolean): Whether the user has read-only access |
| 114 | + - `true`: Can only use read tools |
| 115 | + - `false`: Can use both read and write tools |
| 116 | + |
| 117 | +### Optional Properties |
| 118 | + |
| 119 | +- **`groups`** (string[]): Groups this rule applies to |
| 120 | + - If omitted, rule applies to all groups |
| 121 | + - Matches against groups/roles from OAuth token |
| 122 | + |
| 123 | +- **`deniedTools`** (string[]): Tools explicitly denied |
| 124 | + - Takes precedence over `allowedTools` |
| 125 | + - Useful for exceptions |
| 126 | + |
| 127 | +- **`maxSeverity`** (string): Maximum issue severity visible |
| 128 | + - Options: `INFO`, `MINOR`, `MAJOR`, `CRITICAL`, `BLOCKER` |
| 129 | + - Users won't see issues above this severity |
| 130 | + |
| 131 | +- **`allowedStatuses`** (string[]): Allowed issue statuses |
| 132 | + - Options: `OPEN`, `CONFIRMED`, `REOPENED`, `RESOLVED`, `CLOSED` |
| 133 | + - If specified, only these statuses are visible |
| 134 | + |
| 135 | +- **`hideSensitiveData`** (boolean): Redact sensitive information |
| 136 | + - Hides author, assignee, comments, and changelog |
| 137 | + |
| 138 | +- **`priority`** (number): Rule priority (higher = higher priority) |
| 139 | + - Default: 0 |
| 140 | + - When user has multiple groups, highest priority rule applies |
| 141 | + |
| 142 | +## Available Tools |
| 143 | + |
| 144 | +### Read Operations |
| 145 | +- `projects` - List all projects |
| 146 | +- `metrics` - Get available metrics |
| 147 | +- `issues` - Search and filter issues |
| 148 | +- `system_health` - Get system health status |
| 149 | +- `system_status` - Get system status |
| 150 | +- `system_ping` - Ping the system |
| 151 | +- `measures_component` - Get measures for a component |
| 152 | +- `measures_components` - Get measures for multiple components |
| 153 | +- `measures_history` - Get measures history |
| 154 | +- `quality_gates` - List quality gates |
| 155 | +- `quality_gate` - Get quality gate details |
| 156 | +- `quality_gate_status` - Get quality gate status |
| 157 | +- `source_code` - View source code |
| 158 | +- `scm_blame` - Get SCM blame information |
| 159 | +- `hotspots` - Search security hotspots |
| 160 | +- `hotspot` - Get hotspot details |
| 161 | +- `components` - Search and navigate components |
| 162 | + |
| 163 | +### Write Operations |
| 164 | +- `markIssueFalsePositive` - Mark issue as false positive |
| 165 | +- `markIssueWontFix` - Mark issue as won't fix |
| 166 | +- `markIssuesFalsePositive` - Bulk mark issues as false positive |
| 167 | +- `markIssuesWontFix` - Bulk mark issues as won't fix |
| 168 | +- `addCommentToIssue` - Add comment to issue |
| 169 | +- `assignIssue` - Assign/unassign issue |
| 170 | +- `confirmIssue` - Confirm issue |
| 171 | +- `unconfirmIssue` - Unconfirm issue |
| 172 | +- `resolveIssue` - Resolve issue |
| 173 | +- `reopenIssue` - Reopen issue |
| 174 | +- `update_hotspot_status` - Update security hotspot status |
| 175 | + |
| 176 | +## Group Extraction |
| 177 | + |
| 178 | +The system extracts groups from OAuth tokens using these claim names: |
| 179 | +- `groups` (preferred) |
| 180 | +- `group` |
| 181 | +- `roles` |
| 182 | +- `role` |
| 183 | +- `authorities` |
| 184 | + |
| 185 | +Groups can be: |
| 186 | +- Array: `["admin", "developer"]` |
| 187 | +- Comma-separated string: `"admin,developer"` |
| 188 | +- Space-separated string: `"admin developer"` |
| 189 | + |
| 190 | +## Security Considerations |
| 191 | + |
| 192 | +### Fail-Closed Design |
| 193 | +- If no rules match, access is denied by default |
| 194 | +- Explicit `defaultRule` required to change this behavior |
| 195 | +- No information leakage in error messages |
| 196 | + |
| 197 | +### Rule Evaluation |
| 198 | +1. Rules are sorted by priority (descending) |
| 199 | +2. First matching rule is applied |
| 200 | +3. `deniedTools` takes precedence over `allowedTools` |
| 201 | +4. Write operations require `readonly: false` |
| 202 | + |
| 203 | +### Performance |
| 204 | +- Permission checks are cached (configurable TTL) |
| 205 | +- Regex patterns are compiled once and reused |
| 206 | +- Audit logging available for debugging |
| 207 | + |
| 208 | +## Examples |
| 209 | + |
| 210 | +### Development Team Configuration |
| 211 | + |
| 212 | +```json |
| 213 | +{ |
| 214 | + "rules": [ |
| 215 | + { |
| 216 | + "groups": ["frontend-team"], |
| 217 | + "allowedProjects": ["^frontend-.*", "^ui-.*"], |
| 218 | + "allowedTools": ["issues", "measures_component", "source_code"], |
| 219 | + "readonly": false, |
| 220 | + "maxSeverity": "CRITICAL" |
| 221 | + }, |
| 222 | + { |
| 223 | + "groups": ["backend-team"], |
| 224 | + "allowedProjects": ["^api-.*", "^service-.*"], |
| 225 | + "allowedTools": ["issues", "measures_component", "source_code", "hotspots"], |
| 226 | + "readonly": false |
| 227 | + } |
| 228 | + ], |
| 229 | + "defaultRule": { |
| 230 | + "allowedProjects": [], |
| 231 | + "allowedTools": [], |
| 232 | + "readonly": true |
| 233 | + } |
| 234 | +} |
| 235 | +``` |
| 236 | + |
| 237 | +### Multi-Environment Configuration |
| 238 | + |
| 239 | +```json |
| 240 | +{ |
| 241 | + "rules": [ |
| 242 | + { |
| 243 | + "groups": ["prod-access"], |
| 244 | + "allowedProjects": ["^prod-.*"], |
| 245 | + "allowedTools": ["issues", "quality_gate_status", "measures_component"], |
| 246 | + "readonly": true, |
| 247 | + "hideSensitiveData": true |
| 248 | + }, |
| 249 | + { |
| 250 | + "groups": ["staging-access"], |
| 251 | + "allowedProjects": ["^staging-.*"], |
| 252 | + "allowedTools": ["issues", "quality_gate_status", "measures_component", "source_code"], |
| 253 | + "readonly": false, |
| 254 | + "maxSeverity": "CRITICAL" |
| 255 | + } |
| 256 | + ] |
| 257 | +} |
| 258 | +``` |
| 259 | + |
| 260 | +## Testing Your Configuration |
| 261 | + |
| 262 | +1. Create a test configuration file |
| 263 | +2. Set the environment variable |
| 264 | +3. Start the server with HTTP transport |
| 265 | +4. Make authenticated requests with different group claims |
| 266 | +5. Verify filtering behavior |
| 267 | + |
| 268 | +## Troubleshooting |
| 269 | + |
| 270 | +### Enable Audit Logging |
| 271 | + |
| 272 | +Set `"enableAudit": true` in your configuration to log all permission checks: |
| 273 | + |
| 274 | +```json |
| 275 | +{ |
| 276 | + "enableAudit": true, |
| 277 | + "rules": [...] |
| 278 | +} |
| 279 | +``` |
| 280 | + |
| 281 | +### Common Issues |
| 282 | + |
| 283 | +1. **No projects visible**: Check `allowedProjects` regex patterns |
| 284 | +2. **Tools access denied**: Verify tool names in `allowedTools` |
| 285 | +3. **Write operations failing**: Ensure `readonly: false` |
| 286 | +4. **Wrong rule applied**: Check rule priorities and group matching |
| 287 | + |
| 288 | +## Integration with OAuth Providers |
| 289 | + |
| 290 | +The permission system integrates with any OAuth 2.0 provider that includes group/role information in tokens: |
| 291 | + |
| 292 | +- **Keycloak**: Configure client mappers to include groups |
| 293 | +- **Auth0**: Add groups to custom claims |
| 294 | +- **Okta**: Include groups in token claims |
| 295 | +- **Azure AD**: Map AD groups to token claims |
| 296 | + |
| 297 | +Ensure your OAuth provider is configured to include group information in the access token or ID token used for authentication. |
0 commit comments