-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] added Instance Profile support to SES Transport of Mailer #33326
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
Conversation
src/Symfony/Component/Mailer/Bridge/Amazon/Credential/ApiTokenCredential.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Mailer/Bridge/Amazon/Credential/ApiTokenCredential.php
Outdated
Show resolved
Hide resolved
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.
Great work! Can you also add a note in the CHANGELOG of the component about the BC break?
src/Symfony/Component/Mailer/Bridge/Amazon/Credential/ApiTokenCredential.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Mailer/Bridge/Amazon/Credential/InstanceCredentialProvider.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesTransportFactory.php
Show resolved
Hide resolved
src/Symfony/Component/Mailer/Bridge/Amazon/Credential/InstanceCredentialProvider.php
Outdated
Show resolved
Hide resolved
|
||
$instanceMetadataServerURL = $this->getInstanceMetadataServerURL($roleName); | ||
|
||
while (true) { |
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.
Why do we try several times?
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.
The amazon sdk does the same. I guess connecting to the 169.254.169.254 IP sometime may temporary fail, so thats why I did keep the same logic.
src/Symfony/Component/Mailer/Bridge/Amazon/Credential/InstanceCredentialProvider.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Mailer/Bridge/Amazon/Credential/InstanceCredentialProvider.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Mailer/Bridge/Amazon/Credential/UsernamePasswordCredential.php
Outdated
Show resolved
Hide resolved
This feature must target 4.4 branch please |
src/Symfony/Component/Mailer/Bridge/Amazon/Credential/ApiTokenCredential.php
Outdated
Show resolved
Hide resolved
@connorhu As noticed by fabbot, you should rebase to get rid of the merge commits. And you should rebase on 4.4 instead of master. The current situation is a bit special as we are working on 2 versions in parallel: 4.4 and 5.0/master. |
src/Symfony/Component/Mailer/Bridge/Amazon/Credential/UsernamePasswordCredential.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Mailer/Bridge/Amazon/Transport/RequestSignTrait.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiTransport.php
Show resolved
Hide resolved
} | ||
|
||
if ('smtp' === $scheme || 'smtps' === $scheme) { | ||
return new SesSmtpTransport($user, $password, $region, $this->dispatcher, $this->logger); | ||
return new SesSmtpTransport($credential, $region, $this->dispatcher, $this->logger); |
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.
what if an ApiTokenCredential was instantiated and we reach this point ?
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.
@stof I think the supported credential type(s) should be checked by the Transport instance.
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.
@stof SesSmtpTransport only works with UsernamePasswordCredential (as you can see at the first parameter of the constructor). DX would be better if we check the class and throw an exception with a better message than a native type exception.
@fabpot Ok. When I started to work on this I didn't know the right branch because of the complexity of the work (eg BC BREAK) |
We can break BC here as the component was marked as experimental in 4.3. That eases things a lot :) |
(this should target branch 4.4) |
src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesHttpTransport.php
Show resolved
Hide resolved
|
||
$this->client = HttpClient::create(); | ||
} else { | ||
$this->client = $client; |
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.
Nitpicking mode on: no need for an else here. Simply do $this->client = $client
above where you assign retries. Then check if $this->client
is null instead of $client
and you can remove the if.
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.
@mdeboer I can remove the else, but you're right.
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.
Sorry yeah, I meant the else hehe 😜 Blame the heatwave..
@connorhu I'm going to rebase on 4.4 this PR. |
@connorhu It's a bit more difficult than expected due to the recent changes in the code. Can you have a look? I think the |
@fabpot What would be the right abstraction instead of |
@connorhu Not sure yet. I let you rebase and I think you will understand what I mean. Some logic in |
@fabpot Ok then. I will do the rebase. |
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.
The AWS SDK provides many way to authenticate (some of theme are really simple), What's about implementing the most used and chaining theme (in the same way SDK does) ?
I think about AWS config File, official AWS_ENV vars and "assumed role with web identity" (the last one is used when using EKS(K8S) and allocating a ROLE to a ServiceAccount)
$credentialProvider = new ChainCredentialProvider([
new UserPassProvider($user, $password),
new EnvVarProvider(),
new ConfigFileProvider(),
new RoleProvider(),
new OidcProvider(),
]);
throw new LogicException(sprintf('You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".', __CLASS__)); | ||
} | ||
|
||
$this->client = HttpClient::create(); |
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.
I think the default timeout is 1.0s
in official SDK
} catch (IncompleteDsnException $e) { | ||
$role = $dsn->getOption('role'); | ||
|
||
if (null === $role) { |
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.
role is not needed. In official AWS SDK, the role is fetched from instance metadata. (see InstanceProfileProvider)
Closing in favor of #35992 |
This PR was squashed before being merged into the 5.1-dev branch. Discussion ---------- [Mailer] Use AsyncAws to handle SES requests | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #33183, #35468 and #35037 | License | MIT | Doc PR | TODO alternative to #33326 This PR replace the native code to call AWS SES by the new [AsyncAws](https://github.com/async-aws/aws) project maintained by @Nyholm and me. This removes complexity of signing request, and adds new features likes: - authentication via .aws/config.ini, Instance profile, WebIdentity (K8S service account) - usesignature V4 (the one recommanded by the Official SDK ) - fully compatible with API (uses the official AWS SDK interface contract to generate classes) Because it's based on `symfony/http-client`, it's fully integrable with Symfony application. Commits ------- 2124387 [Mailer] Use AsyncAws to handle SES requests
This PR adds Instance Profile support to SES API and Http Transport of Mailer component.
Things to do:
The token expiry is an unhandled situation. But I'm not sure that the Transport part of the Mailer component can support transport renew.