Skip to content

Expand allowedUsers email field to support comma-separated and domains #9

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

Merged
merged 7 commits into from
Feb 14, 2021
Merged

Expand allowedUsers email field to support comma-separated and domains #9

merged 7 commits into from
Feb 14, 2021

Conversation

JonathonReinhart
Copy link
Collaborator

@JonathonReinhart JonathonReinhart commented Feb 13, 2021

This closes #8 and implements Option 1.

In addition to the unit tests, this has been tested in production with the following sample:

appsrv $2a$10$xxxxxxx [email protected],appsrv.internal.example.com

Then I attempted to send mail (sendmail):

@JonathonReinhart JonathonReinhart marked this pull request as ready for review February 14, 2021 16:41
main.go Outdated
if err != nil {
return smtpd.Error{Code: 451, Message: "Bad sender address"}
}

if email != "" && strings.ToLower(addr) != strings.ToLower(email) {
if !addrAllowed(addr, allowedAddrs) {
Copy link
Owner

Choose a reason for hiding this comment

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

You've lost the strings.ToLower(addr) case but i think this should be done in the new addrAllowed()

Copy link
Collaborator Author

@JonathonReinhart JonathonReinhart Feb 14, 2021

Choose a reason for hiding this comment

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

Good catch. This was a result of the refactor. I've fixed that, and added a test (cabf848).

main.go Outdated
return true
}

domidx := strings.LastIndex(addr, "@")
Copy link
Owner

Choose a reason for hiding this comment

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

Since addr is the sender email it shoud be valid that the address does not contain a domain and @ yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Per below, I was unaware that "local" addresses could reach smtprelay. Updated (see below).

return false
}
domain := strings.ToLower(addr[domidx+1:])

Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
addr = strings.ToLower(addr)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Applied (earlier in the function, so domain is lowercased, too).

main.go Outdated
for _, allowedAddr := range allowedAddrs {
allowedAddr = strings.ToLower(allowedAddr)

if strings.Index(allowedAddr, "@") == -1 {
Copy link
Owner

Choose a reason for hiding this comment

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

This is now a conflict because the absence of @ can be because it's a domain or a local address without domain yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Per below, I was unaware that "local" addresses could reach smtprelay. Updated (see below).

@JonathonReinhart
Copy link
Collaborator Author

JonathonReinhart commented Feb 14, 2021

In two places in addrAllowed(), I missed the fact that addr (as passed to senderChecker) could be a local address without a domain. I assumed that an SMTP Relay (MTA) would only receive mail that already had a full [email protected] address.

In that case, when would the @domain.com part be added? By the upstream smarthost to which this server relays the mail? When I try this with postfix sendmail -r somebody, local postfix is the one that appends @domain.com, due to:

$ postconf  | grep 'origin\>'
append_at_myorigin = yes
myorigin = $myhostname

Anyway, with that fact, you are correct: my allowedUsers format is ambiguous (john.doe and gmail.com are indistinguishable).

I think there is an easy fix: To specify an entire (sub)domain, you simply prefix with an @. So then:

appsrv hash [email protected],@appsrv.example.com

Means:

Does that sound reasonable?

@JonathonReinhart
Copy link
Collaborator Author

Commit c980683 addresses the problems by changing the anyone-at-domain specification to require an @ in front.

@decke
Copy link
Owner

decke commented Feb 14, 2021

That looks good now. Thanks a lot for your contribution!

@decke decke merged commit 0e8986c into decke:master Feb 14, 2021
@JonathonReinhart JonathonReinhart deleted the expanded-allowed-senders branch February 14, 2021 21:29
@JonathonReinhart
Copy link
Collaborator Author

JonathonReinhart commented Feb 14, 2021

Thanks for quickly reviewing and merging! Do you think it would make sense to tag/release 1.5.0 with these latest changes? I've been running v1.4.0-jr3 local releases 😄

Also, I noticed that you seem to have used the "Squash and merge" feature when you merged this. Would you prefer I squash future contributions into a single commit?

@decke
Copy link
Owner

decke commented Feb 16, 2021

Yes, the plan is to release 1.5.0 quite soon.

If possible please keep it as separate commits since that is a lot easier to review but in that case the commits were all about one feature so it made sense to squash them.

@JonathonReinhart
Copy link
Collaborator Author

If possible please keep it as separate commits since that is a lot easier to review but in that case the commits were all about one feature so it made sense to squash them.

👍 As someone who spends much of their day reviewing code, I completely agree. Having clear, concise commits makes code review so much easier.

Yes, the plan is to release 1.5.0 quite soon.

Great, thanks. I've made all of the changes I'd been considering, and v1.4.0 (plus my 3 PRs) is running well in production. So I wouldn't expect any more from me in the short term. Once v1.5.0 is released, I'll build and update my production server.

Thanks for smtprelay which fit my needs very nicely, and thanks for your quick and thorough review+merges!

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.

More flexible control over allowed user "from" address
2 participants