This extension provide the ability to interact with HashiCorp Vault.
- AppRole *
- Azure
- Client Token *
- LDAP *
- Radius *
- Username & Password *
* Available to setup in a service connection
-
Vault - Read KV secrets
Provide the ability to read KV secrets from HashiCorp Vault and load them into variables.
Note
- The field « Secret path » have to ends with a « / » if you want to discover secrets across current folder and his subfolders. See Use case 2. In discovery mode if the « Prefix type » is set to « None » or « Custom » and you have secrets with the same name in different folder the last value read will be set in the variable (erasing previus values).
Examples
For the examples the following folder structure is created.
« ALM » is a KV v2 engine.
« APP1 » and « APP2 » is two folders containing a subfolder « DEV » and two secret « key_1 » and « key_2 ».
Use case 1
Read secrets from a KV v2 engine called « ALM » located at path « APP1/DEV ».
There is now two variables called « APP1_key_1 » and « APP1_key_2 » that you can used in your next tasks by using
$(APP1_key_1) and/or $ (APP1_key_2).Use case 2
Read secrets from a KV v2 engine called « ALM » and browse recursively on sub folders.
There is now four variables called « APP1_DEV_key_1 », « APP1_DEV_key_2 », « APP2_DEV_key_1 », « APP2_DEV_key_2 » that you can used in your next tasks by using
$(APP1_DEV_key_1), $ (APP1_DEV_key_2),$(APP2_DEV_key_1), $ (APP2_DEV_key_2).Use output variables from the Service Connection
Here a YAML pipeline definition example showing how to use output variables:
stages: - stage: 'Stage_A' jobs: - job: 'Job_A1' steps: - task: VaultReadKV@5 displayName: 'Vault - Read KV secrets ' inputs: strAuthType: serviceConnection serviceConnectionName: 'vault-dev' exportServiceConnectionSettings: true ignoreCertificateChecks: true strKVEnginePath: ALM strPrefixType: folder replaceCR: true strCRPrefix: '#{rn}#' - bash: | echo "url '$(VaultReadKV.url)'" echo "username '$(VaultReadKV.username)'" echo "password '$(VaultReadKV.password)'" displayName: 'Check variables' - stage: 'Stage_B' dependsOn: Stage_A jobs: - job: 'Job_B1' variables: vaultUrl: $[stageDependencies.Stage_A.Job_A1.outputs['VaultReadKV.url']] vaultUsername: $[stageDependencies.Stage_A.Job_A1.outputs['VaultReadKV.username']] vaultPassword: $[stageDependencies.Stage_A.Job_A1.outputs['VaultReadKV.password']] steps: - bash: | echo "url '$(vaultUrl)'" echo "username '$(vaultUsername)'" echo "password '$(vaultPassword)'" displayName: 'Check variables'
-
Tool - Create a File
Provide the ability to create a file and perform an action on his content.
Parameters :
-
Target directory: Directory to save the file.
-
File name: Name of the file to create (ended by the extension).
-
File Content: Content of the file.
-
Encoding: Output file encoding. More defails in NodeJS documentation (Buffers and Character Encodings).
-
Action to perform: Action to perform on the file content.
- Replace token by a new line
- Decode from base64
-
Token to replace: Define the token to replace by a new line.
-
New line type: The type of the new line.
- Carriage Return (CR, \r)
- Line Feed (LF, \n)
- CR followed by LF (CRLF, \r\n)
Use case 1
A variable loaded by the task « Vault - Read KV secrets » contains a multiline value where the carriage return have been replaced by a token. This variable is named « $(APP2_DEV_key_3) ». The token is « #{rn}# ».
A file called « myCert.pem » will be created and the token « #{rn}# » will be replaced by a Windows Carriage Return (CRLF).
Use case 2
A variable loaded by the task « Vault - Read KV secrets » contains a base64 encoded value. This variable is named « $(APP2_DEV_key_4) ».
A file called « myCert.pem » will be created with the content of decoded from base64.
- Add execution for node 16 & node 20
- Add the possibility to export Services Connection settings as output variables. Check Use output variables from the Service Connection for more details.
- Add service connection « Vault Interaction » This allows you to set the Vault URL and Authentication methods (AppRole, Client Token, LDAP, Radius, Username & Password) directly in a service connection.
- Remove secret value from output log.
- Disable proxy when useProxy is none.
- Upgrading tasks to Node 10
- Fix bug in token request function.
- Improvement of the errors messages.
- Use package axios to perform http/https requests.
- Add possibility to define a proxy for requests.
- Add the task « Tool - Create a File ».
- Add possibility to use namespaces (Vault Enterprise).
- Fix Windows carriage return who were replaced twice.
- Add possibility to replace carriage return by a token in secrets having multilines because Azure Devops do not manage multiline secrets.
- Add possibility to set a timeout value when requesting Vault's API.
- Add possibility to change the path of an authentication method.
- The task now can recursively load secrets from a folders and his subfolders. Or just load secrets from a specific path.
- Add Azure authentication method
- Add Radius authentication method
- Improvement of the errors management
- Read secret from a KV engine (v1 or v2) and load them into variables.








