Skip to content

Commit

Permalink
Add support of the interactive keyboard authentication (#16441)
Browse files Browse the repository at this point in the history
* Add support of the interactive keyboard authentication
  • Loading branch information
kirill-ivlev authored Jun 20, 2022
1 parent 1ea9325 commit d883a26
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Tasks/SshV0/Strings/resources.resjson/en-US/resources.resjson
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"loc.input.help.interactiveSession": "If this option is selected, interactive session will be started - if there's a password request, it will be filled by user's password. It could be useful to run commands like 'sudo'",
"loc.input.label.readyTimeout": "SSH handshake timeout",
"loc.input.help.readyTimeout": "How long (in milliseconds) to wait for the SSH handshake to complete.",
"loc.input.label.interactiveKeyboardAuthentication": "Use interactive-keyboard authentication",
"loc.input.help.interactiveKeyboardAuthentication": "Use this value if PasswordAuthentication is disabled on the target machine",
"loc.messages.ConnectionFailed": "Failed to connect to remote machine. Verify the SSH service connection details. Error: %s.",
"loc.messages.FailedToWriteScript": "Failed to write the script to disk: %s",
"loc.messages.RemoteCmdExecutionErr": "Command failed with errors on remote machine.",
Expand Down
4 changes: 3 additions & 1 deletion Tasks/SshV0/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async function run() {

//read SSH endpoint input
const sshEndpoint = tl.getInput('sshEndpoint', true);
const tryKeyboard: boolean = tl.getBoolInput('interactiveKeyboardAuthentication', false);
const username: string = tl.getEndpointAuthorizationParameter(sshEndpoint, 'username', false);
const password: string = tl.getEndpointAuthorizationParameter(sshEndpoint, 'password', true); //passphrase is optional
const privateKey: string = process.env['ENDPOINT_DATA_' + sshEndpoint + '_PRIVATEKEY']; //private key is optional, password can be used for connecting
Expand All @@ -36,7 +37,8 @@ async function run() {
host: hostname,
port: port,
username: username,
readyTimeout: readyTimeout
readyTimeout: readyTimeout,
tryKeyboard: tryKeyboard,
};

if (privateKey) {
Expand Down
3 changes: 2 additions & 1 deletion Tasks/SshV0/ssh2helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export function setupSshClientConnection(sshConfig: any): Q.Promise<any> {
defer.resolve(client);
}).on('error', (err) => {
defer.reject(err);
}).connect(sshConfig);
}).on('keyboard-interactive', (name, instructions, instructionsLang, prompts, finish) => { finish([sshConfig.password]); })
.connect(sshConfig);
return defer.promise;
}

Expand Down
11 changes: 10 additions & 1 deletion Tasks/SshV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 200,
"Minor": 207,
"Patch": 0
},
"demands": [],
Expand Down Expand Up @@ -135,6 +135,15 @@
"expression": "isMatch(value, '(^\\d*$)','Multiline')",
"message": "Enter a valid value for timeout."
}
},
{
"name": "interactiveKeyboardAuthentication",
"type": "boolean",
"label": "Use interactive-keyboard authentication",
"defaultValue": false,
"required": false,
"groupName": "advanced",
"helpMarkDown": "Use this value if PasswordAuthentication is disabled on the target machine"
}
],
"execution": {
Expand Down
11 changes: 10 additions & 1 deletion Tasks/SshV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 200,
"Minor": 207,
"Patch": 0
},
"demands": [],
Expand Down Expand Up @@ -135,6 +135,15 @@
"expression": "isMatch(value, '(^\\d*$)','Multiline')",
"message": "Enter a valid value for timeout."
}
},
{
"name": "interactiveKeyboardAuthentication",
"type": "boolean",
"label": "ms-resource:loc.input.label.interactiveKeyboardAuthentication",
"defaultValue": false,
"required": false,
"groupName": "advanced",
"helpMarkDown": "ms-resource:loc.input.help.interactiveKeyboardAuthentication"
}
],
"execution": {
Expand Down

0 comments on commit d883a26

Please sign in to comment.