2.4 KiB
2.4 KiB
| tags | source | created | ||
|---|---|---|---|---|
|
cinema-studio-pro-kling | 2026-04-29 |
Runtime Credential Rotation with Admin Panel
When to use
When you need to allow administrators to update time-sensitive API credentials (like monthly token rotation) without redeploying the application, and credentials must persist across server restarts.
Prerequisites
- Application with admin user concept (authenticated via SSO like Azure AD)
- Backend environment file system (
.envfiles) - Admin users identified by email address in authentication system
- API that requires periodic credential rotation (e.g., monthly token refresh)
Steps
-
Define admin users by adding their email addresses to the server's
.envfile:echo "ADMIN_EMAILS=user@example.com,another@example.com" >> backend/.env.optical(Use emails that match your SSO system, e.g., Azure AD login emails)
-
Create an admin panel endpoint that:
- Verifies the requesting user's email is in
ADMIN_EMAILS - Accepts new credential values (API key, secret, tokens)
- Updates the server's
.envfile directly - Reloads/restarts the application service to apply changes
- Verifies the requesting user's email is in
-
When deploying updates that might overwrite credentials:
git stash # Save local .env changes (real credentials) git pull # Get latest from repository git stash pop # Restore credentials
Key Configuration
# In backend/.env.optical (server-side only, not in git)
ADMIN_EMAILS=vadym.samoilenko@oliver.agency
API_KEY=<current-valid-key>
API_SECRET=<current-valid-secret>
Environment-specific configuration:
- With Kling integration (playground branch):
FRONTEND_URL=https://optical-prod.oliver.solutions/lux-studio - Without Kling (main branch):
FRONTEND_URL=https://ai-sandbox.oliver.solutions/lux-studio
Gotchas
- Git conflicts on pull: Always
stashlocal.envchanges before pulling, thenstash popafter. Never commit real credentials to git. - Service restart required: Changes to
.envdon't apply automatically; the backend service must be restarted (systemd, docker, etc.) - Email case sensitivity: Ensure email addresses in
ADMIN_EMAILSexactly match the SSO system's output (test in auth logs) - Multiple admins: Use comma-separated list without spaces:
ADMIN_EMAILS=user1@example.com,user2@example.com
Source
Project: cinema-studio-pro-kling