Skip to content

Mailgun: Separate configuration of "Private API key" vs. "HTTP webhook signing key" [after Mailgun key rotation] #153

@dominik-lekse

Description

@dominik-lekse

Description

  • I currently evaluate Anymail in my Django project to integrate with Mailgun to be able to process inbound mails via Mailgun routes and the webhook of Anymail and to send mails via Mailgun.
  • The Mailgun API security distinguishes between a "Private API key" and a "HTTP webhook signing key" which are different.
  • According to the Anymail documentation, the Mailgun ESP needs to be provided the ANYMAIL_MAILGUN_API_KEY setting which takes the Mailgun "Private API key".
  • However, if ANYMAIL_MAILGUN_API_KEY is the "Private API key", the verification of inbound mail via the webhook fails
  • Webhook HTTP requests from Mailgun are signed with the "HTTP webhook signing key"

Proposal

  • Define a new setting ANYMAIL_MAILGUN_SIGNING_KEY which must be configured with the "HTTP webhook signing key" when using the inbound mail functionality
  • MailgunBaseWebhookView should take the key to verify the signature from ANYMAIL_MAILGUN_SIGNING_KEY

(Kind of) workaround

  • Depending on which API key is provided to ANYMAIL_MAILGUN_API_KEY, either inbound mails from Mailgun ESP or send mails via Mailgun ESP works, but not both
  • To allow inbound mails, set ANYMAIL_MAILGUN_API_KEY to the "HTTP webhook signing key"
  • To allow sending mails, set ANYMAIL_MAILGUN_API_KEY to the "Private API key"

Some notes

  • Before opening this issue, I have carefully scanned the Anymail documentation but was not able to find a hint
  • I have rotated all Mailgun keys at least once

Environment

  • Python 3.7.3
  • Anymail version: 6.0.1
  • ESP: Mailgun

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions