Issue
Production Azure OpenAI API keys and Redis passwords stored in plaintext .env files introduced multiple security risks:
- Credential exposure: Potential accidental git commits or leaks of full production credentials.
- Unlimited cost exposure: Leaked API keys enabled unlimited API usage, posing financial risks.
- No audit trails: Lack of tracking for API usage or access, complicating breach detection.
- Single point of failure: Shared production credentials across all clients increased risk concentration.
The current setup directly accessed production services without isolation or safeguards.
Culprit
The security gaps originated from:
- Direct credential exposure: Production credentials stored in version-controlled
.envfiles without protection. - Shared resource model: All clients used the same production Azure OpenAI and Redis instances without isolation.
- Missing safeguards: Absence of rate limiting, user-specific keys, and audit logging mechanisms.
Solution
Option 1: Separate Azure Resources (Recommended for Personal Use)
- Isolated Resources: Created dedicated Azure resources for each client with hard usage quotas.
- Cost Control: Implemented capped spending limits (e.g., $50/month) to prevent financial exposure.
- Key Rotation: Simplified credential management with client-specific keys.
- Monitoring: Separated billing and usage tracking for each client.
Option 2: API Gateway with User Keys (Team Use)
- API Gateway: Deployed an AKS-based API gateway integrating with Azure Key Vault for credential management.
- Per-User Keys: Generated individual keys for each user with strict rate limits (e.g., 5 TPM per user).
- Audit Logging: Enabled comprehensive logging via AKS for tracking API usage.
- Key Revocation: Implemented mechanisms for instant key revocation in case of breaches.
Option 3: Offline Read-Only Mode (Demos)
- Local Data Export: Pre-generated embeddings and metadata stored locally to eliminate network dependencies.
- No Credentials: Eliminated the need for credentials in offline environments.
- Immutable Data: Ensured data integrity with no write operations.
Security Best Practices Implemented
- Credential Isolation: Added
.env*files to.gitignoreto prevent accidental commits. - Quota Enforcement: Configured Azure OpenAI quotas to limit usage per client.
- Audit Logging: Integrated middleware for logging requests and user activities.
Cost Comparison
| Approach | Setup Cost | Monthly Cost | Risk Exposure |
|---|---|---|---|
| Current (Basic) | $0 | $0 | Unlimited |
| Separate Resources | $0 | ~$50 | Capped |
| API Gateway | $0 | $0 | Shared |
| Offline | $0 | $0 | None |
This solution ensures robust credential management, cost control, and auditability while maintaining flexibility for different use cases.