Skip to content

Commit d3f71ae

Browse files
authored
Merge pull request #459 from magento/MQE-1671-master
MQE-1671: document using credentials with vault in MFTF tests
2 parents 5aa3796 + 902bad6 commit d3f71ae

File tree

2 files changed

+139
-29
lines changed

2 files changed

+139
-29
lines changed

docs/configuration.md

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Configuration
22

33
The `*.env` file provides additional configuration for the Magento Functional Testing Framework (MFTF).
4-
To run the MFTF on your Magento testing instance, specify the basic configuration values.
4+
To run the MFTF on your Magento instance, specify the basic configuration values.
55
Advanced users can create custom configurations based on requirements and environment.
66

77
## Basic configuration
@@ -204,7 +204,7 @@ Example:
204204
FW_BP=~/magento/magento2-functional-testing-framework
205205
```
206206

207-
#### TESTS_MODULE_PATH
207+
### TESTS_MODULE_PATH
208208

209209
The path to where the MFTF modules mirror Magento modules.
210210

@@ -234,8 +234,8 @@ It points to `MAGENTO_BASE_URL` + `dev/tests/acceptance/utils/command.php`
234234

235235
Modify the default value:
236236

237-
- for non-default Magento installation
238-
- when use a subdirectory in the `MAGENTO_BASE_URL`
237+
- for non-default Magento installation
238+
- when use a subdirectory in the `MAGENTO_BASE_URL`
239239

240240
Example: `dev/tests/acceptance/utils/command.php`
241241

@@ -251,9 +251,35 @@ Example:
251251
BROWSER=firefox
252252
```
253253

254+
### CREDENTIAL_VAULT_ADDRESS
255+
256+
The Api address for a 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
257283
[generateDate]: test/actions.md#generatedate
258284
[mftf]: commands/mftf.md
259-
[timezones]: http://php.net/manual/en/timezones.php
285+
[timezones]: http://php.net/manual/en/timezones.php

docs/credentials.md

+108-24
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
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 the MFTF supports two types of credential storage:
7+
8+
- **.credentials file**
9+
- **HashiCorp vault**
10+
11+
## Configure File Storage
612

713
The MFTF creates a sample file for credentials during [initial setup][]: `magento2/dev/tests/acceptance/.credentials.example`.
814
The file contains an example list of keys for fields that can require credentials.
915

1016
### Create `.credentials`
1117

12-
To make the MFTF process the file with credentials, change directories to `magento2/dev/tests/acceptance/` and copy `.credentials.example` to `.credentials`.
18+
To make the MFTF process the file with credentials, in the command line, navigate to `magento2/dev/tests/acceptance/` and rename `.credentials.example` to `.credentials`.
1319

1420
```bash
1521
cd dev/tests/acceptance/
@@ -33,49 +39,119 @@ The command outputs the path if the file is excluded:
3339
.credentials
3440
```
3541

36-
### Define sensitive data
42+
### Define sensitive data in the `.credentials` file
3743

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

40-
```config
46+
```conf
4147
...
4248
# Credentials for the USPS service
43-
carriers_usps_userid=test_user
44-
carriers_usps_password=Lmgxvrq89uPwECeV
49+
magento/carriers_usps_userid=usps_test_user
50+
magento/carriers_usps_password=Lmgxvrq89uPwECeV
4551
4652
# Credentials for the DHL service
47-
#carriers/dhl/id_us=
48-
#carriers/dhl/password_us=
53+
#magento/carriers_dhl_id_us=dhl_test_user
54+
#magento/carriers_dhl_password_us=Mlgxv3dsagVeG
4955
....
56+
```
57+
58+
Or add new key & value pairs for your own credentials. The keys use the following format:
59+
60+
```conf
61+
<vendor>/<key_name>=<key_value>
5062
```
5163

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

5870
```conf
5971
# Credentials for the MyAwesome service
60-
my_awesome_service_token=rRVSVnh3cbDsVG39oTMz4A
72+
vendor/my_awesome_service_token=rRVSVnh3cbDsVG39oTMz4A
73+
```
6174

62-
# Credentials for the USPS service
63-
carriers_usps_userid=test_user
64-
carriers_usps_password=Lmgxvrq89uPwECeV
65-
....
75+
## Configure Vault Storage
76+
77+
Hashicorp vault secures, stores, and tightly controls access to data in modern computing.
78+
It provides advanced data protection for your testing credentials.
79+
80+
The MFTF works with both `vault enterprise` and `vault open source` that use `KV Version 2` secret engine.
81+
82+
### Install vault CLI
83+
84+
Download and install vault CLI tool if you want to run or develop MFTF tests locally. [Download Vault][Download Vault]
85+
86+
### Authenticate to vault via vault CLI
87+
88+
Authenticate to vault server via the vault CLI tool: [Login Vault][Login Vault].
89+
90+
```bash
91+
vault login -method -path
92+
```
93+
94+
**Do not** use `-no-store` command option, as the MFTF will rely on the persisted token in the token helper (usually the local filesystem) for future API requests.
95+
96+
### Store secrets in vault
97+
98+
The MFTF uses the `KV Version 2` secret engine for secret storage.
99+
More information for working with `KV Version 2` can be found in [Vault KV2][Vault KV2].
100+
101+
#### Secrets path and key convention
102+
103+
The path and key for secret data must follow the format:
104+
105+
```conf
106+
<SECRETS_BASE_PATH>/mftf/<VENDOR>/<SECRET_KEY>
107+
```
108+
109+
```conf
110+
# Secret path and key for carriers_usps_userid
111+
secret/mftf/magento/carriers_usps_userid
112+
113+
# Secret path and key for carriers_usps_password
114+
secret/mftf/magento/carriers_usps_password
115+
```
116+
117+
#### Write secrets to vault
118+
119+
You can use vault CLI or API to write secret data (credentials, etc) to vault. Here is a CLI example:
120+
121+
```bash
122+
vault kv put secret/mftf/magento/carriers_usps_userid carriers_usps_userid=usps_test_user
123+
vault kv put secret/mftf/magento/carriers_usps_password carriers_usps_password=Lmgxvrq89uPwECeV
66124
```
67125

126+
### Setup MFTF to use vault
127+
128+
Add vault configuration environment variables [`CREDENTIAL_VAULT_ADDRESS`][] and [`CREDENTIAL_VAULT_SECRET_BASE_PATH`][]
129+
from `etc/config/.env.example` in `.env`.
130+
Set values according to your vault server configuration.
131+
132+
```conf
133+
# Default vault dev server
134+
CREDENTIAL_VAULT_ADDRESS=http://127.0.0.1:8200
135+
CREDENTIAL_VAULT_SECRET_BASE_PATH=secret
136+
```
137+
138+
## Configure both File Storage and Vault Storage
139+
140+
It is possible and sometimes useful to setup and use both `.credentials` file and vault for secret storage at the same time.
141+
In this case, the MFTF tests are able to read secret data at runtime from both storage options, but the local `.credentials` file will take precedence.
142+
68143
<!-- {% raw %} -->
69144

70145
## Use credentials in a test
71146

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}}`:
147+
Credentials can be used in actions: [`fillField`][], [`magentoCLI`][], and [`createData`][].
148+
149+
Define the value as a reference to the corresponding key in the credentials file or vault such as `{{_CREDS.my_data_key}}`:
74150

75151
- `_CREDS` is an environment constant pointing to the `.credentials` file
76-
- `my_data_key` is a key in the the `.credentials` file that contains the value to be used in a test step
152+
- `my_data_key` is a key in the the `.credentials` file or vault that contains the value to be used in a test step
77153

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

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

93169
<div class="bs-callout bs-callout-info">
94-
The MFTF tests delivered with Magento application do not use credentials and do not cover external services, because of sensitivity of the data.</div>
170+
The MFTF tests delivered with Magento application do not use credentials and do not cover external services, because of sensitivity of the data.
171+
</div>
95172

96173
<!-- Link definitions -->
97174
[`fillField`]: test/actions.md#fillfield
175+
[`magentoCLI`]: test/actions.md#magentocli
176+
[`createData`]: test/actions.md#createdata
98177
[data]: data.md
99178
[initial setup]: getting-started.md
100179
[test reports]: reporting.md
180+
[Download Vault]: https://www.hashicorp.com/products/vault/
181+
[Login Vault]: https://www.vaultproject.io/docs/commands/login.html
182+
[Vault KV2]: https://www.vaultproject.io/docs/secrets/kv/kv-v2.html
183+
[`CREDENTIAL_VAULT_ADDRESS`]: configuration.md#CREDENTIAL_VAULT_ADDRESS
184+
[`CREDENTIAL_VAULT_SECRET_BASE_PATH`]: configuration.md#CREDENTIAL_VAULT_SECRET_BASE_PATH

0 commit comments

Comments
 (0)