microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.5k stars 2.61k forks source link

[BUG]: (CopyFilesOverSSHV0) TypeError: Cannot read property 'getPrivatePEM' of undefined. #19628

Open jonaskohl opened 8 months ago

jonaskohl commented 8 months ago

New issue checklist

Task name

CopyFilesOverSSH

Task version

0.205.0

Issue Description

When using the CopyFilesOverSSH task, the task fails with TypeError: Cannot read property 'getPrivatePEM' of undefined.

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

Azure DevOps Server (Please specify exact version in the textbox below)

Azure DevOps Server Version (if applicable)

Azure DevOps Server 2022.0.1 (AzureDevOpsServer_20230418.1)

Operation system

Windows Server 2019

Relevant log output

##[error]Error: Fehler beim Herstellen einer Verbindung mit dem Remotecomputer. Überprüfen Sie die SSH-Dienstverbindungsdetails. TypeError: Cannot read property 'getPrivatePEM' of undefined.
##[debug]Processed: ##vso[task.issue type=error;]Error: Fehler beim Herstellen einer Verbindung mit dem Remotecomputer. Überprüfen Sie die SSH-Dienstverbindungsdetails. TypeError: Cannot read property 'getPrivatePEM' of undefined.
##[debug]Processed: ##vso[task.complete result=Failed;]Error: Fehler beim Herstellen einer Verbindung mit dem Remotecomputer. Überprüfen Sie die SSH-Dienstverbindungsdetails. TypeError: Cannot read property 'getPrivatePEM' of undefined.

Full task logs with system.debug enabled

2024-03-11T12:21:01.8613415Z ##[debug]Evaluating condition for st***: 'Dateien sicher auf den Remotecomputer kopieren'
2024-03-11T12:21:01.8615807Z ##[debug]Evaluating: succeeded()
2024-03-11T12:21:01.8616371Z ##[debug]Evaluating succeeded:
2024-03-11T12:21:01.8617539Z ##[debug]=> True
2024-03-11T12:21:01.8618205Z ##[debug]Result: True
2024-03-11T12:21:01.8618957Z ##[section]Dateien sicher auf den Remotecomputer kopieren wird gestartet.
2024-03-11T12:21:01.8904067Z ==============================================================================
2024-03-11T12:21:01.8904368Z Task         : Dateien über SSH kopieren
2024-03-11T12:21:01.8904555Z Description  : Dateien oder Buildartefakte auf einen Remotecomputer über SSH kopieren
2024-03-11T12:21:01.8904815Z Version      : 0.205.0
2024-03-11T12:21:01.8904955Z Author       : Microsoft Corporation
2024-03-11T12:21:01.8905115Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/copy-files-over-ssh
2024-03-11T12:21:01.8905429Z ==============================================================================
2024-03-11T12:21:01.9582840Z ##[debug]Using node path: D:\DevOps_Agents\EPAgent64\externals\node10\bin\node.exe
2024-03-11T12:21:02.1754791Z ##[debug]agent.TempDirectory=d:\EPDevOps_Builds\EPAgent64\_temp
2024-03-11T12:21:02.1803318Z ##[debug]loading inputs and endpoints
2024-03-11T12:21:02.1818860Z ##[debug]loading ENDPOINT_AUTH_9919762c-9009-4ddd-9f76-738ac71a93c7
2024-03-11T12:21:02.1837025Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_9919762c-9009-4ddd-9f76-738ac71a93c7_PASSWORD
2024-03-11T12:21:02.1841463Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_9919762c-9009-4ddd-9f76-738ac71a93c7_USERNAME
2024-03-11T12:21:02.1845029Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2024-03-11T12:21:02.1848242Z ##[debug]loading ENDPOINT_AUTH_SCHEME_9919762c-9009-4ddd-9f76-738ac71a93c7
2024-03-11T12:21:02.1851658Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2024-03-11T12:21:02.1854570Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2024-03-11T12:21:02.1858244Z ##[debug]loading INPUT_CLEANHIDDENFILESINTARGET
2024-03-11T12:21:02.1861376Z ##[debug]loading INPUT_CLEANTARGETFOLDER
2024-03-11T12:21:02.1864533Z ##[debug]loading INPUT_CONTENTS
2024-03-11T12:21:02.1868172Z ##[debug]loading INPUT_FAILONEMPTYSOURCE
2024-03-11T12:21:02.1871389Z ##[debug]loading INPUT_FLATTENFOLDERS
2024-03-11T12:21:02.1874306Z ##[debug]loading INPUT_ISWINDOWSONTARGET
2024-03-11T12:21:02.1878036Z ##[debug]loading INPUT_OVERWRITE
2024-03-11T12:21:02.1880666Z ##[debug]loading INPUT_READYTIMEOUT
2024-03-11T12:21:02.1883720Z ##[debug]loading INPUT_SOURCEFOLDER
2024-03-11T12:21:02.1886775Z ##[debug]loading INPUT_SSHENDPOINT
2024-03-11T12:21:02.1890176Z ##[debug]loading INPUT_TARGETFOLDER
2024-03-11T12:21:02.1895767Z ##[debug]loading SECRET_SSHPRIVATEKEY
2024-03-11T12:21:02.1902092Z ##[debug]loaded 19
2024-03-11T12:21:02.1907015Z ##[debug]Agent.ProxyUrl=undefined
2024-03-11T12:21:02.1907894Z ##[debug]Agent.CAInfo=undefined
2024-03-11T12:21:02.1908618Z ##[debug]Agent.ClientCert=undefined
2024-03-11T12:21:02.1909316Z ##[debug]Agent.SkipCertValidation=undefined
2024-03-11T12:21:02.3126164Z ##[debug]check path : d:\EPDevOps_Builds\EPAgent64\_tasks\CopyFilesOverSSH_67cec91b-0351-4c2f-8465-d74b3d2a2d96\0.205.0\task.json
2024-03-11T12:21:02.3130544Z ##[debug]adding resource file: d:\EPDevOps_Builds\EPAgent64\_tasks\CopyFilesOverSSH_67cec91b-0351-4c2f-8465-d74b3d2a2d96\0.205.0\task.json
2024-03-11T12:21:02.3131452Z ##[debug]system.culture=de-DE
2024-03-11T12:21:02.3166172Z ##[debug]sshEndpoint=9919762c-9009-4ddd-9f76-738ac71a93c7
2024-03-11T12:21:02.3170704Z ##[debug]9919762c-9009-4ddd-9f76-738ac71a93c7 auth param username = ***
2024-03-11T12:21:02.3175029Z ##[debug]9919762c-9009-4ddd-9f76-738ac71a93c7 auth param password = ***
2024-03-11T12:21:02.3176079Z ##[debug]9919762c-9009-4ddd-9f76-738ac71a93c7 data host = [REDACTED]
2024-03-11T12:21:02.3176911Z ##[debug]9919762c-9009-4ddd-9f76-738ac71a93c7 data port = 22
2024-03-11T12:21:02.3181610Z ##[debug]readyTimeout=5000
2024-03-11T12:21:02.3182963Z ##[debug]Using private key for ssh connection.
2024-03-11T12:21:02.3185535Z ##[debug]contents=**
2024-03-11T12:21:02.3189670Z ##[debug]sourceFolder=d:\EPDevOps_Builds\EPAgent64\179\s\build\
2024-03-11T12:21:02.3190484Z ##[debug]check path : d:\EPDevOps_Builds\EPAgent64\179\s\build\
2024-03-11T12:21:02.3195619Z ##[debug]targetFolder=/home/***/docker_staging/www/
2024-03-11T12:21:02.3199919Z ##[debug]cleanTargetFolder=true
2024-03-11T12:21:02.3203206Z ##[debug]overwrite=true
2024-03-11T12:21:02.3206236Z ##[debug]failOnEmptySource=true
2024-03-11T12:21:02.3209551Z ##[debug]flattenFolders=false
2024-03-11T12:21:02.3239888Z Die SSH-Dienstverbindung mit dem Remotehost "[REDACTED]" wird eingerichtet.
2024-03-11T12:21:02.3303302Z ##[debug]task result: Failed
2024-03-11T12:21:02.3350440Z ##[error]Error: Fehler beim Herstellen einer Verbindung mit dem Remotecomputer. Überprüfen Sie die SSH-Dienstverbindungsdetails. TypeError: Cannot read property 'getPrivatePEM' of undefined.
2024-03-11T12:21:02.3360037Z ##[debug]Processed: ##vso[task.issue type=error;]Error: Fehler beim Herstellen einer Verbindung mit dem Remotecomputer. Überprüfen Sie die SSH-Dienstverbindungsdetails. TypeError: Cannot read property 'getPrivatePEM' of undefined.
2024-03-11T12:21:02.3367561Z ##[debug]Processed: ##vso[task.complete result=Failed;]Error: Fehler beim Herstellen einer Verbindung mit dem Remotecomputer. Überprüfen Sie die SSH-Dienstverbindungsdetails. TypeError: Cannot read property 'getPrivatePEM' of undefined.
2024-03-11T12:21:02.3369673Z ##[debug]Closing the client connection
2024-03-11T12:21:02.3370391Z ##[debug]Task successfully accomplished
2024-03-11T12:21:02.3490579Z ##[section]Dateien sicher auf den Remotecomputer kopieren wird fertiggstellt

Repro steps

No response

DmitriiBobreshev commented 8 months ago

Hi @jonaskohl, Thank you for the feedback!

The CopyFilesOverSSHV0 task uses SSH service connection with the private key inside. Please make sure that the uploaded private key is valid with the correct host and username.

Based on the log I see that you have privateKey field in your connection, but, the error is located in ssh2 library when the library tries to parse key and, probably confuses the passed key with another and returns wrong instance.

So, could you check that you uploaded/pasted the private key exactly and could you please specify, did you used the file or pasted the key into the field?

jonaskohl commented 8 months ago

The private key is correct for the given host and user. I pasted the key's contents (in PEM format) into the private key textbox inside of the Servie Connection settings

jonaskohl commented 7 months ago

I just tried by writing a small node script that utilizes ssh2 directly and that works without problem.

const { readFileSync } = require('fs');

const { Client } = require('ssh2');

const conn = new Client();
conn.on('ready', () => {
    console.log('Client :: ready');
    conn.exec('uptime', (err, stream) => {
        if (err) throw err;
        stream.on('close', (code, signal) => {
            console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
            conn.end();
        }).on('data', (data) => {
            console.log('STDOUT: ' + data);
        }).stderr.on('data', (data) => {
            console.log('STDERR: ' + data);
        });
    });
}).connect({
    host: [REDACTED],
    port: 22,
    username: [REDACTED],
    privateKey: readFileSync('./id_ed25519')
});

BTW, this issue seems to be affecting the SSHv0 (Version 0.200.0) as well

DmitriiBobreshev commented 7 months ago

@jonaskohl, thanks for the check! We are working on more prioritized issues at the moment, but will get back to this one soon!

linkych commented 7 months ago

Hi there. I'd appreciate fixing this problem, as it blocks our work.

linkych commented 7 months ago

@jonaskohl The workaround for me is to recreate a new service connection without pasting the ssh key, login with a password only

jonaskohl commented 7 months ago

This sadly is not an option for me/my company for security reasons. The remote SSH user does not allow password login, so authentication has to happen via SSH keys.

linkych commented 7 months ago

Hello, @DmitriiBobreshev I wonder whether to you have any ETA regarding this bug?

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

jonaskohl commented 1 month ago

Still no updates after almost half a year?