-
Notifications
You must be signed in to change notification settings - Fork 1
Add AES-256-GCM encryption for environment variables in .env files with Admin UI integration #617
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: main
Are you sure you want to change the base?
Conversation
- Created CLI tool (encryptEnvValue.js) to encrypt passwords and API keys - Added envDecryptor.js for automatic decryption on application startup - Updated config.js to load and decrypt environment variables early - Updated documentation (LDAP auth guide, security.md, config files) - Added encryption examples and best practices to config.env and .env.example - Tested encryption/decryption cycle successfully Co-authored-by: manzke <[email protected]>
- Make encryptEnvValue.js examples more generic (not just LDAP) - Add production check - fail fast if TOKEN_ENCRYPTION_KEY not set - Warn about random key generation causing decryption failures - Provide better error summary when decryption fails - Fix JavaScript syntax error in encryption.md documentation - Add encryption.md comprehensive documentation Co-authored-by: manzke <[email protected]>
- Enhanced security warnings for generated keys in development - Made decryption logging less verbose in production - Extracted regex patterns as constants for maintainability - Reduced credential exposure in test output (use asterisks) - Fixed documentation shell command examples - Clarified limitations about manual encryption requirement - Used generic placeholders in batch script example Co-authored-by: manzke <[email protected]>
manzke
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.
It feels like a lot of duplicate code.
Please review our codebase carefully and make sure we are not repeating ourselves. (Especially the encrypt decrypt part)
We should also check how keys in the admin ui are stored, when a user uses the Ui to configure ldap, ntlm or odic.
We should have a way to generate an encrypted key, so a user can copy and paste it. (User submits plaintext and receives an encrypted key)
- Remove duplicate encryption code from envDecryptor.js - Use TokenStorageService.encryptString/decryptString for consistency - Update encryptEnvValue.js CLI tool to use TokenStorageService - Add /api/admin/auth/encrypt-value endpoint for UI integration - Update documentation to explain admin UI integration - Ensure same encryption across model API keys and env variables Co-authored-by: manzke <[email protected]>
Refactored to eliminate code duplication in commit 560e0db: Changes made:
Admin UI integration: Consistency:
|
Storing LDAP passwords, API keys, and other credentials in plain text in
.envfiles is a security risk. This PR adds transparent encryption support using AES-256-GCM, leveraging the existingTokenStorageServiceto eliminate code duplication and providing both CLI and Admin UI options for encrypting values.Implementation
CLI encryption tool (
server/utils/encryptEnvValue.js)TOKEN_ENCRYPTION_KEYfrom environmentTokenStorageServicefor consistencyENC[AES256_GCM,data:...,iv:...,tag:...,type:str]Automatic decryption (
server/envDecryptor.js)config.jsbefore any other modulesTokenStorageServicefor decryption (no code duplication)ENC[...]values at startupAdmin UI Integration (NEW)
/api/admin/auth/encrypt-valueendpointDocumentation
docs/encryption.mdconfig.envand.env.exampleUsage
Option 1: CLI Tool
Option 2: Admin UI API
Use in .env
Key Points
TokenStorageService- no code duplicationArchitecture
All encryption now uses the same
TokenStorageService:This ensures consistency, eliminates duplicate code, and provides a single source of truth for encryption across the application.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.