Skip to content

Commit f9baa07

Browse files
committed
MQE-1647:  read vault token from local file system
- allow secret base path configurable
1 parent 3304dca commit f9baa07

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

etc/config/.env.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ BROWSER=chrome
3030
#MAGENTO_RESTAPI_SERVER_PORT=8080
3131
#MAGENTO_RESTAPI_SERVER_PROTOCOL=https
3232

33-
#*** Uncomment and set vault base url and access token if you want to use vault to manage _CREDS secrets ***#
34-
#CREDENTIAL_VAULT_BASE_URL=
33+
#*** Uncomment and set vault address and secret base path if you want to use vault to manage _CREDS secrets ***#
34+
#CREDENTIAL_VAULT_ADDRESS=http://127.0.0.1:8200
35+
#CREDENTIAL_VAULT_SECRET_BASE_PATH=secret
3536

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

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ private function __construct()
5858
}
5959

6060
// Initialize vault storage
61-
$csBaseUrl = getenv('CREDENTIAL_VAULT_BASE_URL');
62-
if ($csBaseUrl !== false) {
61+
$cvAddress = getenv('CREDENTIAL_VAULT_ADDRESS');
62+
$cvSecretPath = getenv('CREDENTIAL_VAULT_SECRET_BASE_PATH');
63+
if ($cvAddress !== false && $cvSecretPath !== false) {
6364
try {
64-
$this->credStorage[self::ARRAY_KEY_FOR_VAULT] = new VaultStorage(rtrim($csBaseUrl, '/'));
65+
$this->credStorage[self::ARRAY_KEY_FOR_VAULT] = new VaultStorage(
66+
rtrim($cvAddress, '/'),
67+
'/' . trim($cvSecretPath, '/')
68+
);
6569
} catch (TestFrameworkException $e) {
6670
}
6771
}

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/SecretStorage/VaultStorage.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
class VaultStorage extends BaseStorage
1616
{
17+
/**
18+
* Mftf project path
19+
*/
1720
const MFTF_PATH = '/mftf';
1821
/**
19-
* Adobe Vault
22+
* Vault kv version 2 data
2023
*/
21-
const BASE_PATH = '/dx_magento_qe';
22-
const KV_DATA = 'data';
24+
const KV2_DATA = 'data';
2325

2426
/**
2527
* Default vault token file
@@ -54,18 +56,27 @@ class VaultStorage extends BaseStorage
5456
*/
5557
private $token = null;
5658

59+
/**
60+
* Vault secret base path
61+
*
62+
* @var string
63+
*/
64+
private $secretBasePath;
65+
5766
/**
5867
* CredentialVault constructor
5968
*
6069
* @param string $baseUrl
70+
* @param string $secretBasePath
6171
* @throws TestFrameworkException
6272
*/
63-
public function __construct($baseUrl)
73+
public function __construct($baseUrl, $secretBasePath)
6474
{
6575
parent::__construct();
6676
if (null === $this->client) {
6777
// Creating the client using Guzzle6 Transport and passing a custom url
6878
$this->client = new Client(new Guzzle6Transport(['base_uri' => $baseUrl]));
79+
$this->secretBasePath = $secretBasePath;
6980
}
7081
$this->readVaultTokenFromFileSystem();
7182
if (!$this->authenticated()) {
@@ -96,15 +107,15 @@ public function getEncryptedValue($key)
96107
try {
97108
// Split vendor/key to construct secret path
98109
list($vendor, $key) = explode('/', trim($key, '/'), 2);
99-
$url = self::BASE_PATH
100-
. (empty(self::KV_DATA) ? '' : '/' . self::KV_DATA)
110+
$url = $this->secretBasePath
111+
. (empty(self::KV2_DATA) ? '' : '/' . self::KV2_DATA)
101112
. self::MFTF_PATH
102113
. '/'
103114
. $vendor
104115
. '/'
105116
. $key;
106117
// Read value by key from vault
107-
$value = $this->client->read($url)->getData()[self::KV_DATA][$key];
118+
$value = $this->client->read($url)->getData()[self::KV2_DATA][$key];
108119
// Encrypt value for return
109120
$reValue = openssl_encrypt($value, parent::ENCRYPTION_ALGO, parent::$encodedKey, 0, parent::$iv);
110121
parent::$cachedSecretData[$key] = $reValue;

0 commit comments

Comments
 (0)