Skip to content

[5.6] Allowing IAM role SESSION_TOKEN to be used with SES#23766

Merged
taylorotwell merged 1 commit into
laravel:5.6from
footballencarta:5.6
Apr 9, 2018
Merged

[5.6] Allowing IAM role SESSION_TOKEN to be used with SES#23766
taylorotwell merged 1 commit into
laravel:5.6from
footballencarta:5.6

Conversation

@footballencarta

Copy link
Copy Markdown
Contributor

By default, the SES driver allows for the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to be passed to the SES driver - however for instances using an IAM role, rather than these credentials in the .env file, sending an email will fail with an invalid Session Token error.

This change adds the token attribute in to allow for the AWS_SESSION_TOKEN to be passed in. Config would look something like:

return [
    'ses' => [
        'key'    => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'token'  => env('AWS_SESSION_TOKEN'),
        'region' => env('AWS_REGION', 'eu-west-1'),  // e.g. us-east-1
    ],
];

If the token does not exist, or if the request does not rely on one, this option is safely ignored as the AWS SDK gracefully ignores it (and uses null as default).

@AdamKernig

Copy link
Copy Markdown

Omg +1 this is needed, i was recently doing some work with this and took me ages to figure out why it was breaking. Absolutely need this!

+1+1+1

{
if ($config['key'] && $config['secret']) {
$config['credentials'] = Arr::only($config, ['key', 'secret']);
$config['credentials'] = Arr::only($config, ['key', 'secret', 'token']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if token is not defined in the array at this point? Does Arr::only() handle that gracefully?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping.

@footballencarta footballencarta Apr 3, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've been away for the last couple of days for Easter.

From looking at the Arr::only function, all it does is an intersection:

return array_intersect_key($array, array_flip((array) $keys));

So, running that through PHP with all 3 gives:

image

Just having 'key' and 'secret' in the config gives:

image

So it handles the lack of the token gracefully based off the source code.

I can check with the actual code tonight once I've finished work, however based off the check now, it's handled gracefully.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm it has no effect on existing functionality. Our current local development environment for the given project only contains key and secret, yet our live servers with the above change contain key, secret and token, and both send emails as expected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any progress on this guys?

@AdamKernig

Copy link
Copy Markdown

Ping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants