panel,mail: fail closed on the rate-limit race, session create and app delete
test / test (push) Has been cancelled
test / test (push) Has been cancelled
The level-2 limiter counted stored plus in-flight messages and reserved its own slot in two critical sections, so SMTP sessions that overlapped could each take the last free slot; tryAdmit now does both under one lock. A session that cannot be written no longer yields a cookie the browser would carry while every request bounced to /login. Deleting an application clears its SASL account before its registry row, matching domain delete, so a saslpasswd2 failure leaves a retryable application rather than an account that still authenticates. Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+11
-1
@@ -166,14 +166,24 @@ func (s *Service) RegeneratePassword(id int64) (string, error) {
|
||||
// Delete removes an application: its SASL account, its registry row (and address
|
||||
// rows via cascade) and its sender-map bindings, then reloads Postfix (spec
|
||||
// 7.2.8). The domain and other applications are untouched.
|
||||
//
|
||||
// The order matches domain deletion: the SASL account goes first, while the
|
||||
// login is still in the registry. Dropping the row first would, on a
|
||||
// saslpasswd2 failure, leave an account that can still authenticate to Postfix
|
||||
// but that the panel no longer knows about — an orphan no operator can see or
|
||||
// remove. Failing before the row is deleted is recoverable: the application is
|
||||
// still listed and the delete can be retried.
|
||||
func (s *Service) Delete(id int64) error {
|
||||
a, err := s.store.DeleteApplication(id)
|
||||
a, err := s.store.GetApplication(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.sasl.Delete(a.Login); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := s.store.DeleteApplication(id); err != nil {
|
||||
return err
|
||||
}
|
||||
// Drop the application's level-2 limit, if any (guide § Rate limiting);
|
||||
// rate_limits has no cascade of its own.
|
||||
if err := s.store.DeleteRateLimit(store.RateLimitScopeApp, id); err != nil {
|
||||
|
||||
@@ -181,6 +181,37 @@ func TestServiceDelete(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// If sasldb2 cannot be updated the application must stay in the registry: an
|
||||
// account that still authenticates but has no panel row is invisible to the
|
||||
// operator and cannot be deleted again.
|
||||
func TestServiceDeleteKeepsRowWhenSASLFails(t *testing.T) {
|
||||
svc, st, rec, _ := newServiceHarness(t)
|
||||
d := addDomain(t, st, "example.com")
|
||||
a, _, err := svc.Create(d.ID, "app1", store.AddressModeWildcard, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rec.failNext = true // saslpasswd2 -d fails
|
||||
if err := svc.Delete(a.ID); err == nil {
|
||||
t.Fatal("Delete reported success although the SASL account was not removed")
|
||||
}
|
||||
apps, _ := st.ListApplicationsByDomain(d.ID)
|
||||
if len(apps) != 1 {
|
||||
t.Fatalf("registry row dropped while the SASL account can still authenticate: %+v", apps)
|
||||
}
|
||||
if _, ok := rec.set["app1"]; !ok {
|
||||
t.Fatal("SASL account gone despite the failure — the harness no longer proves the ordering")
|
||||
}
|
||||
// The delete is retryable now that the row is still there.
|
||||
if err := svc.Delete(a.ID); err != nil {
|
||||
t.Fatalf("retried Delete: %v", err)
|
||||
}
|
||||
if _, ok := rec.set["app1"]; ok {
|
||||
t.Error("SASL account not deleted on retry")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceUpdateMode(t *testing.T) {
|
||||
svc, st, _, maps := newServiceHarness(t)
|
||||
d := addDomain(t, st, "example.com")
|
||||
|
||||
Reference in New Issue
Block a user