Skip to content

Make email publishing work, when access-control is enabled #621

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

Conversation

tamcore
Copy link
Contributor

@tamcore tamcore commented Feb 19, 2023

This will fix #420, by allowing emails in the format ${prefix}-${topic}+${token}@${host}, so the user can pass a token with write-permissions to the defined topic.

A container image to test it with is available via ghcr.io/tamcore/ntfy:v2.0.1@sha256:e6616f3531f9960da1f0ea918feb73faa8ffa0794a58d0d606eb131f911a7650


Tests

Without token

root@ubuntu:/# cat << EOC | nc -N ntfy.ntfy.svc.cluster.local 2525
> EHLO example.com
> MAIL FROM: phil@example.com
> RCPT TO: ntfy-mytopic@ntfy.ntfy.svc.cluster.local
> DATA
> Subject: Email for you
> Content-Type: text/plain; charset="UTF-8"
>
> Hello from 🇩🇪
> .
> EOC
220 ntfy.ntfy.svc.cluster.local ESMTP Service Ready
250-Hello example.com
250-PIPELINING
250-8BITMIME
250-ENHANCEDSTATUSCODES
250-CHUNKING
250-AUTH PLAIN
250 SIZE 1048576
250 2.0.0 Roger, accepting mail from <phil@example.com>
250 2.0.0 I'll make sure <ntfy-mytopic@ntfy.ntfy.svc.cluster.local> gets this
354 2.0.0 Go ahead. End your data with <CR><LF>.<CR><LF>
554 5.0.0 Error: transaction failed, blame it on the weather: error: {"code":40301,"http":403,"error":"forbidden","link":"https://ntfy.sh/docs/publish/#authentication"}

With invalid token

root@ubuntu:/# cat << EOC | nc -N ntfy.ntfy.svc.cluster.local 2525
> EHLO example.com
> MAIL FROM: phil@example.com
> RCPT TO: ntfy-mytopic+tk_invalidtoken@ntfy.ntfy.svc.cluster.local
> DATA
> Subject: Email for you
> Content-Type: text/plain; charset="UTF-8"
>
> Hello from 🇩🇪
> .
> EOC
220 ntfy.ntfy.svc.cluster.local ESMTP Service Ready
250-Hello example.com
250-PIPELINING
250-8BITMIME
250-ENHANCEDSTATUSCODES
250-CHUNKING
250-AUTH PLAIN
250 SIZE 1048576
250 2.0.0 Roger, accepting mail from <phil@example.com>
250 2.0.0 I'll make sure <ntfy-mytopic+tk_invalidtoken@ntfy.ntfy.svc.cluster.local> gets this
354 2.0.0 Go ahead. End your data with <CR><LF>.<CR><LF>
554 5.0.0 Error: transaction failed, blame it on the weather: error: {"code":40101,"http":401,"error":"unauthorized","link":"https://ntfy.sh/docs/publish/#authentication"}

With valid token

root@ubuntu:/# cat << EOC | nc -N ntfy.ntfy.svc.cluster.local 2525
> EHLO example.com
> MAIL FROM: phil@example.com
> RCPT TO: ntfy-mytopic+tk_JhbsnoMrgy2FcfHeofv97Pi5uXaZZ@ntfy.ntfy.svc.cluster.local
> DATA
> Subject: Email for you
> Content-Type: text/plain; charset="UTF-8"
>
> Hello from 🇩🇪
> .
> EOC
220 ntfy.ntfy.svc.cluster.local ESMTP Service Ready
250-Hello example.com
250-PIPELINING
250-8BITMIME
250-ENHANCEDSTATUSCODES
250-CHUNKING
250-AUTH PLAIN
250 SIZE 1048576
250 2.0.0 Roger, accepting mail from <phil@example.com>
250 2.0.0 I'll make sure <ntfy-mytopic+tk_JhbsnoMrgy2FcfHeofv97Pi5uXaZZ@ntfy.ntfy.svc.cluster.local> gets this
354 2.0.0 Go ahead. End your data with <CR><LF>.<CR><LF>
250 2.0.0 OK: queued

@tamcore tamcore force-pushed the feature/email-with-access-control branch from 7643765 to 8e3fc9d Compare February 19, 2023 18:22
Copy link
Owner

@binwiederhier binwiederhier 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 fantastic. Could you add a unit test for this?

@tamcore tamcore force-pushed the feature/email-with-access-control branch from 8e3fc9d to 8c57a66 Compare February 20, 2023 07:00
@tamcore
Copy link
Contributor Author

tamcore commented Feb 20, 2023

Could you add a unit test for this?

Unfortunately struggling a bit with this bit, as i can't figure out how to mock the full app with enabled ACLs, so i can test for valid/invalid token. If ACL is disabled, it doesn't seem to care about the presence of a valid/invalid token.

@binwiederhier
Copy link
Owner

I don't think you need to do a full end to end test with this. Just one like the other SMTP tests. Just make sure that the auth header with the token gets to the handler function. Like in the other SMTP tests.

@tamcore tamcore force-pushed the feature/email-with-access-control branch from 8c57a66 to e892b99 Compare February 20, 2023 11:46
@tamcore
Copy link
Contributor Author

tamcore commented Feb 20, 2023

Gotcha! PR updated :)

@binwiederhier
Copy link
Owner

Looks fantastic. Thanks for your contribution!

@binwiederhier binwiederhier merged commit 33e7537 into binwiederhier:main Feb 20, 2023
@chrisjameschamp
Copy link

This is not working for me on 2.1.1

I get "Unrouteable address" error when attaching my token and without it I get a 403 error

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.

E-mail publishing with access-control enabled
3 participants