-
Notifications
You must be signed in to change notification settings - Fork 15
Add bearer token authentication support to DEEPaaS API #198
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
base: v3-fastapi
Are you sure you want to change the base?
Add bearer token authentication support to DEEPaaS API #198
Conversation
This requires that we change all model args/responses from Marshmallow to Pydantic. Most of the code is in this change, we can split it later on two different changes (marshmallow + pydantic and FastAPI for predict).
After checking with people using the package for a while, the training methods were not used at all, therefore we are now removing the training endpoints. This also allows us to have a much more simple codebase.
…lementation Co-authored-by: alvarolopez <[email protected]>
Co-authored-by: alvarolopez <[email protected]>
Co-authored-by: alvarolopez <[email protected]>
alvarolopez
left a comment
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.
@copilot please address the changes, and take into account that we use rST for docs.
deepaas/auth.py
Outdated
| ) -> str: | ||
| """Verify the bearer token against the configured token. | ||
|
|
||
| Args: |
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.
@copilot please use sphinx syntax here
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.
Updated the docstring to use proper Sphinx syntax with :param:, :type:, :returns:, :rtype:, and :raises: format in commit 288b790.
… to reStructuredText Co-authored-by: alvarolopez <[email protected]>
Addressed both changes:
The documentation is now properly integrated into the Sphinx documentation structure and follows project conventions. Commit 288b790. |
|
f0df6de to
471eb1a
Compare



This PR implements bearer token authentication for DEEPaaS API endpoints to address cases where fine-grained authentication is not needed but API access control is required.
Overview
The implementation adds optional bearer token authentication that can be enabled via configuration. When enabled, protected endpoints require a valid
Authorization: Bearer <token>header. The feature is backward compatible - authentication is disabled by default and existing deployments continue to work unchanged.Key Features
🔐 Security Implementation
HTTPBearersecurity scheme following RFC 6750 standards/v2/models/) and predict endpoints (/v2/models/{model}/predict)/and version/v2/) remain accessible without authenticationWWW-Authenticate: Bearerheaders for unauthorized requests⚙️ Configuration
The bearer token is configured via the new
--auth-bearer-tokenoption:🔌 API Usage
When authentication is enabled, API clients must include the bearer token:
Implementation Details
New Files
deepaas/auth.py- Authentication module with token validation logic (using Sphinx docstring format)deepaas/tests/test_auth.py- Unit tests for authentication functionalitydeepaas/tests/test_e2e_auth.py- End-to-end API integration testsdoc/source/user/authentication.rst- Documentation with usage examples and security considerations (reStructuredText format)Modified Files
deepaas/config.py- Addedauth_bearer_tokenconfiguration option (marked as secret)deepaas/api/v2/models.py- Added authentication dependency to model endpointsdeepaas/api/v2/predict.py- Added authentication dependency to predict endpointsdoc/source/user/index.rst- Added authentication documentation to user documentation indexBehavioral Changes
auth_bearer_tokenis not set (default): All endpoints work as before - no authentication requiredauth_bearer_tokenis set: Model and predict endpoints require valid bearer token, other endpoints remain publicTesting
Added comprehensive test coverage with 18 new tests:
Security Considerations
This implementation provides a simple but effective authentication mechanism for deployments that need basic API access control without the complexity of fine-grained authorization systems.
Fixes #151
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.