Skip to content

Commit b74cae8

Browse files
committed
Add group-to-scope mappings in scopes.yml for consistent authorization between M2M and session cookie auth mode; Updated auth server to use configuration-driven scope mapping instead of hardcoded logic; Updated library package;
1 parent 4674482 commit b74cae8

File tree

3 files changed

+51
-27
lines changed

3 files changed

+51
-27
lines changed

auth_server/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ dependencies = [
2020
"boto3>=1.28.0",
2121
"pyjwt>=2.6.0",
2222
"cryptography>=40.0.0",
23-
"pyyaml>=6.0.0"
23+
"pyyaml>=6.0.0",
24+
"itsdangerous>=2.0.0"
2425
]
2526

2627
[project.optional-dependencies]

auth_server/scopes.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
# MCP Server Access Scopes Configuration
22
# This file defines access permissions for MCP servers and their tools
33

4+
# Group to scope mappings for user authentication
5+
# Maps Cognito groups to MCP scopes for consistent authorization
6+
group_mappings:
7+
# Administrative access
8+
mcp-admin:
9+
- mcp-servers-unrestricted/read
10+
- mcp-servers-unrestricted/execute
11+
12+
# Standard user access
13+
mcp-user:
14+
- mcp-servers-restricted/read
15+
16+
# Server-specific access groups
17+
mcp-server-currenttime:
18+
- mcp-servers-restricted/execute
19+
mcp-server-fininfo:
20+
- mcp-servers-restricted/execute
21+
mcp-server-mcpgw:
22+
- mcp-servers-restricted/execute
23+
24+
# Fine-grained tool access (optional)
25+
mcp-server-currenttime-tool-current_time_by_timezone:
26+
- mcp-servers-restricted/execute
27+
mcp-server-fininfo-tool-get_stock_price:
28+
- mcp-servers-restricted/execute
29+
mcp-server-fininfo-tool-get_company_info:
30+
- mcp-servers-restricted/execute
31+
432
mcp-servers-unrestricted/read:
533
- server: auth_server
634
methods:

auth_server/server.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def load_scopes_config():
4646

4747
def map_cognito_groups_to_scopes(groups: List[str]) -> List[str]:
4848
"""
49-
Map Cognito groups to MCP scopes using the same format as M2M resource server scopes.
49+
Map Cognito groups to MCP scopes using scopes.yml configuration.
50+
51+
Uses the same scope format as M2M tokens for consistency.
5052
5153
Args:
5254
groups: List of Cognito group names
@@ -56,34 +58,27 @@ def map_cognito_groups_to_scopes(groups: List[str]) -> List[str]:
5658
"""
5759
scopes = []
5860

61+
# Use group mappings from scopes.yml if available
62+
group_mappings = SCOPES_CONFIG.get('group_mappings', {})
63+
5964
for group in groups:
60-
if group == 'mcp-admin':
61-
# Admin gets unrestricted read and execute access
62-
scopes.append('mcp-servers-unrestricted/read')
63-
scopes.append('mcp-servers-unrestricted/execute')
64-
elif group == 'mcp-user':
65-
# Regular users get restricted read access by default
66-
scopes.append('mcp-servers-restricted/read')
67-
elif group.startswith('mcp-server-'):
68-
# Server-specific groups grant access based on server permissions
69-
# For now, grant restricted execute access for specific servers
70-
# This allows access to the servers defined in the restricted scope
71-
scopes.append('mcp-servers-restricted/execute')
72-
73-
# Note: The actual server access control is handled by the
74-
# validate_server_tool_access function which checks the scopes.yml
75-
# configuration. The group names are preserved in the 'groups' field
76-
# for potential future fine-grained access control.
65+
if group in group_mappings:
66+
# Use configured mapping
67+
scopes.extend(group_mappings[group])
68+
else:
69+
# Legacy fallback for backward compatibility
70+
logger.debug(f"Group '{group}' not in group_mappings, using legacy mapping")
71+
72+
if group == 'mcp-admin':
73+
scopes.extend(['mcp-servers-unrestricted/read',
74+
'mcp-servers-unrestricted/execute'])
75+
elif group == 'mcp-user':
76+
scopes.append('mcp-servers-restricted/read')
77+
elif group.startswith('mcp-server-'):
78+
scopes.append('mcp-servers-restricted/execute')
7779

7880
# Remove duplicates while preserving order
79-
seen = set()
80-
unique_scopes = []
81-
for scope in scopes:
82-
if scope not in seen:
83-
seen.add(scope)
84-
unique_scopes.append(scope)
85-
86-
return unique_scopes
81+
return list(dict.fromkeys(scopes))
8782

8883
def validate_session_cookie(cookie_value: str) -> Dict[str, any]:
8984
"""

0 commit comments

Comments
 (0)