I am using AWS Simple Email Service (SES), however I want to have a very tightly restricted policy.
I want to set up a policy to
- only be able to send emails to a domain (mydomain)
- from a specific ([email protected]) email address
- using a specific configuration set (internalonly)
I have tried the entry below, but it is not restricting the recipients. I cant see what Im doing wrongly.
Ive been chewing this one for a few days, and need some help. Can anyone point me in the right direction?
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ses:SendRawEmail",
"Resource": "arn:aws:ses:eu-west-1:999999999:identity/[email protected]",
"Condition": {
"StringLike": {
"ses:FromAddress": "[email protected]"
},
"ForAllValues:StringLike": {
"ses:Recipients": "*@mydomain.com"
}
}
},
{
"Effect": "Allow",
"Action": "ses:SendRawEmail",
"Resource": "arn:aws:ses:eu-west-1:99999999999:configuration-set/internalonly",
"Condition": {
"StringLike": {
"ses:FromAddress": "[email protected]"
},
"ForAllValues:StringLike": {
"ses:Recipients": "*@mydomain.com"
}
}
}
]
}
Following applying the policy, I tested this using the details here: https://docs.aws.amazon.com/ses/latest/dg/send-email-smtp-client-command-line.html
Sample test file ses-internal.txt
EHLO mydomain.com
AUTH LOGIN
Base64EncodedSMTPUserName
Base64EncodedSMTPPassword
MAIL FROM: [email protected]
RCPT TO: [email protected]
DATA
X-SES-CONFIGURATION-SET: internalonly
From: PM Access <[email protected]>
To: [email protected]
Subject: Amazon SES SMTP Test to luke
This message was sent using the Amazon SES SMTP interface.
.
QUIT
Testing: works when it should prevent me sending to [email protected]
% openssl s_client -crlf -quiet -starttls smtp -connect email-smtp.<region>.amazonaws.com:587 < ses-internal.txt
depth=4 C = US, O = "Starfield Technologies, Inc.", OU = Starfield Class 2 Certification Authority
verify return:1
depth=3 C = US, ST = Arizona, L = Scottsdale, O = "Starfield Technologies, Inc.", CN = Starfield Services Root Certificate Authority - G2
verify return:1
depth=2 C = US, O = Amazon, CN = Amazon Root CA 1
verify return:1
depth=1 C = US, O = Amazon, OU = Server CA 1B, CN = Amazon
verify return:1
depth=0 CN = email-smtp.<region>.amazonaws.com
verify return:1
250 Ok
250-email-smtp.amazonaws.com
250-8BITMIME
250-STARTTLS
250-AUTH PLAIN LOGIN
250 Ok
334 VXNlcm5hbWU6
334 UGFzc3dvcmQ6
235 Authentication successful.
250 Ok
250 Ok
354 End data with <CR><LF>.<CR><LF>
250 Ok 01020184133e8041-ba607190-5bf0-4610-9280-bbc38b9cb074-000000
451 4.4.2 Timeout waiting for data from client.
2
Answers
Many thanks for the suggestion @baduker
More reading and I found the mistake. A) The "ses:Recipients" should be an array B) The test file I was using has a schoolboy SMTP error in it. The To: field is documentary, the RCPT TO: field is the real recipient.
Here is the complete solution
Could you give this policy a try and see if the recipients are getting restricted?
Also, please note that to use a configuration set when sending an email, you must pass the name of the configuration set in the headers of the email.