Skip to content

Commit

Permalink
Add service connection « Vault Interaction »
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizcko committed Jan 19, 2024
1 parent 1f7d252 commit d505f67
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 39 deletions.
7 changes: 6 additions & 1 deletion build_job.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ catch{
$subProjects = $jsonVssConfigFile.contributions
Foreach ($subProject in $subProjects){
$currentProjectName = $subProject.properties.name

if ($currentProjectName -eq "VaultInteractionEndpoint") {
continue
}

$subProjectPath = Join-Path -Path $rootPath -ChildPath $subProject.properties.name
$subCommunFolderPath = Join-Path -Path $subProjectPath -ChildPath $commonFolderName
$pathTaskConfigFile = Join-Path -Path $subProjectPath -ChildPath "task.json"
Expand Down Expand Up @@ -104,4 +109,4 @@ Remove-Item -Path "$pathCommon" -Recurse -Force

# Start build
Set-Location $rootPath
tfx extension create --manifest-globs vss-extension.json
npx tfx extension create --manifest-globs vss-extension.json
42 changes: 26 additions & 16 deletions dist/kv_read/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
],
"author": "Fizcko",
"version": {
"Major": 4,
"Major": 5,
"Minor": 0,
"Patch": 2
"Patch": 0
},
"instanceNameFormat": "Vault - Read KV secrets",
"groups": [
Expand All @@ -34,13 +34,32 @@
}
],
"inputs": [
{
"name": "strAuthType",
"type": "pickList",
"label": "Authentication Method",
"defaultValue": "clientToken",
"required": true,
"helpMarkDown": "Specifies the authentication method.",
"options": {
"approle": "AppRole",
"azure": "Azure",
"clientToken": "Client Token",
"ldap": "LDAP",
"radius": "Radius",
"serviceConnection": "Service connection",
"userpass": "Username \u0026 Password"
},
"groupName": "grpServer"
},
{
"name": "strUrl",
"type": "string",
"label": "Vault URL",
"defaultValue": "https://myurl",
"required": true,
"helpMarkDown": "Specifies the url of the Vault server (http or https).",
"visibleRule": "strAuthType != serviceConnection",
"groupName": "grpServer"
},
{
Expand Down Expand Up @@ -104,21 +123,12 @@
"groupName": "grpServer"
},
{
"name": "strAuthType",
"type": "pickList",
"label": "Authentication Method",
"defaultValue": "clientToken",
"name": "serviceConnectionName",
"type": "connectedService:VaultInteractionEndpoint",
"label": "Vault Interaction Service Connection",
"required": true,
"helpMarkDown": "Specifies the authentication method.",
"options": {
"approle": "AppRole",
"azure": "Azure",
"clientToken": "Client Token",
"ldap": "LDAP",
"radius": "Radius",
"userpass": "Username \u0026 Password"
},
"groupName": "grpAuth"
"groupName": "grpAuth",
"visibleRule": "strAuthType = serviceConnection"
},
{
"name": "strAuthPath",
Expand Down
4 changes: 2 additions & 2 deletions dist/tool_create_file/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
],
"author": "Fizcko",
"version": {
"Major": 4,
"Major": 5,
"Minor": 0,
"Patch": 2
"Patch": 0
},
"instanceNameFormat": "Tool - Create a File",
"groups": [
Expand Down
20 changes: 13 additions & 7 deletions overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

## Authentication methods available

- AppRole
- AppRole *
- Azure
- Client Token
- LDAP
- Radius
- Username & Password
- Client Token *
- LDAP *
- Radius *
- Username & Password *

\* Available to setup in a service connection

## Utilities

Expand Down Expand Up @@ -96,11 +98,15 @@ Parameters :

## Release note

### v5.0.0
- 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.

### v4.0.2
- Remove secret value from output log
- Remove secret value from output log.

### v4.0.1
- Disable proxy when useProxy is none
- Disable proxy when useProxy is none.

### v4.0.0
- Upgrading tasks to Node 10
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"devDependencies": {
"@types/node": "10.17.39",
"@types/q": "^1.5.1",
"mocha": "^6.1.4"
"mocha": "^6.1.4",
"tfx-cli": "0.8.1"
}
}
84 changes: 74 additions & 10 deletions src/common/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,22 @@ export function requestVault(requestedUrl: string, ignoreCertificateChecks: bool
export function getToken(strRequestTimeout): Promise<string> {
return new Promise((resolve, reject) => {

var strUrl = tl.getInput('strUrl', true);
var strUrl;
var serverEndpointAuth;
var overloadFromServiceConnection = false;

var strAuthType = tl.getInput('strAuthType', true);

if(strAuthType == "serviceConnection"){
var serviceConnectionValues = tl.getInput('serviceConnectionName',true);
strUrl = tl.getEndpointUrl(serviceConnectionValues, false);
serverEndpointAuth = tl.getEndpointAuthorization(serviceConnectionValues, false);
strAuthType = serverEndpointAuth["parameters"]["authType"];
overloadFromServiceConnection = true;
}
else{
strUrl = tl.getInput('strUrl', true);
}
var ignoreCertificateChecks = tl.getBoolInput('ignoreCertificateChecks', true);

var authUrl = null;
Expand All @@ -145,8 +159,17 @@ export function getToken(strRequestTimeout): Promise<string> {
apiURL = "/v1/auth/" + strAuthPath + "/login";
}

var strRoleID = tl.getInput('strRoleID', true);
var strSecretID = tl.getInput('strSecretID', true);
var strRoleID;
var strSecretID;

if(overloadFromServiceConnection){
strRoleID = serverEndpointAuth["parameters"]["username"];
strSecretID = serverEndpointAuth["parameters"]["password"];
}
else{
strRoleID = tl.getInput('strRoleID', true);
strSecretID = tl.getInput('strSecretID', true);
}

authUrl = url.resolve(strUrl,apiURL);
bodyData = JSON.stringify({
Expand Down Expand Up @@ -190,7 +213,15 @@ export function getToken(strRequestTimeout): Promise<string> {
break;
case "clientToken":
console.log("[INFO] Authentication Method : 'Client Token'");
var strToken = tl.getInput('strToken', true);

var strToken;

if(overloadFromServiceConnection){
strToken = serverEndpointAuth["parameters"]["password"];
}
else{
strToken = tl.getInput('strToken', true);
}
resolve(strToken);
break;
case "ldap":
Expand All @@ -200,8 +231,19 @@ export function getToken(strRequestTimeout): Promise<string> {
if(strAuthPath){
apiURL = "/v1/auth/" + strAuthPath + "/login/";
}
var strUsername = tl.getInput('strUsername', true);
var strPassword = tl.getInput('strPassword', true);

var strUsername;
var strPassword;

if(overloadFromServiceConnection){
strUsername = serverEndpointAuth["parameters"]["username"];
strPassword = serverEndpointAuth["parameters"]["password"];
}
else{
strUsername = tl.getInput('strUsername', true);
strPassword = tl.getInput('strPassword', true);
}

authUrl = url.resolve(strUrl,apiURL + strUsername);
bodyData = JSON.stringify({
password: strPassword
Expand All @@ -214,8 +256,19 @@ export function getToken(strRequestTimeout): Promise<string> {
if(strAuthPath){
apiURL = "/v1/auth/" + strAuthPath + "/login/";
}
var strUsername = tl.getInput('strUsername', true);
var strPassword = tl.getInput('strPassword', true);

var strUsername;
var strPassword;

if(overloadFromServiceConnection){
strUsername = serverEndpointAuth["parameters"]["username"];
strPassword = serverEndpointAuth["parameters"]["password"];
}
else{
strUsername = tl.getInput('strUsername', true);
strPassword = tl.getInput('strPassword', true);
}

authUrl = url.resolve(strUrl,apiURL + strUsername);
bodyData = JSON.stringify({
password: strPassword
Expand All @@ -228,8 +281,19 @@ export function getToken(strRequestTimeout): Promise<string> {
if(strAuthPath){
apiURL = "/v1/auth/" + strAuthPath + "/login/";
}
var strUsername = tl.getInput('strUsername', true);
var strPassword = tl.getInput('strPassword', true);

var strUsername;
var strPassword;

if(overloadFromServiceConnection){
strUsername = serverEndpointAuth["parameters"]["username"];
strPassword = serverEndpointAuth["parameters"]["password"];
}
else{
strUsername = tl.getInput('strUsername', true);
strPassword = tl.getInput('strPassword', true);
}

authUrl = url.resolve(strUrl,apiURL + strUsername);
bodyData = JSON.stringify({
password: strPassword
Expand Down
11 changes: 10 additions & 1 deletion src/kv_read/kv_read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ async function run() {

tl.setResourcePath(path.join(__dirname, 'task.json'));

var strUrl = tl.getInput('strUrl', true);
var strUrl;
var strAuthType = tl.getInput('strAuthType', true);
if(strAuthType == "serviceConnection"){
var serviceConnectionValues = tl.getInput('serviceConnectionName',true);
strUrl = tl.getEndpointUrl(serviceConnectionValues, false);
}
else{
strUrl = tl.getInput('strUrl', true);
}

var ignoreCertificateChecks = tl.getBoolInput('ignoreCertificateChecks', true);
var useProxy = tl.getInput('useProxy', true);
var strRequestTimeout = tl.getInput('strRequestTimeout', false);
Expand Down
Loading

0 comments on commit d505f67

Please sign in to comment.