Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup domain policy #245

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Cleanup domain policy #245

wants to merge 13 commits into from

Conversation

sydneyli
Copy link
Contributor

@sydneyli sydneyli commented Jun 21, 2019

Tested, complete version of #228.

Sorry for the massive PR; been working on-and-off on testing the move for a while. Reorganized commits this week, so they should be nicely organized and easier to review individually.

One final TODO item is to migrate old DB into the new one.

models/policy.go Outdated
return oldPolicy.Email != p.Email
}
// If old policy is manual and in testing, we can update it safely.
if !oldPolicy.MTASTS && oldPolicy.Policy.Mode == "testing" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If new policy enforce and manual, don't upgrade either


import (
"errors"
// "strings"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -30,6 +30,31 @@ type List struct {
Policies map[string]TLSPolicy `json:"policies"`
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: comment above TLSPolicy.Mode that it can only be one of none enforce testing

Copy link
Collaborator

@vbrown608 vbrown608 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I really like PolicySubmission - its role is much clearer than Domain. I also like the separation of pending vs. accepted and testing vs. enforce vs. none. That seems like clear up so much confusion from Domain.Status. The abstraction on top of the two policy tables is cool :D

api.go Outdated
@@ -41,7 +41,7 @@ type checkPerformer func(API, string) (checker.DomainResult, error)
// Any POST request accepts either URL query parameters or data value parameters,
// and prefers the latter if both are present.
type API struct {
Database db.Database
Database *db.SQLDatabase
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yesss

api.go Outdated
func getDomainParams(r *http.Request) (models.Domain, error) {
// Extracts relevant parameters from http.Request for a POST to /api/queue into PolicySubmission
// If MTASTS is set, doesn't try to extract hostnames. Otherwise, expects between 1 and MaxHostnames
// valid hostnames to be given in |r|.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helpful addition :)

RemovePolicy(string) (PolicySubmission, error)
}

type policyList interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment distinguishing this from policyStore would be helpful

models/policy.go Outdated
}

// CanUpdate returns whether we can update the policyStore with this particular
// Policy Submission. In some cases, you should be able to update the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// CanUpdate returns whether we can update the policyStore with this particular
// Policy Submission. Domains that have already been added to the policy store
// can only:
// 1. Have their their contact e-mail address updated
// 2. Have their policy updated if they're manual and in testing.

return fmt.Sprintf(query, p.tableName, "domain, email, mta_sts, mxs, mode")
}

type scanner interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite, I think-- It looks like Scanner expects a single interface{} destination, whereas here we are scanning into a varied number: ...interface{}

db/policy.go Outdated
}

// GetPolicy returns the policy submission for the given domain.
func (p *PolicyDB) GetPolicy(domainName string) (models.PolicySubmission, bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Named return values might be nice here, since the meaning of bool isn't immediately obvious.

// PutOrUpdatePolicy upserts the given policy into the data store, if
// CanUpdate passes.
func (p *PolicyDB) PutOrUpdatePolicy(ps *models.PolicySubmission) error {
if p.strict && !ps.CanUpdate(p) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like these guards - this seems like a good place for this type of validation. It seems like we're never running this code with strict = true. Is there somewhere we should be?

models/policy.go Outdated
"Please use the STARTTLS checker to scan your domain's " +
"STARTTLS configuration so we can validate your submission"
}
if scan.Timestamp.Add(time.Minute * 10).Before(time.Now()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much UX experience around this process but 10 minutes seems a bit low to me - I could imagine a user stopping on the add-domain form to do some research before submitting. Maybe an hour?

models/token.go Outdated
store.RemoveDomain(domainData.Name, domainOnList.State)
}
err = store.SetStatus(domainData.Name, StateTesting)
_, err = pending.RemovePolicy(domain)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If store.PutOrUpdatePolicy and pending.RemovePolicy always happen together maybe we should wrap them in a single action on Policy so we can make sure they always both occur.

@sydneyli
Copy link
Contributor Author

sydneyli commented Jul 2, 2019

If this generally looks OK to you, I think there are two more things to do before landing this:

  • writing the final DB migration script
  • bumping up coverage a little bit with some more testing.

Let me know if you have any more comments on the meat of the code! I'll work on the above two concurrently, but they should be relatively easy to review.

@vbrown608
Copy link
Collaborator

LGTM, ready for merge pending migration script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants