Manage .env from the admin panel
Add an Environment tab to /admin that lists every variable in .env.example and lets keys, OAuth settings, email settings and generated secrets be changed without SSH. Secrets are write-only; infrastructure variables are shown read-only. The backend never writes .env or touches Docker. It validates an edit and queues it in env-apply/run/request.json; env-apply/apply.py, run on the host by a systemd path unit (env-apply/install.sh), rewrites .env atomically, keeps .env.bak, and recreates only the services that read the change. backend/services/env_registry.json is the single list of variables, shared by the backend and the host script; a test keeps it in step with .env.example. It replaces the drifted checklist in handle_admin.go. The job capture token card moves to the new tab. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -8,95 +8,10 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// This file backs the admin diagnostics panel: a configuration report and a
|
||||
// log tail. Both are admin-only REST endpoints rather than GraphQL because
|
||||
// they read the process environment and the filesystem — things outside the
|
||||
// data model the GraphQL schema describes.
|
||||
|
||||
// ConfigVar describes one piece of configuration the backend can report on.
|
||||
// Required marks vars whose absence visibly breaks a feature; Optional vars
|
||||
// have a working default.
|
||||
type ConfigVar struct {
|
||||
Name string `json:"name"`
|
||||
Purpose string `json:"purpose"`
|
||||
Required bool `json:"required"`
|
||||
}
|
||||
|
||||
// configVars is the checklist the panel renders. Sensitive values are never
|
||||
// returned — only whether each var is present — so the endpoint cannot leak
|
||||
// credentials even to an admin client.
|
||||
var configVars = []ConfigVar{
|
||||
{"POSTGRES_HOST", "Database connectivity", true},
|
||||
{"POSTGRES_USER", "Database connectivity", true},
|
||||
{"POSTGRES_PASSWORD", "Database connectivity", true},
|
||||
{"POSTGRES_DB", "Database connectivity", true},
|
||||
{"DOMAIN", "Site origin, JWT cookie domain", true},
|
||||
{"AUTH_SECRET", "JWT signing", true},
|
||||
{"SPOTIFY_CLIENT_ID", "Spotify listening widget", true},
|
||||
{"SPOTIFY_CLIENT_SECRET", "Spotify listening widget", true},
|
||||
{"SPOTIFY_REDIRECT_URI", "Spotify listening widget", true},
|
||||
{"STEAM_API_KEY", "Steam status widget", false},
|
||||
{"STEAM_ID", "Steam status widget", false},
|
||||
{"CLAUDE_API_KEY", "Email summarisation", false},
|
||||
{"EMAIL_BACKEND", "Email sync (graph/imap)", false},
|
||||
{"MSGRAPH_CLIENT_ID", "Email sync (Microsoft Graph)", false},
|
||||
{"MSGRAPH_CLIENT_SECRET", "Email sync (Microsoft Graph)", false},
|
||||
{"MSGRAPH_REDIRECT_URI", "Email sync (Microsoft Graph)", false},
|
||||
{"MSGRAPH_TENANT_ID", "Email sync (Microsoft Graph)", false},
|
||||
{"IMAP_HOST", "Email sync (IMAP fallback)", false},
|
||||
{"IMAP_EMAIL", "Email sync (IMAP fallback)", false},
|
||||
{"IMAP_PASSWORD", "Email sync (IMAP fallback)", false},
|
||||
{"GITEA_HOST", "Gitea activity feed", false},
|
||||
{"GITEA_PORT", "Gitea activity feed", false},
|
||||
{"JWT_COOKIE_SECURE", "Cookie security in dev", false},
|
||||
{"ICECAST_URL", "Radio queue widget", false},
|
||||
}
|
||||
|
||||
// ConfigCheck backs GET /admin/config. It reports one entry per known var:
|
||||
// set or empty, plus the value only for vars flagged non-sensitive (none of
|
||||
// the credentials are). A var not in the list at all is not reported — the
|
||||
// point is a checklist, not a full env dump.
|
||||
func (store *Store) ConfigCheck(ctx *gin.Context) {
|
||||
type entry struct {
|
||||
ConfigVar
|
||||
Set bool `json:"set"`
|
||||
Value string `json:"value,omitempty"`
|
||||
Secret bool `json:"secret"`
|
||||
}
|
||||
|
||||
// Vars whose *value* may come back (bad values like "consumers" are fine;
|
||||
// they contain no credential).
|
||||
visible := map[string]bool{
|
||||
"EMAIL_BACKEND": true,
|
||||
"MSGRAPH_TENANT_ID": true,
|
||||
"ICECAST_URL": true,
|
||||
"STEAM_ID": true,
|
||||
}
|
||||
|
||||
// Explicitly-credentialled vars get the secret badge so the panel can
|
||||
// label them "present" instead of showing a masked string.
|
||||
secrets := map[string]bool{
|
||||
"POSTGRES_PASSWORD": true,
|
||||
"AUTH_SECRET": true,
|
||||
"SPOTIFY_CLIENT_SECRET": true,
|
||||
"MSGRAPH_CLIENT_SECRET": true,
|
||||
"CLAUDE_API_KEY": true,
|
||||
"STEAM_API_KEY": true,
|
||||
"IMAP_PASSWORD": true,
|
||||
}
|
||||
|
||||
result := make([]entry, 0, len(configVars))
|
||||
for _, v := range configVars {
|
||||
val := os.Getenv(v.Name)
|
||||
e := entry{ConfigVar: v, Set: strings.TrimSpace(val) != "", Secret: secrets[v.Name]}
|
||||
if e.Set && visible[v.Name] {
|
||||
e.Value = val
|
||||
}
|
||||
result = append(result, e)
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, gin.H{"vars": result})
|
||||
}
|
||||
// This file backs the admin diagnostics panel's log tail. It is an admin-only
|
||||
// REST endpoint rather than GraphQL because it reads the filesystem — outside
|
||||
// the data model the GraphQL schema describes. The configuration report that
|
||||
// used to live here is now the Environment tab (handle_env.go).
|
||||
|
||||
// logTailBytes and logTailLines bound how much of the log file one request
|
||||
// moves: 256 KiB is beyond any useful screen at log-ish line lengths, and is
|
||||
|
||||
Reference in New Issue
Block a user