Refuse the keys of an account that is not active
Resolve now checks the owner's state for a personal key; the authenticator treats an inactive owner as a revoked key. Suspension stops the keys within the cache TTL, reinstatement brings them back. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
20ebd21243
commit
27c49d0af9
4 files changed
+50
No files matched your search
@@ -97,6 +97,11 @@ APIs change between minors without a deprecation period.
|
||||
the request was priced as the model asked for. Fallbacks a key may not use
|
||||
are now skipped, and a request is charged what the model that answered
|
||||
costs.
|
||||
- **Suspending an account stops its keys.** Suspension closed the person's
|
||||
sessions and left every API key they had made working. A key whose owner's
|
||||
account is not active — suspended, pending, or gone — is now refused as a
|
||||
revoked key is, within `auth.cache_ttl`, and works again when the account
|
||||
is reinstated.
|
||||
|
||||
### Everything that can be changed on a running cluster, from the console
|
||||
|
||||
|
||||
@@ -185,6 +185,11 @@ func (a *Authenticator) resolve(ctx context.Context, hash []byte) (Principal, er
|
||||
}
|
||||
|
||||
eff, err := a.store.Resolve(ctx, k.ID)
|
||||
if errors.Is(err, store.ErrOwnerInactive) {
|
||||
// Said as a revoked key is: whether the key exists is not the
|
||||
// caller's to learn.
|
||||
return Principal{}, ErrRevoked
|
||||
}
|
||||
if err != nil {
|
||||
return Principal{}, err
|
||||
}
|
||||
|
||||
@@ -190,9 +190,25 @@ func (s *DB) Resolve(ctx context.Context, keyID string) (Effective, error) {
|
||||
}
|
||||
e.Band, e.RoutingProfile = band.String, profile.String
|
||||
e.ProjectID, e.UserID = project.String, user.String
|
||||
// A person's key works while the person's account does: suspending an
|
||||
// account closed its sessions and left every key it had made working.
|
||||
if e.UserID != "" {
|
||||
var state string
|
||||
err := s.db.QueryRowContext(ctx, `SELECT state FROM users WHERE id = ?`, e.UserID).Scan(&state)
|
||||
if errors.Is(err, sql.ErrNoRows) || (err == nil && UserState(state) != UserActive) {
|
||||
return Effective{}, ErrOwnerInactive
|
||||
}
|
||||
if err != nil {
|
||||
return Effective{}, err
|
||||
}
|
||||
}
|
||||
return e, s.resolveChain(ctx, &e, true)
|
||||
}
|
||||
|
||||
// ErrOwnerInactive is a key whose owner's account is suspended, pending, or
|
||||
// gone.
|
||||
var ErrOwnerInactive = errors.New("the key's owner is not an active account")
|
||||
|
||||
// ResolveFor resolves a caller that has no key row: the chat page, spending
|
||||
// as a person in a project or, with no project, personally.
|
||||
func (s *DB) ResolveFor(ctx context.Context, callerID, userID, projectID string) (Effective, error) {
|
||||
|
||||
@@ -283,3 +283,27 @@ func TestTheChatPagesUseIsReportedWhereItWasSpent(t *testing.T) {
|
||||
t.Errorf("gateway's spend on the quota page: %d, %v", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestASuspendedPersonsKeysStopWorkingAndComeBackWithThem(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
ctx := t.Context()
|
||||
_, k, _ := NewKey("key-s", "personal", "")
|
||||
if err := f.s.CreateUserKey(ctx, f.user, k); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := f.s.Resolve(ctx, k.ID); err != nil {
|
||||
t.Fatalf("an active person's key: %v", err)
|
||||
}
|
||||
if err := f.s.SetUserState(ctx, f.user, UserSuspended); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := f.s.Resolve(ctx, k.ID); !errors.Is(err, ErrOwnerInactive) {
|
||||
t.Errorf("a suspended person's key resolved: %v", err)
|
||||
}
|
||||
if err := f.s.SetUserState(ctx, f.user, UserActive); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := f.s.Resolve(ctx, k.ID); err != nil {
|
||||
t.Errorf("reinstated, the key still refused: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user