Skip to content

Add ability to run WP-CLI commands over SSH#2327

Merged
luismulinari merged 8 commits into
trunkfrom
wp-cli-command-over-ssh
Apr 24, 2025
Merged

Add ability to run WP-CLI commands over SSH#2327
luismulinari merged 8 commits into
trunkfrom
wp-cli-command-over-ssh

Conversation

@luismulinari
Copy link
Copy Markdown
Contributor

@luismulinari luismulinari commented Apr 18, 2025

Description

This PR introduces a new feature for executing WP-CLI commands via SSH instead of using websockets.

Pull request checklist

New release checklist

Steps to Test

  1. Check out PR.
  2. Run npm run build
  3. node ./dist/bin/vip-wp.js <site> --yes -- user list

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 18, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails
npm/@types/ssh2 ^1.15.4 🟢 6.9
Details
CheckScoreReason
Code-Review🟢 8Found 25/29 approved changesets -- score normalized to 8
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
License🟢 9license file detected
Security-Policy🟢 10security policy file detected
Signed-Releases⚠️ -1no releases found
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration
Vulnerabilities🟢 100 existing vulnerabilities detected
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
Binary-Artifacts🟢 10no binaries found in the repo
Pinned-Dependencies🟢 8dependency not pinned by hash detected -- score normalized to 8
Fuzzing⚠️ 0project is not fuzzed
npm/ssh2 1.16.0 🟢 4.3
Details
CheckScoreReason
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Code-Review⚠️ 0Found 0/30 approved changesets -- score normalized to 0
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Packaging⚠️ -1packaging workflow not detected
Maintained🟢 103 commit(s) and 11 issue activity found in the last 90 days -- score normalized to 10
SAST⚠️ 0no SAST tool detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Security-Policy⚠️ 0security policy file not detected
Vulnerabilities🟢 100 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
Binary-Artifacts🟢 9binaries present in source code
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Fuzzing⚠️ 0project is not fuzzed
Branch-Protection⚠️ 0branch protection not enabled on development/release branches

Scanned Files

  • package.json

Comment thread src/commands/wp.ts Outdated
Comment thread src/bin/vip-wp.js Outdated

let countSIGINT = 0;

if ( ! opts.env.isK8sResident ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do an explicit check that it's a WP Cloud site?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/commands/wp.ts Outdated
luismulinari and others added 2 commits April 22, 2025 11:09
Co-authored-by: abdullah-kasim <abdullah.kasim@automattic.com>
Co-authored-by: Mohammad Jangda <mo@automattic.com>
Comment thread src/bin/vip-wp.js Fixed
@luismulinari luismulinari force-pushed the wp-cli-command-over-ssh branch from c0055cb to 3ab374e Compare April 22, 2025 23:14
@luismulinari luismulinari marked this pull request as ready for review April 22, 2025 23:18
@luismulinari luismulinari requested a review from mjangda April 22, 2025 23:18
Copy link
Copy Markdown
Member

@mjangda mjangda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted some minor things but overall, this looks great.

Comment thread src/bin/vip-wp.js Outdated
Comment thread src/commands/wp.ts
@@ -0,0 +1,255 @@
/**
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Should we give this file a more specific name, like wp-ssh.ts?

Comment thread src/commands/wp.ts Outdated

debug( "Requesting SSH authentication for command '%s'", command );

const sshAuth = await getSSHAuthForCommand( this.app.id, this.env.id, command );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this in a try-catch to handle failures more gracefully?

Comment thread src/commands/wp.ts Outdated
message: 'Error executing command over SSH',
} );

throw new Error( message );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of throwing, should we just be exiting?

Suggested change
throw new Error( message );
process.exit( 1 );

Comment thread src/commands/wp.ts
if ( ! this.app.id || ! this.env.id ) {
await this.track( 'error', {
error: 'no_app_env_id',
message: 'No app or env ID provided',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In src/bin/vip-wp.js, we also include a stripped down version of the command. Should we do that here as well? This can be done in a separate PR.

luismulinari and others added 2 commits April 23, 2025 16:05
Co-authored-by: Mohammad Jangda <mo@automattic.com>
@sonarqubecloud
Copy link
Copy Markdown

@luismulinari luismulinari merged commit 37adbd9 into trunk Apr 24, 2025
18 checks passed
@luismulinari luismulinari deleted the wp-cli-command-over-ssh branch April 24, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants