Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom username for SSH git deployment #1254

Merged
merged 2 commits into from Nov 6, 2021

Conversation

bztes
Copy link
Contributor

@bztes bztes commented Nov 6, 2021

Problem
GIT deployment via SSH throws an authorization error if the SSH username is different from 'git'. This happens because the ssh username is hard coded and not taken from the URL

Fix
Changed the implementation of the URL sanitizer to take the SSH username from the URL.

Implementation
Sanitizing is done in two steps: 1. extract the individual parts from the input URL via a regex (domain, port, repo, ...). 2. construct a new URL by putting the parts together. For the input URL only the domain name and repo name needs to be provided. All other parts of the URL are optional. Default SSH username is 'git' and default port is '22'. '.git' suffix is optional as well.

Copy link
Collaborator

@githubsaturn githubsaturn left a comment

Choose a reason for hiding this comment

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

Perfect! Thanks!

@@ -10,6 +10,22 @@ import Utils from './Utils'
const exec = util.promisify(childPross.exec)

export default class GitHelper {
static #SSH_PATH_RE = new RegExp(
Copy link
Collaborator

Choose a reason for hiding this comment

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

The common practice across the codebase is to use private - rather than # prefix.
It's a minor change, I'll make the change this after merge.

@githubsaturn githubsaturn merged commit 2651ee2 into caprover:master Nov 6, 2021
@githubsaturn
Copy link
Collaborator

@bztes - please see #1863. I've fixed the issue in c174183

But my regex knowledge is same as a 5 year old... please review and patch if needed.

@maietta
Copy link

maietta commented Aug 30, 2023

If help with regular expressions are needed, I'm an expert and I'll be glad to help in my free time. Just let me know.

@githubsaturn
Copy link
Collaborator

githubsaturn commented Aug 30, 2023

@maietta thanks! Feel free to review my changes in the commit linked above and let me know if I did anything dumb :) it's a super naive change, but i read regex the same way i read gibberish 😆

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.

None yet

3 participants