Add a landing page and a read-only cluster dashboard
Pasting the gateway's address into a browser returned 404, which looks like a broken endpoint rather than one that tells you how to use it. Two pages, and the split between them is a security boundary rather than a layout choice. The landing page is served without a key — it has to be, because the person reading it is the one who does not have one yet — so it contains no data at all: it says how to connect, not what is here. Model names stay behind /v1/models. It reconstructs the address from the forwarded headers so the copy-pasteable example names the address the client actually used rather than the internal one; those headers are reflected into displayed text and never used for a decision. The dashboard shows nodes, models, replicas, placement failures and usage, and lives on the admin listener only. That listener is loopback-bound and also serves pprof, which can dump the process heap — where API keys sit in plaintext — so reaching the page from elsewhere is an SSH tunnel's job. It is read-only: anything that mints a credential stays in `llmgw keys`, where it needs a shell rather than a browser session this project has no way to authenticate. Mounting the landing page uncovered a hole in the exemption list. An entry ending in "/" was a prefix rule, and "/" ends in "/", so exempting the landing page would have exempted every path there is — authentication still installed, still logging, and letting the whole API through. "/" is now exact, with a test enumerating what must and must not be exempt. Server-rendered templates and one stylesheet, embedded. The single-binary goal rules out a JavaScript toolchain and nothing on either page needs one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
0b93fb2883
commit
1839832b8b
14 files changed
+836
-10
No files matched your search
@@ -504,3 +504,31 @@ func nowMillis() int64 { return time.Now().UnixMilli() }
|
||||
|
||||
// SQLite satisfies Store.
|
||||
var _ Store = (*SQLite)(nil)
|
||||
|
||||
// UsageSince summarizes activity per key.
|
||||
//
|
||||
// The join brings in the key's name and prefix, which is what a dashboard needs
|
||||
// to show: a row identified only by an opaque id tells an operator nothing.
|
||||
// Revoked keys still appear, because their usage still happened.
|
||||
func (s *SQLite) UsageSince(ctx context.Context, since time.Time) ([]KeyUsage, error) {
|
||||
return queryAll(ctx, s.db, `
|
||||
SELECT u.key_id,
|
||||
COALESCE(k.name, ''), COALESCE(k.key_prefix, ''), u.project_id,
|
||||
COUNT(*), SUM(u.prompt_tokens), SUM(u.completion_tokens),
|
||||
SUM(u.cost_micros),
|
||||
SUM(CASE WHEN u.status >= 400 THEN 1 ELSE 0 END),
|
||||
MAX(u.ts)
|
||||
FROM usage u
|
||||
LEFT JOIN api_keys k ON k.id = u.key_id
|
||||
WHERE u.ts >= ?
|
||||
GROUP BY u.key_id, u.project_id
|
||||
ORDER BY SUM(u.cost_micros) DESC, COUNT(*) DESC`,
|
||||
[]any{millis(since)}, func(rows *sql.Rows) (KeyUsage, error) {
|
||||
var k KeyUsage
|
||||
var last int64
|
||||
err := rows.Scan(&k.KeyID, &k.KeyName, &k.KeyPrefix, &k.ProjectID,
|
||||
&k.Requests, &k.Prompt, &k.Completion, &k.CostMicros, &k.Errors, &last)
|
||||
k.LastAt = fromMillis(last)
|
||||
return k, err
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user