Skip to content

Commit 5fb8569

Browse files
committed
MQE-1671: document using credentials with vault in MFTF tests
1 parent d9de524 commit 5fb8569

File tree

2 files changed

+128
-22
lines changed

2 files changed

+128
-22
lines changed

docs/configuration.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,32 @@ Example:
251251
BROWSER=firefox
252252
```
253253

254+
###CREDENTIAL_VAULT_ADDRESS
255+
256+
Api address for vault server.
257+
258+
Default: http://127.0.0.1:8200
259+
260+
Example:
261+
262+
```conf
263+
# Default api address for local vault dev server
264+
CREDENTIAL_VAULT_ADDRESS=http://127.0.0.1:8200
265+
```
266+
267+
###CREDENTIAL_VAULT_SECRET_BASE_PATH
268+
269+
Vault secret engine base path.
270+
271+
Default: secret
272+
273+
Example:
274+
275+
```conf
276+
# Default base path for kv secret engine in local vault dev server
277+
CREDENTIAL_VAULT_SECRET_BASE_PATH=secret
278+
```
279+
254280
<!-- Link definitions -->
255281

256282
[`MAGENTO_CLI_COMMAND_PATH`]: #magento_cli_command_path

docs/credentials.md

Lines changed: 102 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Credentials
22

3-
When you test functionality that involves external services such as UPS, FedEx, PayPal, or SignifyD, use the MFTF credentials feature to hide sensitive [data][] like integration tokens and API keys.
3+
When you test functionality that involves external services such as UPS, FedEx, PayPal, or SignifyD,
4+
use the MFTF credentials feature to hide sensitive [data][] like integration tokens and API keys.
45

5-
## Define sensitive data in `.credentials`
6+
Currently MFTF supports two types of credential storage: **.credentials file** and **HashiCorp vault**.
7+
8+
# Configure File Storage
69

710
The MFTF creates a sample file for credentials during [initial setup][]: `magento2/dev/tests/acceptance/.credentials.example`.
811
The file contains an example list of keys for fields that can require credentials.
@@ -33,49 +36,119 @@ The command outputs the path if the file is excluded:
3336
.credentials
3437
```
3538

36-
### Define sensitive data
39+
### Define sensitive data in `.credentials` file
3740

38-
Open the `.credentials` file, uncomment the fields you want to use, and add your values:
41+
Open the `.credentials` file, for Magento core credentials, uncomment the fields you want to use, and add your values:
3942

40-
```config
43+
```conf
4144
...
4245
# Credentials for the USPS service
43-
carriers_usps_userid=test_user
44-
carriers_usps_password=Lmgxvrq89uPwECeV
46+
magento/carriers_usps_userid=usps_test_user
47+
magento/carriers_usps_password=Lmgxvrq89uPwECeV
4548
4649
# Credentials for the DHL service
47-
#carriers/dhl/id_us=
48-
#carriers/dhl/password_us=
50+
#magento/carriers_dhl_id_us=dhl_test_user
51+
#magento/carriers_dhl_password_us=Mlgxv3dsagVeG
4952
....
53+
```
54+
55+
Or add new key & value pairs for your own credentials. The keys use the following format:
56+
57+
```conf
58+
<vendor>/<key_name>=<key_value>
5059
```
5160

5261
<div class="bs-callout bs-callout-info" markdown="1">
53-
The `/` symbol is not supported in a key name.
62+
The `/` symbol is not supported in a `key_name` other than the one after your vendor or extension name.
5463
</div>
55-
56-
You are free to use any other keys you like, as they are merely the keys to reference from your tests.
64+
65+
Otherwise you are free to use any other `key_name` you like, as they are merely the keys to reference from your tests.
5766

5867
```conf
5968
# Credentials for the MyAwesome service
60-
my_awesome_service_token=rRVSVnh3cbDsVG39oTMz4A
69+
vendor/my_awesome_service_token=rRVSVnh3cbDsVG39oTMz4A
70+
```
6171

62-
# Credentials for the USPS service
63-
carriers_usps_userid=test_user
64-
carriers_usps_password=Lmgxvrq89uPwECeV
65-
....
72+
# Configure Vault Storage
73+
74+
Hashicorp vault secures, stores, and tightly controls access to data in modern computing.
75+
It provides advanced data protection for your testing credentials.
76+
77+
MFTF works with both `vault enterprise` and `vault open source` that use `KV Version 2` secret engine.
78+
79+
### Install vault CLI
80+
81+
Download and install vault CLI tool if you want to run or develop MFTF tests locally. [Download Vault][Download Vault]
82+
83+
### Authenticate to vault via vault CLI
84+
85+
Authenticate to vault server via vault CLI tool. [Login Vault][Login Vault]
86+
87+
```terminal
88+
vault login -method -path
6689
```
90+
**Do not** use `-no-store` command option, as MFTF will rely on the persisted token in the token helper
91+
(usually the local filesystem) for future api requests.
92+
93+
### Store secrets in vault
94+
95+
MFTF uses `KV Version 2` secret engine for secret storage.
96+
More information for working with `KV Version 2` can be found in [Vault KV2][Vault KV2].
97+
98+
#### Secrets path and key convention
99+
100+
The path and key for secret data must follow:
101+
102+
```conf
103+
<SECRETS_BASE_PATH>/mftf/<VENDOR>/<SECRET_KEY>
104+
```
105+
106+
```conf
107+
# Secret path and key for carriers_usps_userid
108+
secret/mftf/magento/carriers_usps_userid
109+
110+
# Secret path and key for carriers_usps_password
111+
secret/mftf/magento/carriers_usps_password
112+
```
113+
114+
#### Write secrets to vault
115+
116+
You can use vault CLI or Api to write secret data (credentials, etc) to vault. Here is a CLI example:
117+
118+
```terminal
119+
vault kv put secret/mftf/magento/carriers_usps_userid carriers_usps_userid=usps_test_user
120+
vault kv put secret/mftf/magento/carriers_usps_password carriers_usps_password=Lmgxvrq89uPwECeV
121+
```
122+
123+
### Setup MFTF to use vault
124+
125+
Add vault configuration environment variables [`CREDENTIAL_VAULT_ADDRESS`][] and [`CREDENTIAL_VAULT_SECRET_BASE_PATH`][]
126+
from `etc/config/.env.example` in `.env`.
127+
Set values according to your vault server configuration.
128+
129+
```conf
130+
# Default vault dev server
131+
CREDENTIAL_VAULT_ADDRESS=http://127.0.0.1:8200
132+
CREDENTIAL_VAULT_SECRET_BASE_PATH=secret
133+
```
134+
135+
# Configure both File Storage and Vault Storage
136+
137+
It's possible and sometimes useful to setup and use both `.credentials` file and vault for secret storage at the same time.
138+
In this case, MFTF tests are able to read secret data at runtime from both storage, and local `.credentials` file will take precedence.
67139

68140
<!-- {% raw %} -->
69141

70-
## Use credentials in a test
142+
# Use credentials in a test
143+
144+
Credentials can be used in actions: [`fillField`][], [`magentoCLI`][], and [`createData`][].
71145

72-
Access the data defined in the `.credentials` file using the [`fillField`][] action with the `userInput` attribute.
73-
Define the value as a reference to the corresponding key in the credentials file such as `{{_CREDS.my_data_key}}`:
146+
Define the value as a reference to the corresponding key in the credentials file or vault such as `{{_CREDS.my_data_key}}`:
74147

75148
- `_CREDS` is an environment constant pointing to the `.credentials` file
76149
- `my_data_key` is a key in the the `.credentials` file that contains the value to be used in a test step
77150

78-
For example:
151+
For example, reference secret data in the [`fillField`][] action with the `userInput` attribute.
79152

80153
```xml
81154
<fillField stepKey="FillApiToken" selector=".api-token" userInput="{{_CREDS.my_data_key}}" />
@@ -88,13 +161,20 @@ For example:
88161
The generated tests do not contain credentials values.
89162
The MFTF dynamically retrieves, encrypts, and decrypts the sensitive data during test execution.
90163
Decrypted credentials do not appear in the console, error logs, or [test reports][].
91-
The decrypted values are only available in the `.credentials` file.
164+
The decrypted values are only available in the `.credentials` file or within vault.
92165

93166
<div class="bs-callout bs-callout-info">
94167
The MFTF tests delivered with Magento application do not use credentials and do not cover external services, because of sensitivity of the data.</div>
95168

96169
<!-- Link definitions -->
97170
[`fillField`]: test/actions.md#fillfield
171+
[`magentoCLI`]: test/actions.md#magentocli
172+
[`createData`]: test/actions.md#createdata
98173
[data]: data.md
99174
[initial setup]: getting-started.md
100175
[test reports]: reporting.md
176+
[Download Vault]: https://www.hashicorp.com/products/vault/
177+
[Login Vault]: https://www.vaultproject.io/docs/commands/login.html
178+
[Vault KV2]: https://www.vaultproject.io/docs/secrets/kv/kv-v2.html
179+
[`CREDENTIAL_VAULT_ADDRESS`]: configuration.md#CREDENTIAL_VAULT_ADDRESS
180+
[`CREDENTIAL_VAULT_SECRET_BASE_PATH`]: configuration.md#CREDENTIAL_VAULT_SECRET_BASE_PATH

0 commit comments

Comments
 (0)