Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(server): say when a secretbox gate key is set but invalid (#11045)

eatmoreduck 多吃鸭7b53608e1681
diff --git a/server/cmd/server/router.go b/server/cmd/server/router.go
index f888e2fd52..425d2c2336 100644
--- a/server/cmd/server/router.go
+++ b/server/cmd/server/router.go
@@ -111,6 +111,21 @@ var corsExposedHeaders = []string{
handler.HeaderDashboardHistoryLimit,
}
+// logSecretboxGateDisabled explains why a secretbox-gated integration stayed
+// off. A key that reached the process but fails to decode (invalid base64,
+// wrong length) is an operator error the old blanket "not set" message hid:
+// the operator reads "not set", goes to debug their env plumbing, and the real
+// reason — the value arrived and was simply invalid — never surfaces
+// (#9036). Distinguish the two so the log answers the question the operator
+// will actually ask next.
+func logSecretboxGateDisabled(label, envVar string, err error) {
+ if os.Getenv(envVar) != "" {
+ slog.Warn(label+" disabled ("+envVar+" is set but invalid)", "reason", err)
+ return
+ }
+ slog.Info(label + " disabled (" + envVar + " not set)")
+}
+
func registerPluginActionRoutes(r chi.Router, h *handler.Handler) {
r.Get(publicapiv1.PathContext, h.GetPluginContext)
r.Get(publicapiv1.PathIssue, h.GetPluginIssue)
@@ -796,7 +811,7 @@ func NewRouterWithOptions(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.Bus
}
}
} else {
- slog.Info("lark integration disabled (MULTICA_LARK_SECRET_KEY not set)")
+ logSecretboxGateDisabled("lark integration", "MULTICA_LARK_SECRET_KEY", err)
}
// Slack integration. Multi-tenant B2 model (MUL-3666): Multica hosts ONE
@@ -903,7 +918,7 @@ func NewRouterWithOptions(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.Bus
slog.Info("slack integration enabled (BYO per-installation socket mode)")
}
} else {
- slog.Info("slack integration disabled (MULTICA_SLACK_SECRET_KEY not set)")
+ logSecretboxGateDisabled("slack integration", "MULTICA_SLACK_SECRET_KEY", err)
}
// DingTalk uses one outbound Stream connection per BYO installation. The
@@ -953,7 +968,7 @@ func NewRouterWithOptions(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.Bus
slog.Info("dingtalk integration enabled (BYO per-installation stream mode)")
}
} else {
- slog.Info("dingtalk integration disabled (MULTICA_DINGTALK_SECRET_KEY not set)")
+ logSecretboxGateDisabled("dingtalk integration", "MULTICA_DINGTALK_SECRET_KEY", err)
}
// WeCom smart-bot integration ("智能机器人" / aibot). Per-installation
@@ -1264,7 +1279,7 @@ func NewRouterWithOptions(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.Bus
}
}
} else {
- slog.Info("wecom integration disabled (MULTICA_WECOM_SECRET_KEY not set)")
+ logSecretboxGateDisabled("wecom integration", "MULTICA_WECOM_SECRET_KEY", err)
}
// WeChat iLink needs only an at-rest key; users authorize their bot by QR.
@@ -1289,7 +1304,7 @@ func NewRouterWithOptions(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.Bus
slog.Info("weixin integration enabled (QR login and long polling)")
}
} else {
- slog.Info("weixin integration disabled (MULTICA_WEIXIN_SECRET_KEY not set)")
+ logSecretboxGateDisabled("weixin integration", "MULTICA_WEIXIN_SECRET_KEY", err)
}
// Telegram integration. Same shape as Slack: BYO bot token pasted at
@@ -1358,7 +1373,7 @@ func NewRouterWithOptions(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.Bus
slog.Info("telegram integration enabled (per-installation long polling)")
}
} else {
- slog.Info("telegram integration disabled (MULTICA_TELEGRAM_SECRET_KEY not set)")
+ logSecretboxGateDisabled("telegram integration", "MULTICA_TELEGRAM_SECRET_KEY", err)
}
// Composio integration (MUL-3720). Gated by COMPOSIO_API_KEY plus the
@@ -1471,7 +1486,7 @@ func NewRouterWithOptions(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.Bus
slog.Info("vcs integration enabled")
}
} else {
- slog.Info("vcs integration disabled (MULTICA_VCS_SECRET_KEY not set)")
+ logSecretboxGateDisabled("vcs integration", "MULTICA_VCS_SECRET_KEY", err)
}
// Plugin secrets use a dedicated deployment key. Keeping this separate from
@@ -1498,7 +1513,7 @@ func NewRouterWithOptions(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.Bus
slog.Info("Plugin secret encryption enabled")
}
} else {
- slog.Info("Plugin secrets disabled (MULTICA_PLUGIN_SECRET_KEY not set)")
+ logSecretboxGateDisabled("Plugin secrets", "MULTICA_PLUGIN_SECRET_KEY", err)
}
// Hook engine. Event-triggered hooks are dispatched off the bus onto a
diff --git a/server/cmd/server/secretbox_gate_logging_test.go b/server/cmd/server/secretbox_gate_logging_test.go
new file mode 100644
index 0000000000..1e5b7023b7
--- /dev/null
+++ b/server/cmd/server/secretbox_gate_logging_test.go
@@ -0,0 +1,70 @@
+package main
+
+import (
+ "bytes"
+ "errors"
+ "log/slog"
+ "strings"
+ "testing"
+)
+
+// captureDefaultLogger swaps the package-level slog default for one writing
+// into buf and returns a restore func, so the assertions see exactly what the
+// gate helper emitted through slog.Info/slog.Warn.
+func captureDefaultLogger(buf *bytes.Buffer) func() {
+ previous := slog.Default()
+ logger := slog.New(slog.NewTextHandler(buf, &slog.HandlerOptions{Level: slog.LevelDebug}))
+ slog.SetDefault(logger)
+ return func() { slog.SetDefault(previous) }
+}
+
+func TestLogSecretboxGateDisabledDistinguishesSetButInvalidFromNotSet(t *testing.T) {
+ const envVar = "MULTICA_TELEGRAM_SECRET_KEY"
+ const gateErr = "secretbox: MULTICA_TELEGRAM_SECRET_KEY decodes to 13 bytes, expected 32"
+
+ t.Setenv(envVar, "not-a-valid-key")
+
+ var logs bytes.Buffer
+ restore := captureDefaultLogger(&logs)
+ defer restore()
+
+ logSecretboxGateDisabled("telegram integration", envVar, errors.New(gateErr))
+
+ out := logs.String()
+ if !strings.Contains(out, "WARN") {
+ t.Fatalf("a set-but-invalid key must log at WARN, got:\n%s", out)
+ }
+ if !strings.Contains(out, "is set but invalid") {
+ t.Fatalf("the message must say the variable is set but invalid, got:\n%s", out)
+ }
+ if !strings.Contains(out, gateErr) {
+ t.Fatalf("the decode reason must be surfaced, got:\n%s", out)
+ }
+ if strings.Contains(out, "not set") {
+ t.Fatalf("a set-but-invalid key must not be reported as \"not set\", got:\n%s", out)
+ }
+}
+
+func TestLogSecretboxGateDisabledKeepsNotSetAtInfo(t *testing.T) {
+ const envVar = "MULTICA_TELEGRAM_SECRET_KEY"
+ const gateErr = "secretbox: MULTICA_TELEGRAM_SECRET_KEY is not set"
+
+ t.Setenv(envVar, "")
+
+ var logs bytes.Buffer
+ restore := captureDefaultLogger(&logs)
+ defer restore()
+
+ logSecretboxGateDisabled("telegram integration", envVar, errors.New(gateErr))
+
+ out := logs.String()
+ if !strings.Contains(out, "INFO") {
+ t.Fatalf("an intentionally unset variable stays a normal INFO line, got:\n%s", out)
+ }
+ if !strings.Contains(out, "not set") {
+ t.Fatalf("the message must say the variable is not set, got:\n%s", out)
+ }
+ if strings.Contains(out, "WARN") {
+ t.Fatalf("an unset variable is not an operator error and must not warn, got:\n%s", out)
+ }
+}