Skip to content
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

Add Optional API Key Authentication to FastAPI Services #541

Merged
merged 2 commits into from
Jan 4, 2025

Conversation

ParisNeo
Copy link
Contributor

@ParisNeo ParisNeo commented Jan 4, 2025

This PR implements optional API key authentication across all FastAPI services in LightRAG. The implementation provides flexible security that can be enabled or disabled through configuration.

Key Changes:

  • Added optional API key authentication system across all FastAPI endpoints
  • Authentication can be configured through environment variable LIGHTRAG_API_KEY or command line argument
  • Services run without authentication when no API key is configured
  • Implemented proper security headers and API key validation
  • Added OpenAPI documentation support for API key authentication

Implementation Details:

  • Used FastAPI's built-in security utilities for robust authentication
  • Added X-API-Key header support for API authentication
  • Implemented graceful fallback to no-auth when API key is not configured
  • Maintained CORS middleware compatibility
  • Added proper error handling for authentication failures

Configuration:

  • Set API key through environment variable: LIGHTRAG_API_KEY=your_key
  • Or through command line: --key your_key
  • Leave unset to disable authentication

Testing:

  • Tested with authentication enabled/disabled
  • Verified CORS functionality
  • Confirmed OpenAPI documentation accuracy
  • Tested error handling for invalid API keys

This enhancement improves the security posture of LightRAG while maintaining flexibility for different deployment scenarios.

@LarFii LarFii merged commit fb41458 into HKUDS:main Jan 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants