Let people sign up, be approved, and issue their own keys
Every key needed an operator with a shell. This adds the login system that made that necessary, which is the thing I argued against building until it was asked for — so it is built as if it will be attacked, because a public login form is. Signing up produces an account that can do nothing. Approval is what makes it work and stays on the CLI: having a shell on the control plane is what makes someone an administrator, and that is a smaller thing to get right than roles and an admin UI that mints credentials. The details that matter: Passwords are argon2id, where a slow hash is correct — the input is chosen by a human and has a dictionary, which is the opposite of an API key. Both kinds of authentication now live in this codebase and they are in separate packages so neither set of assumptions leaks into the other. Length is the only rule: composition rules push people towards Password1! and cost more entropy than they buy. Signup never says whether an address already has an account, and sign-in answers the same way for a wrong password and a missing account — verifying against a dummy hash when there is no user, so a stopwatch cannot enumerate accounts. Account state is checked after the password, not before, so guessing an address reveals nothing about it. Guessing is bounded per address rather than per IP: an attacker has many addresses to come from and one to guess against, and limiting by IP locks out an office behind one NAT. Sessions are server-side, so signing out and suspending take effect immediately rather than whenever a token expires; suspension is checked in the same query that resolves the session, because a second round trip is a check somebody eventually forgets. Every state-changing form carries a CSRF token verified against a hash in the session — a cookie authenticates the browser, not the page that asked. Key ownership is enforced in the UPDATE rather than by reading first, so a guessed key id from another account changes nothing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8d35faf6f8
commit
216fc9bb03
22 files changed
+2263
-39
No files matched your search
+26
-13
@@ -24,7 +24,7 @@ func get(t *testing.T, h http.Handler, target string, headers map[string]string)
|
||||
}
|
||||
|
||||
func TestLandingPageTellsYouHowToConnect(t *testing.T) {
|
||||
code, body := get(t, Landing("v1.2.3", true, "", ""), "http://llmgw.example/", nil)
|
||||
code, body := get(t, Landing("v1.2.3", true, false, "", ""), "http://llmgw.example/", nil)
|
||||
if code != http.StatusOK {
|
||||
t.Fatalf("status %d", code)
|
||||
}
|
||||
@@ -38,7 +38,7 @@ func TestLandingPageTellsYouHowToConnect(t *testing.T) {
|
||||
func TestLandingPageSaysNothingAboutWhatIsHere(t *testing.T) {
|
||||
// It is served without a key, to anyone who can reach the address. Anything
|
||||
// on it is public, so nothing about the cluster belongs on it.
|
||||
_, body := get(t, Landing("v1", true, "", ""), "http://llmgw.example/", nil)
|
||||
_, body := get(t, Landing("v1", true, false, "", ""), "http://llmgw.example/", nil)
|
||||
for _, leak := range []string{"llama", "qwen", "10.0.0.", "replica", "node01"} {
|
||||
if strings.Contains(strings.ToLower(body), leak) {
|
||||
t.Errorf("the landing page leaks %q", leak)
|
||||
@@ -49,11 +49,11 @@ func TestLandingPageSaysNothingAboutWhatIsHere(t *testing.T) {
|
||||
func TestLandingPageWarnsWhenTheGatewayIsOpen(t *testing.T) {
|
||||
// Someone who reaches this page on an unauthenticated gateway should learn
|
||||
// that from the page rather than by discovering they can use it.
|
||||
_, open := get(t, Landing("v1", false, "", ""), "http://llmgw.example/", nil)
|
||||
_, open := get(t, Landing("v1", false, false, "", ""), "http://llmgw.example/", nil)
|
||||
if !strings.Contains(open, "no API keys configured") {
|
||||
t.Error("an open gateway does not say so")
|
||||
}
|
||||
_, closed := get(t, Landing("v1", true, "", ""), "http://llmgw.example/", nil)
|
||||
_, closed := get(t, Landing("v1", true, false, "", ""), "http://llmgw.example/", nil)
|
||||
if strings.Contains(closed, "no API keys configured") {
|
||||
t.Error("a closed gateway claims to be open")
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func TestTheExampleURLSurvivesAReverseProxy(t *testing.T) {
|
||||
// The process sees http and an internal host; the client used https and a
|
||||
// public name. An example naming the internal address is one nobody can
|
||||
// paste anywhere.
|
||||
_, body := get(t, Landing("v1", true, "", ""), "http://10.0.0.140:8080/", map[string]string{
|
||||
_, body := get(t, Landing("v1", true, false, "", ""), "http://10.0.0.140:8080/", map[string]string{
|
||||
"X-Forwarded-Proto": "https",
|
||||
"X-Forwarded-Host": "llmgw.mynodes.xyz",
|
||||
})
|
||||
@@ -77,7 +77,7 @@ func TestTheExampleURLSurvivesAReverseProxy(t *testing.T) {
|
||||
|
||||
func TestForwardedHeaderChainsTakeTheFirstEntry(t *testing.T) {
|
||||
// A chain of proxies appends rather than replaces.
|
||||
_, body := get(t, Landing("v1", true, "", ""), "http://internal/", map[string]string{
|
||||
_, body := get(t, Landing("v1", true, false, "", ""), "http://internal/", map[string]string{
|
||||
"X-Forwarded-Proto": "https, http",
|
||||
"X-Forwarded-Host": "llmgw.example, internal",
|
||||
})
|
||||
@@ -89,7 +89,7 @@ func TestForwardedHeaderChainsTakeTheFirstEntry(t *testing.T) {
|
||||
func TestOnlyTheRootIsTheLandingPage(t *testing.T) {
|
||||
// A catch-all would turn every mistyped path into this page, hiding real
|
||||
// 404s from anyone debugging a client.
|
||||
code, _ := get(t, Landing("v1", true, "", ""), "http://x/v1/chat/completionz", nil)
|
||||
code, _ := get(t, Landing("v1", true, false, "", ""), "http://x/v1/chat/completionz", nil)
|
||||
if code != http.StatusNotFound {
|
||||
t.Errorf("a mistyped path returned %d", code)
|
||||
}
|
||||
@@ -235,12 +235,14 @@ func TestStaticIsNotAFileServer(t *testing.T) {
|
||||
func TestTheLandingPageSaysWhereToGetAKey(t *testing.T) {
|
||||
// A page that explains the API and leaves the reader with no route to using
|
||||
// it is where onboarding stops.
|
||||
_, body := get(t, Landing("v1", true, "platform@example.com", ""), "http://x/", nil)
|
||||
_, body := get(t, Landing("v1", true, false, "platform@example.com", ""), "http://x/", nil)
|
||||
if !strings.Contains(body, `href="mailto:platform@example.com"`) {
|
||||
t.Error("an address was not turned into a mailto link")
|
||||
}
|
||||
if !strings.Contains(body, "one-time link") {
|
||||
t.Error("the page does not say how a key will arrive")
|
||||
// With signup closed, the route is a person; the page still has to say what
|
||||
// arriving looks like.
|
||||
if !strings.Contains(body, "shown once") {
|
||||
t.Error("the page does not say a key cannot be recovered")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +286,7 @@ func TestADangerousContactSchemeIsNeverLinked(t *testing.T) {
|
||||
t.Errorf("contactLink(%q) dropped the text entirely", bad)
|
||||
}
|
||||
|
||||
_, body := get(t, Landing("v1", true, bad, ""), "http://x/", nil)
|
||||
_, body := get(t, Landing("v1", true, false, bad, ""), "http://x/", nil)
|
||||
if strings.Contains(body, "href=\"javascript") || strings.Contains(body, "href=\"data:") {
|
||||
t.Errorf("%q reached the page as a link", bad)
|
||||
}
|
||||
@@ -292,7 +294,7 @@ func TestADangerousContactSchemeIsNeverLinked(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTheNoticeIsEscaped(t *testing.T) {
|
||||
_, body := get(t, Landing("v1", true, "", "<script>alert(1)</script>"), "http://x/", nil)
|
||||
_, body := get(t, Landing("v1", true, false, "", "<script>alert(1)</script>"), "http://x/", nil)
|
||||
if strings.Contains(body, "<script>alert(1)</script>") {
|
||||
t.Error("the notice was rendered as markup")
|
||||
}
|
||||
@@ -302,8 +304,19 @@ func TestTheNoticeIsEscaped(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithoutAContactThePageStillSaysSomethingUseful(t *testing.T) {
|
||||
_, body := get(t, Landing("v1", true, "", ""), "http://x/", nil)
|
||||
_, body := get(t, Landing("v1", true, false, "", ""), "http://x/", nil)
|
||||
if !strings.Contains(body, "whoever operates this gateway") {
|
||||
t.Error("an unconfigured gateway leaves the reader with nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithSignupOpenTheLandingPagePointsAtIt(t *testing.T) {
|
||||
// The route from "I found this address" to "I have a key" has to be on the
|
||||
// page, or the reader is stuck whatever else it says.
|
||||
_, body := get(t, Landing("v1", true, true, "", ""), "http://x/", nil)
|
||||
for _, want := range []string{`href="/signup"`, `href="/login"`, `href="/profile"`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("the page does not link to %s", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user