A sign-in through the identity provider may end on either control plane

The cookie that carries a sign-in across the provider was signed with a
key each process made for itself, so with two control planes behind a
balancer a callback reaching the other one was refused as tampered — half
of all sign-ins. The key is now the store's oidc-state secret, sealed like
the others and the same on every control plane.

Changelog: the fixes since v0.14.2.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-10 11:33:41 +02:00
1 parent eaea671f23
commit 8d7b96621e
4 files changed
+65 -9

No files matched your search

+3 -4
View File
@@ -386,10 +386,9 @@ portal is not done — the page shows; the console and ctl change.
tenant-admin / billing; `ctl audit`. Depends on A5 for a real actor.
2. **Done (branch `features-c`):** OIDC sign-in (`auth.oidc`, PKCE,
verified email, roles and memberships from groups, `no_passwords`) and
SCIM 2.0 (`/scim/v2` Users and Groups). Left: the sign-in cookie is
signed with a per-process key, so with two control planes behind a
balancer the callback must reach the one that started it (sticky
sessions) until the key comes from the store. **OIDC/SSO login (M), then SCIM (M).** `internal/account/service.go`,
SCIM 2.0 (`/scim/v2` Users and Groups). The sign-in cookie's key comes
from the store (2026-10-10), so a callback may reach either control
plane behind a balancer. **OIDC/SSO login (M), then SCIM (M).** `internal/account/service.go`,
`internal/web/account.go`; map IdP groups to org/team/admin.
3. **Done (branch `features-c`):** key lifetime limits (gateway, org, team,
project), `keys rotate --overlap`, kinds and expiry in `keys list`.
+16
View File
@@ -26,6 +26,22 @@ APIs change between minors without a deprecation period.
## Unreleased
### Fixed
- **An engine's output no longer breaks when its agent restarts.** Engines
wrote to a pipe of the agent's, which an agent that restarted and adopted
them left with no reader; an engine's next large write failed, and in a
Python engine took the request it was reporting on with it. Each process
now writes to its own file in the agent's work directory, and an adopted
engine's log keeps what it wrote before the restart.
- **Single sign-on behind a balancer.** The cookie that carries a sign-in
across the identity provider was signed with a key of each process's own,
so with two control planes a callback that reached the other one was
refused. The key is now a secret in the store, the same on every control
plane.
- The usage sums and exports count pictures (`images`), as the request
records did; pictures made before are added to the sums.
## v0.14.2 — 2026-10-10
Pictures: OpenAI's `/v1/images/generations`, made by ComfyUI on the
+10 -4
View File
@@ -33,6 +33,8 @@ type OIDCStore interface {
AllOrgs(ctx context.Context) ([]store.Org, error)
AllTeams(ctx context.Context) ([]store.TeamPath, error)
AllProjects(ctx context.Context) ([]store.ProjectPath, error)
// ClusterSecret is a secret every control plane reads alike.
ClusterSecret(ctx context.Context, name string) (string, error)
}
// oidcLogin is sign-in through an identity provider.
@@ -59,11 +61,15 @@ func (p *AccountPages) RegisterOIDC(mux *http.ServeMux, cfg config.OIDC, st OIDC
}
secret = strings.TrimSpace(string(b))
}
key := make([]byte, 32)
if _, err := rand.Read(key); err != nil {
return err
// From the store, not made here: a sign-in begun on one control plane
// comes back from the provider to whichever one the balancer picks, and
// a key of this process's own made that one refuse it — with two behind
// a balancer, half of all sign-ins.
key, err := st.ClusterSecret(context.Background(), "oidc-state")
if err != nil {
return fmt.Errorf("the key that carries a sign-in across the provider: %w", err)
}
o := &oidcLogin{cfg: cfg, secret: secret, st: st, key: key}
o := &oidcLogin{cfg: cfg, secret: secret, st: st, key: []byte(key)}
p.oidc = o
mux.HandleFunc("GET /login/oidc", p.oidcStart)
mux.HandleFunc("GET /login/oidc/callback", p.oidcCallback)
+36 -1
View File
@@ -98,6 +98,9 @@ func (m *oidcStoreMem) AllTeams(context.Context) ([]store.TeamPath, error) {
return []store.TeamPath{{ID: "t1", Name: "ml", OrgName: "Acme"}}, nil
}
func (m *oidcStoreMem) AllProjects(context.Context) ([]store.ProjectPath, error) { return nil, nil }
func (m *oidcStoreMem) ClusterSecret(_ context.Context, name string) (string, error) {
return "the store's " + name, nil
}
type sessionAccounts struct{ fakeAccounts }
@@ -107,6 +110,13 @@ func (sessionAccounts) OpenSession(context.Context, string) (string, string, err
// signIn goes through /login/oidc and back, as a browser would.
func signIn(t *testing.T, mux http.Handler, idp *fakeIdP, tamper bool) *httptest.ResponseRecorder {
t.Helper()
return signInAcross(t, mux, mux, idp, tamper)
}
// signInAcross begins a sign-in on one gateway and comes back from the
// provider to another, as a balancer in front of two may send it.
func signInAcross(t *testing.T, mux, back http.Handler, idp *fakeIdP, tamper bool) *httptest.ResponseRecorder {
t.Helper()
start := httptest.NewRecorder()
mux.ServeHTTP(start, httptest.NewRequest("GET", "/login/oidc", nil))
@@ -127,7 +137,7 @@ func signIn(t *testing.T, mux http.Handler, idp *fakeIdP, tamper bool) *httptest
cb.AddCookie(c)
}
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, cb)
back.ServeHTTP(rec, cb)
return rec
}
@@ -172,3 +182,28 @@ func TestSigningInThroughAProvider(t *testing.T) {
t.Errorf("unknown without create_accounts: %d %s", rec.Code, rec.Body.String())
}
}
func TestASignInBegunOnOneControlPlaneEndsOnTheOther(t *testing.T) {
// The cookie carrying a sign-in across the provider was signed with a
// key each process made for itself, so with two control planes behind a
// balancer a callback reaching the other one was refused as tampered.
idp := newFakeIdP(t)
st := &oidcStoreMem{users: map[string]store.User{}, roles: map[string]string{}}
cfg := config.OIDC{Issuer: idp.srv.URL, ClientID: "llmgw", CreateAccounts: true}
var muxes []*http.ServeMux
for range 2 {
p := NewAccountPages(sessionAccounts{}, nil, nil, "v0", slog.New(slog.NewTextHandler(io.Discard, nil)))
mux := http.NewServeMux()
if err := p.RegisterOIDC(mux, cfg, st); err != nil {
t.Fatal(err)
}
muxes = append(muxes, mux)
}
idp.claims = map[string]any{"email": "dan@example.com", "email_verified": true}
if rec := signInAcross(t, muxes[0], muxes[1], idp, false); rec.Code != http.StatusSeeOther {
t.Fatalf("a callback on the other control plane: %d %s", rec.Code, rec.Body.String())
}
if rec := signInAcross(t, muxes[0], muxes[1], idp, true); rec.Code != http.StatusForbidden {
t.Errorf("a tampered state on the other control plane: %d", rec.Code)
}
}