-
Notifications
You must be signed in to change notification settings - Fork 2
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
Added code to derive SES SMTP password from existing AWS API keys #348
Conversation
@@ -155,7 +155,38 @@ | |||
$config['smtp.settings']['smtp_allowhtml'] = 1; | |||
|
|||
// @see baywatch.module for SMTP_REPLYTO setting. | |||
$config['system.site']['mail'] = getenv('SMTP_FROM') ?: '[email protected]'; | |||
$config['system.site']['mail'] = getenv('SMTP_FROM') ?: sprintf("%s.%[email protected]", getenv('LAGOON_ENVIRONMENT'), getenv('LAGOON_PROJECT')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sets the default FROM address to [env].[project]@sdp.delivery
. This should be overridden in prod.
if (empty($config['smtp.settings']['smtp_password']) && | ||
str_contains($config['smtp.settings']['smtp_host'], "amazonaws.com")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only enter this block if SMTP_PASSWORD
is empty, and the host points to SES.
$config['smtp.settings']['smtp_password'] = (function(string $region, string $awsSecretAccessKey): string { | ||
// Adapted from AWS SDK. | ||
// @see https://github.com/aws/aws-sdk-php/blob/a63e79c15a972c54bf015a16cce3f3572e0c8221/src/Ses/SesClient.php#L195 | ||
$date = "11111111"; | ||
$service = "ses"; | ||
$terminal = "aws4_request"; | ||
$message = "SendRawEmail"; | ||
$version = 0x04; | ||
|
||
$signature = hash_hmac('sha256', $date, "AWS4" . $awsSecretAccessKey, true); | ||
$signature = hash_hmac('sha256', $region, $signature, true); | ||
$signature = hash_hmac('sha256', $service, $signature, true); | ||
$signature = hash_hmac('sha256', $terminal, $signature, true); | ||
$signature = hash_hmac('sha256', $message, $signature, true); | ||
$signatureAndVersion = pack('c', $version) . $signature; | ||
|
||
return base64_encode($signatureAndVersion); | ||
})($region, $aws_key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with a closure to prevent the function scope vars leaking out into the rest of settings.php
$signatureAndVersion = pack('c', $version) . $signature; | ||
|
||
return base64_encode($signatureAndVersion); | ||
})($region, $aws_key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this passing $region
and $aws_key
out to the parent scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this is passing those vars into the function.
To include parent scope vars the use ($region, $aws_key)
syntax is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are the vars set?
SES can not use the AWS_SECRET_ACCESS_KEY directly via the SMTP interfaces.
Changes
Sets default values for
SMTP_USERNAME
andSMTP_PASSWORD
when none set, and AWS credentials are available.