elementor / elementor/static-html-output
Allow usage of the defaultProvider() CredentialProvider for S3
- Dominant language
- PHP
- Stars
- 128
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Description
https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.Credentials.CredentialProvider.html
Currently the plugin requires the usage of an IAM Access Key and Secret Access Key to be provided in order to authenticate to S3 to upload. This is not industry best practice. The default `CredentialProvider` attempts to load credentials in the following order:
1. Check for environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN `
2. Check for a **default** profile in `~/.aws/credentials`
3. Check for **default** profile in `~/.aws/config`
4. Make GET request to ECS environment variables (only if using Elastic Container Service)
5. Checks for credentials using an External Process: https://docs.aws.amazon.com/cli/latest/topic/config-vars.html#sourcing-credentials-from-external-processes
6. Check for EC2 instance profile credentials using the local metadata endpoint of 169.254.169.254
7. It finally uses the `'credentials' => ['key' => 'my-access-key-id', 'secret' => 'my-secret-access-key']` configuration of the client constructor given that no other credentials are found.
We configure the majority of our sensitive site configuration using either Environment Variables or IAM Roles assigned to EC2 instances, utilizing the EC2 instance metadata (option 6 above).
Here is an implementation that would use the key and secret, if provided, and otherwise revert to the default order of operations:
```php
use Aws\Credentials\CredentialProvider;
use Aws\Credentials;
$credentialProvider = CredentialProvider::memoize(
CredentialProvider::chain(
CredentialProvider::fromCredentials(new Credentials($key ?? '', $secret ?? '')),
CredentialProvider::defaultProvider()
)
);
$s3Client = new S3Client([
'region' => $region,
'version' => 'latest',
'credentials' => $credentialProvider
]);
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.