Skip to content

Enhance ssh auth options#495

Closed
alcastronic wants to merge 1 commit intogitleaks:masterfrom
alcastronic:ssh-auth-options
Closed

Enhance ssh auth options#495
alcastronic wants to merge 1 commit intogitleaks:masterfrom
alcastronic:ssh-auth-options

Conversation

@alcastronic
Copy link

@alcastronic alcastronic commented Dec 21, 2020

Description:

Currently gitleaks only has support for ssh keys without a pasphrase. This PR adds the ability to specify the passphrase
for an ssh key via the command line. The password will be retrieved by syscall.Stdin hence the import syscall was added.
Furthermore functionallity to support ssh agent authentication is added via the NewSSHAgentAuth function from go-git.

Fixes #263 How to pass SSH key password as argument?

ssh key with passphrase

It is possible to use an ssh key with passphrase either by specifing an ssh key with the --ssh-key= option or
use the default key file location. The ssh passphrase will be retrieved in an interactive prompt when the flag --ssh-pass
is specified on the commandline.

Specify an ssh key and ask for the passphrase.

# ./build/gitleaks-linux-amd64 --ssh-key=/home/tronic/.ssh/id_rsa --ssh-pass -r git@github.com:zricethezav/gitleaks.git    
Enter Password: 
INFO[0004] cloning... git@github.com:zricethezav/gitleaks.git     
INFO[0024] scan time: 17 seconds 770 milliseconds 891 microseconds     
INFO[0024] commits scanned: 612                             
WARN[0024] leaks found: 745    

ssh key default location and passphrase

When the --ssh-key option is ommitted the default key location under /home/$user/.ssh/id_rsa will be used.

./build/gitleaks-linux-amd64 --ssh-pass -r git@github.com:zricethezav/gitleaks.git    
Enter Password: 
INFO[0005] cloning... git@github.com:zricethezav/gitleaks.git     
INFO[0032] scan time: 17 seconds 883 milliseconds 37 microseconds     
INFO[0032] commits scanned: 612                           
WARN[0032] leaks found: 745    

ssh agent

It is also possible to authenticate with an ssh agent.

  1. Add the private key to the local ssh agent
  2. Execute gitleaks with the --ssh-agent option

When the ssh agent option is used gitleaks opens a channel to the local ssh agent.

 ./build/gitleaks-linux-amd64 --ssh-agent -r git@github.com:zricethezav/gitleaks.git    
INFO[0000] cloning... git@github.com:zricethezav/gitleaks.git     
INFO[0021] scan time: 17 seconds 783 milliseconds 151 microseconds     
INFO[0021] commits scanned: 612                           
WARN[0021] leaks found: 745     

Checklist:

  • Does your PR pass tests?
  • Have you written new tests for your changes? No
  • Have you lint your code locally prior to submission? No

@Tomy2e Tomy2e mentioned this pull request Mar 10, 2021
3 tasks
@adrianbn
Copy link

This and #536 seem to be working on similar problems are are both very useful features. Is there anything I can do to help get these merged?

@w0rmr1d3r
Copy link
Contributor

Hello @alcastronic & @adrianbn !

Can we resolve the conflicts?
I've seen the PR and looks quite good!

Cheers!

@zricethezav
Copy link
Collaborator

zricethezav commented Nov 23, 2021

gitleaks does not clone in v8

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.

How to pass SSH key password as argument?

4 participants