Skip to content

Commit d0d9805

Browse files
committed
MQE-1918: MFTF AWS Secrets Manager - Local Use
1 parent 579c96d commit d0d9805

File tree

6 files changed

+58
-58
lines changed

6 files changed

+58
-58
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Handlers\SecretStorage;
88

99
use Aws\SecretsManager\SecretsManagerClient;
10-
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\SecretStorage\AwsSecretManagerStorage;
10+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\SecretStorage\AwsSecretsManagerStorage;
1111
use Aws\Result;
1212
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
1313
use ReflectionClass;
1414

15-
class AwsSecretManagerStorageTest extends MagentoTestCase
15+
class AwsSecretsManagerStorageTest extends MagentoTestCase
1616
{
1717
/**
18-
* Test encryption/decryption functionality in AwsSecretManagerStorage class.
18+
* Test encryption/decryption functionality in AwsSecretsManagerStorage class.
1919
*/
2020
public function testEncryptAndDecrypt()
2121
{
@@ -44,7 +44,7 @@ public function testEncryptAndDecrypt()
4444
});
4545

4646
/** @var SecretsManagerClient */
47-
$credentialStorage = new AwsSecretManagerStorage($testRegion, $testProfile);
47+
$credentialStorage = new AwsSecretsManagerStorage($testRegion, $testProfile);
4848
$reflection = new ReflectionClass($credentialStorage);
4949
$reflection_property = $reflection->getProperty('client');
5050
$reflection_property->setAccessible(true);

docs/configuration.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,26 +277,26 @@ Example:
277277
CREDENTIAL_VAULT_SECRET_BASE_PATH=secret
278278
```
279279

280-
### CREDENTIAL_AWS_SECRET_MANAGER_REGION
280+
### CREDENTIAL_AWS_SECRETS_MANAGER_REGION
281281

282-
The region that Aws Secret Manager is located.
282+
The region that AWS Secrets Manager is located.
283283

284284
Example:
285285

286286
```conf
287-
# Region of Aws Secret Manager
288-
CREDENTIAL_AWS_SECRET_MANAGER_REGION=us-east-1
287+
# Region of AWS Secrets Manager
288+
CREDENTIAL_AWS_SECRETS_MANAGER_REGION=us-east-1
289289
```
290290

291-
### CREDENTIAL_AWS_SECRET_MANAGER_PROFILE
291+
### CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE
292292

293-
The profile used to connect to Aws Secret Manager.
293+
The profile used to connect to AWS Secrets Manager.
294294

295295
Example:
296296

297297
```conf
298-
# Profile used to connect to Aws Secret Manager.
299-
CREDENTIAL_AWS_SECRET_MANAGER_PROFILE=default
298+
# Profile used to connect to AWS Secrets Manager.
299+
CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE=default
300300
```
301301

302302
### ENABLE_BROWSER_LOG

docs/credentials.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Currently the MFTF supports three types of credential storage:
77

88
- **.credentials file**
99
- **HashiCorp Vault**
10-
- **Aws Secret Manager**
10+
- **AWS Secrets Manager**
1111

1212
## Configure File Storage
1313

@@ -136,22 +136,22 @@ CREDENTIAL_VAULT_ADDRESS=http://127.0.0.1:8200
136136
CREDENTIAL_VAULT_SECRET_BASE_PATH=secret
137137
```
138138

139-
## Configure Aws Secret Manager
139+
## Configure AWS Secrets Manager
140140

141-
Aws Secrets Manager offers secret management that supports:
141+
AWS Secrets Manager offers secret management that supports:
142142
- Secret rotation with built-in integration for Amazon RDS, Amazon Redshift, and Amazon DocumentDB
143143
- Fine-grained policies and permissions
144144
- Audit secret rotation centrally for resources in the AWS Cloud, third-party services, and on-premises
145145

146146
### Prerequisites
147147
- AWS account
148-
- AWS Secret Manger is created and configured
149-
- IAM User or Role is created
148+
- AWS Secrets Manger is created and configured
149+
- IAM User or Role is created with appropriate AWS Secrets Manger access permission
150150

151-
### Store secrets in Aws Secret Manager
151+
### Store secrets in AWS Secrets Manager
152152

153153
#### Secrets format
154-
`Secret Name`, `Secret Key`, `Secret Value` are three key pieces of information to construct an Aws Secret.
154+
`Secret Name`, `Secret Key`, `Secret Value` are three key pieces of information to construct an AWS Secret.
155155
`Secret Key` and `Secret Value` can be any content you want to secure, `Secret Name` must follow the format:
156156

157157
```conf
@@ -172,18 +172,18 @@ mftf/magento/carriers_usps_password
172172
carriers_usps_password
173173
```
174174

175-
### Setup MFTF to use Aws Secret Manager
175+
### Setup MFTF to use AWS Secrets Manager
176176

177-
To use Aws Secret Manager, the Aws region to connect to is required. You can set it through environment variable [`CREDENTIAL_AWS_SECRET_MANAGER_REGION`][] in `.env`.
177+
To use AWS Secrets Manager, the AWS region to connect to is required. You can set it through environment variable [`CREDENTIAL_AWS_SECRETS_MANAGER_REGION`][] in `.env`.
178178

179-
MFTF uses the recommended [Default Credential Provider Chain][credential chain] to establish connection to Aws Secret Manager service.
179+
MFTF uses the recommended [Default Credential Provider Chain][credential chain] to establish connection to AWS Secrets Manager service.
180180
You can setup credentials according to [Default Credential Provider Chain][credential chain] and there is no MFTF specific setup required.
181-
Optionally, however, you can explicitly set Aws profile through environment variable [`CREDENTIAL_AWS_SECRET_MANAGER_PROFILE`][] in `.env`.
181+
Optionally, however, you can explicitly set AWS profile through environment variable [`CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE`][] in `.env`.
182182

183183
```conf
184-
# Sample Aws Secret Manager configuration
185-
CREDENTIAL_AWS_SECRET_MANAGER_REGION=us-east-1
186-
CREDENTIAL_AWS_SECRET_MANAGER_PROFILE=default
184+
# Sample AWS Secrets Manager configuration
185+
CREDENTIAL_AWS_SECRETS_MANAGER_REGION=us-east-1
186+
CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE=default
187187
```
188188

189189
## Configure multiple credential storage
@@ -192,7 +192,7 @@ It is possible and sometimes useful to setup and use multiple credential storage
192192
In this case, the MFTF tests are able to read secret data at runtime from all storage options, in this case MFTF use the following precedence:
193193

194194
```
195-
.credentials File > HashiCorp Vault > Aws Secret Manager
195+
.credentials File > HashiCorp Vault > AWS Secrets Manager
196196
```
197197
<!-- {% raw %} -->
198198

@@ -238,5 +238,5 @@ The MFTF tests delivered with Magento application do not use credentials and do
238238
[`CREDENTIAL_VAULT_ADDRESS`]: configuration.md#credential_vault_address
239239
[`CREDENTIAL_VAULT_SECRET_BASE_PATH`]: configuration.md#credential_vault_secret_base_path
240240
[credential chain]: https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
241-
[`CREDENTIAL_AWS_SECRET_MANAGER_PROFILE`]: configuration.md#credential_aws_secret_manager_profile
242-
[`CREDENTIAL_AWS_SECRET_MANAGER_REGION`]: configuration.md#credential_aws_secret_manager_region
241+
[`CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE`]: configuration.md#credential_aws_secrets_manager_profile
242+
[`CREDENTIAL_AWS_SECRETS_MANAGER_REGION`]: configuration.md#credential_aws_secrets_manager_region

etc/config/.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ BROWSER=chrome
3434
#CREDENTIAL_VAULT_ADDRESS=http://127.0.0.1:8200
3535
#CREDENTIAL_VAULT_SECRET_BASE_PATH=secret
3636

37-
#*** To use AWS Secret Manager to manage _CREDS secrets, uncomment and set region, profile is optional, when omitted, AWS default credential provider chain will be used ***#
38-
#CREDENTIAL_AWS_SECRET_MANAGER_PROFILE=default
39-
#CREDENTIAL_AWS_SECRET_MANAGER_REGION=us-east-1
37+
#*** To use AWS Secrets Manager to manage _CREDS secrets, uncomment and set region, profile is optional, when omitted, AWS default credential provider chain will be used ***#
38+
#CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE=default
39+
#CREDENTIAL_AWS_SECRETS_MANAGER_REGION=us-east-1
4040

4141
#*** Uncomment these properties to set up a dev environment with symlinked projects ***#
4242
#TESTS_BP=

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/CredentialStore.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1010
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\SecretStorage\FileStorage;
1111
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\SecretStorage\VaultStorage;
12-
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\SecretStorage\AwsSecretManagerStorage;
12+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\SecretStorage\AwsSecretsManagerStorage;
1313
use Magento\FunctionalTestingFramework\Util\Path\UrlFormatter;
1414

1515
class CredentialStore
1616
{
1717
const ARRAY_KEY_FOR_VAULT = 'vault';
1818
const ARRAY_KEY_FOR_FILE = 'file';
19-
const ARRAY_KEY_FOR_AWS_SECRET_MANAGER = 'aws';
19+
const ARRAY_KEY_FOR_AWS_SECRETS_MANAGER = 'aws';
2020

2121
const CREDENTIAL_STORAGE_INFO = 'MFTF uses Credential Storage in the following precedence: '
22-
. '.credentials file, HashiCorp Vault and AWS Secret Manager. '
22+
. '.credentials file, HashiCorp Vault and AWS Secrets Manager. '
2323
. 'You need to configure at least one to use _CREDS in tests.';
2424

2525
/**
@@ -77,15 +77,15 @@ private function __construct()
7777
}
7878
}
7979

80-
// Initialize AWS secret manager storage
81-
$awsRegion = getenv('CREDENTIAL_AWS_SECRET_MANAGER_REGION');
82-
$awsProfile = getenv('CREDENTIAL_AWS_SECRET_MANAGER_PROFILE');
80+
// Initialize AWS Secrets Manager storage
81+
$awsRegion = getenv('CREDENTIAL_AWS_SECRETS_MANAGER_REGION');
82+
$awsProfile = getenv('CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE');
8383
if ($awsRegion !== false) {
8484
if ($awsProfile === false) {
8585
$awsProfile = null;
8686
}
8787
try {
88-
$this->credStorage[self::ARRAY_KEY_FOR_AWS_SECRET_MANAGER] = new AwsSecretManagerStorage(
88+
$this->credStorage[self::ARRAY_KEY_FOR_AWS_SECRETS_MANAGER] = new AwsSecretsManagerStorage(
8989
$awsRegion,
9090
$awsProfile
9191
);
@@ -109,8 +109,8 @@ private function __construct()
109109
*/
110110
public function getSecret($key)
111111
{
112-
// Get secret data from storage according to the order they are stored
113-
// File storage is preferred over vault storage to allow local secret value overriding remote secret value
112+
// Get secret data from storage according to the order they are stored which follows this precedence:
113+
// FileStorage > VaultStorage > AwsSecretsManagerStorage
114114
foreach ($this->credStorage as $storage) {
115115
$value = $storage->getEncryptedValue($key);
116116
if (null !== $value) {
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
use InvalidArgumentException;
1616
use Exception;
1717

18-
class AwsSecretManagerStorage extends BaseStorage
18+
class AwsSecretsManagerStorage extends BaseStorage
1919
{
2020
/**
2121
* Mftf project path
2222
*/
2323
const MFTF_PATH = 'mftf';
2424

2525
/**
26-
* AWS Secret Manager version
26+
* AWS Secrets Manager version
2727
*
2828
* Last tested version '2017-10-17'
2929
*/
@@ -37,7 +37,7 @@ class AwsSecretManagerStorage extends BaseStorage
3737
private $client = null;
3838

3939
/**
40-
* AwsSecretManagerStorage constructor
40+
* AwsSecretsManagerStorage constructor
4141
*
4242
* @param string $region
4343
* @param string $profile
@@ -47,7 +47,7 @@ class AwsSecretManagerStorage extends BaseStorage
4747
public function __construct($region, $profile = null)
4848
{
4949
parent::__construct();
50-
$this->createAwsSecretManagerClient($region, $profile);
50+
$this->createAwsSecretsManagerClient($region, $profile);
5151
}
5252

5353
/**
@@ -65,8 +65,8 @@ public function getEncryptedValue($key)
6565
}
6666

6767
if (MftfApplicationConfig::getConfig()->verboseEnabled()) {
68-
LoggingUtil::getInstance()->getLogger(VaultStorage::class)->debug(
69-
"Retrieving secret for key name {$key} from AWS Secret Manager"
68+
LoggingUtil::getInstance()->getLogger(AwsSecretsManagerStorage::class)->debug(
69+
"Retrieving value for key name {$key} from AWS Secrets Manager"
7070
);
7171
}
7272

@@ -79,7 +79,7 @@ public function getEncryptedValue($key)
7979
. $vendor
8080
. '/'
8181
. $key;
82-
// Read value by id from AWS Secret Manager, and parse the result
82+
// Read value by id from AWS Secrets Manager, and parse the result
8383
$value = $this->parseAwsSecretResult(
8484
$this->client->getSecretValue(['SecretId' => $secretId]),
8585
$key
@@ -90,14 +90,14 @@ public function getEncryptedValue($key)
9090
} catch (AwsException $e) {
9191
$error = $e->getAwsErrorCode();
9292
if (MftfApplicationConfig::getConfig()->verboseEnabled()) {
93-
LoggingUtil::getInstance()->getLogger(VaultStorage::class)->debug(
94-
"AWS error code: {$error}. Unable to read secret for key {$key} from AWS Secret Manager"
93+
LoggingUtil::getInstance()->getLogger(AwsSecretsManagerStorage::class)->debug(
94+
"AWS error code: {$error}. Unable to read value for key {$key} from AWS Secrets Manager"
9595
);
9696
}
9797
} catch (\Exception $e) {
9898
if (MftfApplicationConfig::getConfig()->verboseEnabled()) {
99-
LoggingUtil::getInstance()->getLogger(VaultStorage::class)->debug(
100-
"Unable to read secret for key {$key} from AWS Secret Manager"
99+
LoggingUtil::getInstance()->getLogger(AwsSecretsManagerStorage::class)->debug(
100+
"Unable to read value for key {$key} from AWS Secrets Manager"
101101
);
102102
}
103103
}
@@ -118,39 +118,39 @@ private function parseAwsSecretResult($awsResult, $key)
118118
if (isset($awsResult['SecretString'])) {
119119
$rawSecret = $awsResult['SecretString'];
120120
} else {
121-
throw new TestFrameworkException("Error parsing AWS secret result");
121+
throw new TestFrameworkException("Error parsing result from AWS Secrets Manager");
122122
}
123123
$secret = json_decode($rawSecret, true);
124124
if (isset($secret[$key])) {
125125
return $secret[$key];
126126
}
127-
throw new TestFrameworkException("Error parsing AWS secret result");
127+
throw new TestFrameworkException("Error parsing result from AWS Secrets Manager");
128128
}
129129

130130
/**
131-
* Create Aws Secret Manager client
131+
* Create Aws Secrets Manager client
132132
*
133133
* @param string $region
134134
* @param string $profile
135135
* @return void
136136
* @throws TestFrameworkException
137137
* @throws InvalidArgumentException
138138
*/
139-
private function createAwsSecretManagerClient($region, $profile)
139+
private function createAwsSecretsManagerClient($region, $profile)
140140
{
141141
if (null !== $this->client) {
142142
return;
143143
}
144144

145-
// Create AWS Secret Manager client
145+
// Create AWS Secrets Manager client
146146
$this->client = new SecretsManagerClient([
147147
'profile' => $profile,
148148
'region' => $region,
149149
'version' => self::LATEST_VERSION
150150
]);
151151

152152
if ($this->client === null) {
153-
throw new TestFrameworkException("Unable to create AWS Secret Manager client");
153+
throw new TestFrameworkException("Unable to create AWS Secrets Manager client");
154154
}
155155
}
156156
}

0 commit comments

Comments
 (0)