You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/03/29 18:42:53 UTC
[GitHub] [airflow] dimberman opened a new issue #7986: SMTP Mail delivery
fails with server using CRAM-MD5 auth
dimberman opened a new issue #7986: SMTP Mail delivery fails with server using CRAM-MD5 auth
URL: https://github.com/apache/airflow/issues/7986
Ticket was created 03/Feb/17 18:09
**Description**
Traceback when sending email from smtp-server configured to offer CRAM-MD5 (in all cases, tls included). This occurs because the configuration module returns the password as a futures.types.newstr, instead of a plain str (see below for gory details of why this breaks).
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/airflow/models.py", line 1308, in handle_failure
self.email_alert(error, is_retry=False)
File "/usr/local/lib/python2.7/site-packages/airflow/models.py", line 1425, in email_alert
send_email(task.email, title, body)
File "/usr/local/lib/python2.7/site-packages/airflow/utils/email.py", line 43, in send_email
return backend(to, subject, html_content, files=files, dryrun=dryrun)
File "/usr/local/lib/python2.7/site-packages/airflow/utils/email.py", line 79, in send_email_smtp
send_MIME_email(SMTP_MAIL_FROM, to, msg, dryrun)
File "/usr/local/lib/python2.7/site-packages/airflow/utils/email.py", line 95, in send_MIME_email
s.login(SMTP_USER, SMTP_PASSWORD)
File "/usr/local/lib/python2.7/smtplib.py", line 607, in login
(code, resp) = self.docmd(encode_cram_md5(resp, user, password))
File "/usr/local/lib/python2.7/smtplib.py", line 571, in encode_cram_md5
response = user + " " + hmac.HMAC(password, challenge).hexdigest()
File "/usr/local/lib/python2.7/hmac.py", line 75, in _init_
self.outer.update(key.translate(trans_5C))
File "/usr/local/lib/python2.7/site-packages/future/types/newstr.py", line 390, in translate
if ord(c) in table:
TypeError: 'in <string>' requires string as left operand, not int
SMTP configs:
[email]
email_backend = airflow.utils.email.send_email_smtp
[smtp]
smtp_host =
{a_smtp_server}
smtp_port = 587
smtp_starttls = True
smtp_ssl = False
smtp_user =
{a_username}
smtp_password =
{a_password}
smtp_mail_from =
{a_email_addr}
*Gory details
If the server offers CRAM-MD5, smptlib prefers this by default, and will try to use hmac.HMAC to hash the password:
https://hg.python.org/cpython/file/2.7/Lib/smtplib.py#l602
https://hg.python.org/cpython/file/2.7/Lib/smtplib.py#l571
But if the password is a newstr, newstr.translate expects a dict mapping instead of str, and raises an exception.
https://hg.python.org/cpython/file/2.7/Lib/hmac.py#l75
All of this occurs after a successful SMTP.ehlo(), so it's probably not crap container networking
Could be resolved by passing the smtp password as a futures.types.newbytes, as this behaves as expected:
from future.types import newstr, newbytes
import hmac
Make str / newstr types
test = 'a_string'
test_newstr = newstr(test)
test_newbytes = newbytes(test)
msg = 'future problems'
Test 1 - Try to do a HMAC:
fine
hmac.HMAC(test, msg)
fails horribly
hmac.HMAC(test_newstr, msg)
is completely fine
hmac.HMAC(test_newbytes, msg)
**Use case / motivation**
**Related Issues**
Moved here from https://issues.apache.org/jira/browse/AIRFLOW-835
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services