-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FUZ-22 - API Token improvements - Tool Segmentation #1061
base: master
Are you sure you want to change the base?
FUZ-22 - API Token improvements - Tool Segmentation #1061
Conversation
No Taskcluster jobs started for this pull requestThe |
server/covmanager/views.py
Outdated
def create(self, request, *args, **kwargs): | ||
"""Check user has access to tools before creation""" | ||
tools_str = request.data.get("tools") | ||
if tools_str is None: | ||
return Response( | ||
{"message": "Missing required 'tools' parameter"}, | ||
status=status.HTTP_400_BAD_REQUEST, | ||
) | ||
|
||
requested_tools = set(tools_str.split(",")) | ||
|
||
user = User.get_or_create_restricted(request.user)[0] | ||
if user.restricted: | ||
allowed_tools = set(user.defaultToolsFilter.values_list("name", flat=True)) | ||
if not allowed_tools: | ||
raise PermissionDenied({"message": "No tools assigned to user"}) | ||
|
||
unauthorized_tools = requested_tools - allowed_tools | ||
if unauthorized_tools: | ||
raise PermissionDenied( | ||
{ | ||
"message": f"You don't have permission to use the following tools: {', '.join(unauthorized_tools)}" | ||
} | ||
) | ||
|
||
return super().create(request, *args, **kwargs) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This update looks very similar to the one in crashmanager/view.py. We also noticed a few other functions in both views that share similarities. However, to avoid circular imports, we've kept them separate.
Would you prefer abstracting these similar logic pieces elsewhere in the codebase to reduce duplication?
This PR was created by GitStart to address the requirements from this ticket: FUZ-22.
This PR adds tool-specific segmentation to users to enhance security in FuzzManager. Currently, API tokens (and thus users given the 1:1 mapping) have unrestricted access across all tools, creating potential security risks if compromised.
The changes:
Restrict users to specific tools
Add Django commands add_tool_to_user and remove_tool_from_user for user-tool management
Implement user restrictions based on tool access
Prevent unauthorized tool access
This segmentation limits the impact of potential token leaks and provides better access control for crash/coverage reporting.
Demo
https://www.loom.com/share/c26267c717214c44be30ebe21ea7e60c
Test Plan
1. Setup Test Environment
Run the following in python manage.py shell to prepare for testing:
2. Test Scenarios
A. Restricted User Tests
Successfully create a crash with allowed tool:
Attempt to create a crash with unauthorized tool (should fail):
B. Unrestricted User Tests
Create a collection with multiple tools (should succeed):
3. Tool Assignment Management
Use these management commands to add or remove tools from users:
Add tool to user:
Remove tool from user:
Additional Notes:
The test suite has been updated to correctly reflect the new security model:
Test fixtures now properly assign tools to restricted users before testing
Tests verify that restricted users can only report crashes for tools they have permission to use
Unauthorized tool access is properly prevented and tested