Skip to content

Commit

Permalink
Fix error when deactivating an account (#7899)
Browse files Browse the repository at this point in the history
The RA's DeactivateAccount method expects the account provided to it by
the WFE to still have status Valid. The new WFE deactivation code was
hardcoding the status to Deactivated. Fix the WFE to pass the account's
current status instead.

Add an integration test to confirm both the breakage and the fix. Also
leave behind some TODOs to simplify this codepath further, and not
require the status to be provided at all.

Part of #5554
  • Loading branch information
aarongable authored Dec 18, 2024
1 parent 5c34d05 commit 0c658f2
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
5 changes: 5 additions & 0 deletions ra/ra.go
Original file line number Diff line number Diff line change
Expand Up @@ -2442,13 +2442,18 @@ func (ra *RegistrationAuthorityImpl) DeactivateRegistration(ctx context.Context,
if reg == nil || reg.Id == 0 {
return nil, errIncompleteGRPCRequest
}
// TODO(#5554): Remove this check: this is only enforcing that the WFE has
// told us the correct status. The SA will enforce that the current status is
// valid during its database update.
if reg.Status != string(core.StatusValid) {
return nil, berrors.MalformedError("only valid registrations can be deactivated")
}
_, err := ra.SA.DeactivateRegistration(ctx, &sapb.RegistrationID{Id: reg.Id})
if err != nil {
return nil, err
}

// TODO(#5554): Return the updated account object.
return &emptypb.Empty{}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions sa/sa.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ func (ssa *SQLStorageAuthority) DeactivateRegistration(ctx context.Context, req
if err != nil {
return nil, err
}

// TODO(#5554): Return the updated account object.
return &emptypb.Empty{}, nil
}

Expand Down
50 changes: 50 additions & 0 deletions test/integration/account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//go:build integration

package integration

import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"testing"

"github.com/eggsampler/acme/v3"

"github.com/letsencrypt/boulder/core"
)

// TestAccountDeactivate tests that account deactivation works. It does not test
// that we reject requests for other account statuses, because eggsampler/acme
// wisely does not allow us to construct such malformed requests.
func TestAccountDeactivate(t *testing.T) {
t.Parallel()

c, err := acme.NewClient("http://boulder.service.consul:4001/directory")
if err != nil {
t.Fatalf("failed to connect to acme directory: %s", err)
}

acctKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
t.Fatalf("failed to generate account key: %s", err)
}

account, err := c.NewAccount(acctKey, false, true, "mailto:hello@blackhole.net")
if err != nil {
t.Fatalf("failed to create initial account: %s", err)
}

got, err := c.DeactivateAccount(account)
if err != nil {
t.Errorf("unexpected error while deactivating account: %s", err)
}

if got.Status != string(core.StatusDeactivated) {
t.Errorf("account deactivation should have set status to %q, instead got %q", core.StatusDeactivated, got.Status)
}

// TODO(#5554): Check that the contacts have been cleared. We can't do this
// today because eggsampler/acme unmarshals the WFE's response into the same
// account object as it used to make the request, and a wholly missing
// contacts field doesn't overwrite whatever eggsampler was holding in memory.
}
7 changes: 6 additions & 1 deletion wfe2/wfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -1466,12 +1466,17 @@ func (wfe *WebFrontEndImpl) updateAccount(
// their contacts, the deactivation will take place and return before an
// update would be performed. Deactivation deletes the contacts field.
if accountUpdateRequest.Status == core.StatusDeactivated {
_, err = wfe.ra.DeactivateRegistration(ctx, &corepb.Registration{Id: currAcct.ID, Status: string(core.StatusDeactivated)})
// TODO(#5554): Remove the need to pass Status here: we wouldn't have reached
// this point unless the requesting account was valid.
_, err = wfe.ra.DeactivateRegistration(ctx, &corepb.Registration{Id: currAcct.ID, Status: string(currAcct.Status)})
if err != nil {
return nil, web.ProblemDetailsForError(err, "Unable to deactivate account")
}

// TODO(#5554): Have DeactivateRegistration return the updated account
// object, so we don't have to modify it ourselves.
currAcct.Status = core.StatusDeactivated
currAcct.Contact = nil
return currAcct, nil
}

Expand Down
6 changes: 0 additions & 6 deletions wfe2/wfe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2756,9 +2756,6 @@ func TestDeactivateAccount(t *testing.T) {
"n": "yNWVhtYEKJR21y9xsHV-PD_bYwbXSeNuFal46xYxVfRL5mqha7vttvjB_vc7Xg2RvgCxHPCqoxgMPTzHrZT75LjCwIW2K_klBYN8oYvTwwmeSkAz6ut7ZxPv-nZaT5TJhGk0NT2kh_zSpdriEJ_3vW-mqxYbbBmpvHqsa1_zx9fSuHYctAZJWzxzUZXykbWMWQZpEiE0J4ajj51fInEzVn7VxV-mzfMyboQjujPh7aNJxAWSq4oQEJJDgWwSh9leyoJoPpONHxh5nEE5AjE01FkGICSxjpZsF-w8hOTI3XXohUdu29Se26k2B0PolDSuj0GIQU6-W9TdLXSjBb2SpQ",
"e": "AQAB"
},
"contact": [
"mailto:person@mail.com"
],
"status": "deactivated"
}`)

Expand All @@ -2775,9 +2772,6 @@ func TestDeactivateAccount(t *testing.T) {
"n": "yNWVhtYEKJR21y9xsHV-PD_bYwbXSeNuFal46xYxVfRL5mqha7vttvjB_vc7Xg2RvgCxHPCqoxgMPTzHrZT75LjCwIW2K_klBYN8oYvTwwmeSkAz6ut7ZxPv-nZaT5TJhGk0NT2kh_zSpdriEJ_3vW-mqxYbbBmpvHqsa1_zx9fSuHYctAZJWzxzUZXykbWMWQZpEiE0J4ajj51fInEzVn7VxV-mzfMyboQjujPh7aNJxAWSq4oQEJJDgWwSh9leyoJoPpONHxh5nEE5AjE01FkGICSxjpZsF-w8hOTI3XXohUdu29Se26k2B0PolDSuj0GIQU6-W9TdLXSjBb2SpQ",
"e": "AQAB"
},
"contact": [
"mailto:person@mail.com"
],
"status": "deactivated"
}`)

Expand Down

0 comments on commit 0c658f2

Please sign in to comment.