-
Notifications
You must be signed in to change notification settings - Fork 7
Implement Hashing for API Key Storage to Enhance Security #142 #158
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
Implement Hashing for API Key Storage to Enhance Security #142 #158
Conversation
- Added encryption for API keys during storage using Fernet. - Implemented decryption for API keys when retrieved. - Updated API key creation to store encrypted keys. - Modified tests to verify the integrity of decrypted keys. - Introduced utility functions for key encryption and decryption in the security module.
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
backend/app/alembic/versions/77dc462dc6b0_seed_organization_table.py
Outdated
Show resolved
Hide resolved
backend/app/alembic/versions/77dc462dc6b0_seed_organization_table.py
Outdated
Show resolved
Hide resolved
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
2 similar comments
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
4e71d89 to
41bcec3
Compare
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
…ng up whitespace for improved readability.
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
…ashed keys, ensuring keys are stored and retrieved in their original format. Update tests to verify the integrity of the raw keys.
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
…ion ID, user ID, and raw key format to ensure comprehensive validation of retrieved keys.
Description
This PR implements a secure and efficient approach for API key management, focusing on maintaining the original key format while ensuring security. The implementation uses a streamlined encryption process:
API keys are generated with a consistent format (prefixed with "ApiKey ")
The original key is encrypted using Fernet encryption before storage
The encryption key is derived from the application's secret key using PBKDF2HMAC
When retrieved, keys are automatically decrypted and returned in their original format
Changes Made
Benefits
fastapi run --reload app/main.pyordocker compose upin the repository root and test.This pull request aims to enhance the security of API key storage in the
priyanshu6238/ai-platformrepository by implementing hashing and encryption mechanisms. The changes are made across several files:backend/app/alembic/versions/77dc462dc6b0_seed_organization_table.py: The database seeding script is updated to hash and encrypt API keys before storage. This involves importing security utility functions and modifying the
create_api_keyfunction to incorporate these security measures. The update also addresses potential issues with the hashing strategy and the complexity of the hash-then-encrypt approach.backend/app/core/security.py: New functionality is introduced for encrypting and decrypting API keys using Fernet symmetric encryption. An encryption key is derived from the application's
SECRET_KEYusing PBKDF2HMAC, and utility functions for encryption and decryption are provided, including basic error handling.backend/app/crud/api_key.py: API key security is enhanced by storing encrypted hashes instead of raw keys. The key creation process is updated to store an encrypted hash, and retrieval functions are modified to handle this new format. A verification function iterates through keys, using
get_password_hashand custom encryption/decryption functions. While this improves security, it introduces performance concerns in key verification, potential issues with encrypting hashes, and lacks error handling for decryption.Overall, this pull request significantly improves the security posture of API key management by ensuring that raw keys are not stored and by implementing robust encryption and hashing techniques.