Skip to content

Commit

Permalink
Non owner can delete domain after grace period ends (#1201)
Browse files Browse the repository at this point in the history
* bnsd: Implement grace perion feature on deleteDomain

* bnscli: add domain grace period to update-account-conf

* bnsd: Add domain grace period to datamigration

* Add changelog
  • Loading branch information
orkunkl authored Apr 6, 2020
1 parent 406079a commit 35b6df3
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## HEAD
- `feature/account`: A non owner can delete domain after grace period ends

## 1.0.1
- `bnsd`: updated error messages to better reflect the account module spec
Expand Down
3 changes: 2 additions & 1 deletion cmd/bnscli/clitests/account_update_configuration.test.gold
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"valid_name": "^valid-name-rule$",
"valid_blockchain_id": "^valid-bl-id-rule$",
"valid_blockchain_address": "^valid-bl-address-rule$",
"domain_renew": 151711200
"domain_renew": 151711200,
"domain_grace_period": 2592000
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/bnscli/cmd_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Create a transaction for registering an account within a given domain.
nameFl = fl.String("name", "", "Account name")
domainFl = fl.String("domain", "", "Account domain.")
adminFl = flAddress(fl, "owner", "", "An address that the newly registered account will belong to.")
brokerFl = flAddress(fl, "broker", "", "Address of the issuer entity")
brokerFl = flAddress(fl, "broker", "", "Address of the issuer entity")
)
fl.Parse(args)

Expand Down Expand Up @@ -201,6 +201,7 @@ Create a transaction to change account extension configuration.
validBlockchainID = fl.String("valid-bl-id", "", "Regular expression defining a rule for a valid blockchain ID string.")
validBlockchainAddr = fl.String("valid-bl-address", "", "Regular expression defining a rule for a valid blockchain address string.")
domainRenewFl = fl.Duration("domain-renew", 0, "Domain renew time.")
domainGracePeriodFl = fl.Duration("domain-grace-period", 30*24*time.Hour, "Domain grace period.")
)
fl.Parse(args)

Expand All @@ -214,6 +215,7 @@ Create a transaction to change account extension configuration.
ValidBlockchainID: *validBlockchainID,
ValidBlockchainAddress: *validBlockchainAddr,
DomainRenew: weave.AsUnixDuration(*domainRenewFl),
DomainGracePeriod: weave.AsUnixDuration(*domainGracePeriodFl),
},
}
if err := msg.Validate(); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/bnsd/app/datamigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func migrateRelease_1_0(ctx context.Context, db weave.KVStore) error {
ValidBlockchainID: `^[a-z0-9A-Z\-]+$`,
ValidBlockchainAddress: `^[a-z0-9A-Z]+$`,
DomainRenew: weave.AsUnixDuration(365*24*time.Hour + 6*time.Hour),
DomainGracePeriod: weave.AsUnixDuration(30 * 24 * time.Hour),
}); err != nil {
return errors.Wrap(err, "save initial gconf configuration")
}
Expand All @@ -85,6 +86,7 @@ func migrateRelease_1_0(ctx context.Context, db weave.KVStore) error {
ValidBlockchainID: `^[a-z0-9A-Z\-:]+$`,
ValidBlockchainAddress: `^[a-z0-9A-Z]+$`,
DomainRenew: weave.AsUnixDuration(365*24*time.Hour + 6*time.Hour),
DomainGracePeriod: weave.AsUnixDuration(30 * 24 * time.Hour),
}); err != nil {
return errors.Wrap(err, "save final gconf configuration")
}
Expand Down
168 changes: 104 additions & 64 deletions cmd/bnsd/x/account/codec.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion cmd/bnsd/x/account/codec.proto
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ message Configuration {
// Valid blockchain address defines a regular expression that a valid target
// blockchain address must match.
string valid_blockchain_address = 6;
// Domain review defines the duration of the domain renewal period.
// Domain renew defines the duration of the domain renewal period.
int64 domain_renew = 7 [(gogoproto.casttype) = "github.com/iov-one/weave.UnixDuration"];
// Domain grace period defines the duration of the release duration of a domain. A non-admin
// can delete the domain after the grace period ends.
int64 domain_grace_period = 8 [(gogoproto.casttype) = "github.com/iov-one/weave.UnixDuration"];
}

// UpdateConfigurationMsg is used by the gconf extension to update the
Expand Down
17 changes: 15 additions & 2 deletions cmd/bnsd/x/account/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,22 @@ func (h *deleteDomainHandler) validate(ctx weave.Context, db weave.KVStore, tx w
if !domain.HasSuperuser {
return nil, nil, errors.Wrap(errors.ErrState, "domain without a superuser cannot be deleted")
}
if !h.auth.HasAddress(ctx, domain.Admin) {
return nil, nil, errors.Wrap(errors.ErrUnauthorized, "only admin can delete a domain")
conf, err := loadConf(db)
if err != nil {
return nil, nil, errors.Wrap(err, "cannot load configuration")
}
now, err := weave.BlockTime(ctx)
if err != nil {
return nil, nil, errors.Wrap(err, "block time")
}
// if now > domain.ValidUntil + DomainGracePeriod then non owner can delete
// issue https://github.com/iov-one/weave/issues/1199
if !now.After(domain.ValidUntil.Add(conf.DomainGracePeriod.Duration()).Time()) {
if !h.auth.HasAddress(ctx, domain.Admin) {
return nil, nil, errors.Wrap(errors.ErrUnauthorized, "only admin can delete a domain")
}
}

return &domain, &msg, nil
}

Expand Down
Loading

0 comments on commit 35b6df3

Please sign in to comment.