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

Debug and create test for datagov-smtp broker #3810

Closed
5 tasks done
nickumia-reisys opened this issue May 4, 2022 · 8 comments
Closed
5 tasks done

Debug and create test for datagov-smtp broker #3810

nickumia-reisys opened this issue May 4, 2022 · 8 comments
Assignees
Labels

Comments

@nickumia-reisys
Copy link
Contributor

nickumia-reisys commented May 4, 2022

datagov-brokerpak-smtp @ main

How to reproduce

  1. Create a datagov-smtp service
  2. Bind service to catalog main app
  3. Configure CKAN with smtp credentials
  4. Perform action that would send email (e.g. harvesting)
  5. Wait for email to be generated

Expected behavior

Email sent to desired recipient

Actual behavior

 2022-05-03T21:09:30.89-0400 [APP/TASK/harvester/0] ERR 2022-05-04 01:09:30,896 ERROR [ckan.lib.mailer] SMTPDataError(554, b"Access denied: User `arn:aws:iam::821341638715:user/cf/ses-b7a1cd34ddf3b0cf-csb--e3a67950-0aa6-4cb0-b272-76cfcf93cb8a' is not authorized to perform `ses:SendRawEmail' on resource `arn:aws:ses:us-west-2:821341638715:identity/aaron.borden@gsa.gov'")
   2022-05-03T21:09:30.89-0400 [APP/TASK/harvester/0] ERR Traceback (most recent call last):
   2022-05-03T21:09:30.89-0400 [APP/TASK/harvester/0] ERR File "/home/vcap/deps/1/python/lib/python3.7/site-packages/ckan/lib/mailer.py", line 107, in _mail_recipient
   2022-05-03T21:09:30.89-0400 [APP/TASK/harvester/0] ERR smtp_connection.sendmail(mail_from, [recipient_email], msg.as_string())
   2022-05-03T21:09:30.89-0400 [APP/TASK/harvester/0] ERR File "/home/vcap/deps/1/python/lib/python3.7/smtplib.py", line 893, in sendmail
   2022-05-03T21:09:30.89-0400 [APP/TASK/harvester/0] ERR raise SMTPDataError(code, resp)
   2022-05-03T21:09:30.89-0400 [APP/TASK/harvester/0] ERR smtplib.SMTPDataError: (554, b"Access denied: User `arn:aws:iam::821341638715:user/cf/ses-b7a1cd34ddf3b0cf-csb--e3a67950-0aa6-4cb0-b272-76cfcf93cb8a' is not authorized to perform `ses:SendRawEmail' on resource `arn:aws:ses:us-west-2:821341638715:identity/aaron.borden@gsa.gov'")

Sketch

  • Investigate where Aaron's email is set
  • Untie smtp brokerpak from his account (since his account is probably deactivated)
  • Create a manual test in smtp brokerpak to see if it can send email
  • Promote AWS SES Account from Sandbox to Production
  • Push and release updates
@nickumia-reisys nickumia-reisys added the bug Software defect or bug label May 4, 2022
@nickumia-reisys nickumia-reisys self-assigned this May 4, 2022
@nickumia-reisys
Copy link
Contributor Author

Verified in the AWS Console, the SES instance was verified,

image

@nickumia-reisys
Copy link
Contributor Author

Ohhhh, I think I found the problem.. I think we should be doing this,

{
  "Version":"2012-10-17",
  "Statement":[
    {
      "Effect":"Allow",
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Resource":"*"
    }
  ]
}

Instead of doing this,

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Resource": "${var.domain_arn}"
    }
  ]
}

The second one restricts sending emails only to itself as opposed to, to anywhere.

@nickumia-reisys
Copy link
Contributor Author

nickumia-reisys commented May 4, 2022

Okay.. well... there's a few steps that need to happen here,

  • Promote our SES Account to production from sandbox to be able to send real emails to external accounts
  • This PR needs to be reviewed and merged to be able to send emails to anyone, instead of just to itself.
    • I'm writing a test to manually send an email.

My script will continue to fail with Email Address not verified until our SES Account is promoted to production,
image

This blocker is described here and I think requires a government person to be involved.

@nickumia-reisys
Copy link
Contributor Author

The original error was trying to send an email to aaron's email, not use aaron's email to do something.

@nickumia-reisys
Copy link
Contributor Author

Proof that sending emails works 😄

image

image

@mogul
Copy link
Contributor

mogul commented May 4, 2022

Ohhhh, I think I found the problem.. I think we should be doing this,

{
  "Version":"2012-10-17",
  "Statement":[
    {
      "Effect":"Allow",
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Resource":"*"
    }
  ]
}

Instead of doing this,

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Resource": "${var.domain_arn}"
    }
  ]
}

The second one restricts sending emails only to itself as opposed to, to anywhere.

I don't think that's what is happening here... Restricting to just a particular target address looks different.

@mogul
Copy link
Contributor

mogul commented May 4, 2022

See also how the word "Resource" is applied here... It refers to the SES identity being used for sending, not the recipient.

image

Here's a list of brokered SES identities:
image

If you make the resource * instead of ${var.domain_arn} then you are saying that credentials brokered for one service instance can also be used to send from the identity associated with another instance. Definitely not what we want!

nickumia-reisys added a commit to GSA-TTS/datagov-brokerpak-smtp that referenced this issue May 4, 2022
@nickumia-reisys
Copy link
Contributor Author

Summary of work:

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

No branches or pull requests

2 participants