@@ -13,11 +13,13 @@ import (
1313 "github.com/google/uuid"
1414 "github.com/keybase/bot-ssh-ca/src/kssh"
1515 "github.com/keybase/bot-ssh-ca/src/shared"
16+ log "github.com/sirupsen/logrus"
1617
1718 "golang.org/x/crypto/ssh"
1819)
1920
2021func main () {
22+ kssh .InitLogging ()
2123 team , remainingArgs , action , err := handleArgs (os .Args [1 :])
2224 if err != nil {
2325 fmt .Printf ("Failed to parse arguments: %v\n " , err )
@@ -29,7 +31,9 @@ func main() {
2931 os .Exit (1 )
3032 }
3133 if isValidCert (keyPath ) {
34+ log .WithField ("keyPath" , keyPath ).Debug ("Reusing unexpired certificate" )
3235 doAction (action , keyPath , remainingArgs )
36+ os .Exit (0 )
3337 }
3438 config , err := getConfig (team )
3539 if err != nil {
@@ -80,6 +84,7 @@ var cliArguments = []kssh.CLIArgument{
8084 {Name : "--set-default-user" , HasArgument : true },
8185 {Name : "--clear-default-user" , HasArgument : false },
8286 {Name : "--help" , HasArgument : false },
87+ {Name : "-v" , HasArgument : false , Preserve : true },
8388}
8489
8590func generateHelpPage () string {
@@ -93,7 +98,8 @@ VERSION:
9398 0.0.1
9499
95100GLOBAL OPTIONS:
96- --help, Show help
101+ --help Show help
102+ -v Enable kssh and ssh debug logs
97103 --provision Provision a new SSH key and add it to the ssh-agent. Useful if you need to run another
98104 program that uses SSH auth (eg scp, rsync, etc)
99105 --set-default-bot Set the default bot to be used for kssh. Not necessary if you are only in one team that
@@ -171,6 +177,9 @@ func handleArgs(args []string) (string, []string, Action, error) {
171177 fmt .Println (generateHelpPage ())
172178 os .Exit (0 )
173179 }
180+ if arg .Argument .Name == "-v" {
181+ log .SetLevel (log .DebugLevel )
182+ }
174183 }
175184 return team , remaining , action , nil
176185}
@@ -249,7 +258,7 @@ func isValidCert(keyPath string) bool {
249258
250259// Provision a new signed SSH key with the given config
251260func provisionNewKey (config kssh.ConfigFile , keyPath string ) error {
252- fmt . Println ("Generating a new SSH key..." )
261+ log . Debug ("Generating a new SSH key..." )
253262 err := sshutils .GenerateNewSSHKey (keyPath , true , false )
254263 if err != nil {
255264 return fmt .Errorf ("Failed to generate a new SSH key: %v" , err )
@@ -264,13 +273,15 @@ func provisionNewKey(config kssh.ConfigFile, keyPath string) error {
264273 return fmt .Errorf ("Failed to generate a new UUID for the SignatureRequest: %v" , err )
265274 }
266275
276+ log .Debug ("Requesting signature from the CA...." )
267277 resp , err := kssh .GetSignedKey (config , shared.SignatureRequest {
268278 UUID : randomUUID .String (),
269279 SSHPublicKey : string (pubKey ),
270280 })
271281 if err != nil {
272282 return fmt .Errorf ("Failed to get a signed key from the CA: %v" , err )
273283 }
284+ log .Debug ("Received signature from the CA!" )
274285
275286 err = ioutil .WriteFile (shared .KeyPathToCert (keyPath ), []byte (resp .SignedKey ), 0600 )
276287 if err != nil {
@@ -291,7 +302,7 @@ func runSSHWithKey(keyPath string, remainingArgs []string) {
291302 }
292303 if user != "" {
293304 useConfig = true
294- err = kssh .CreateDefaultUserConfigFile ()
305+ err = kssh .CreateDefaultUserConfigFile (keyPath )
295306 if err != nil {
296307 fmt .Printf ("Failed to set default user: %v\n " , err )
297308 os .Exit (1 )
@@ -305,13 +316,11 @@ func runSSHWithKey(keyPath string, remainingArgs []string) {
305316 os .Exit (1 )
306317 }
307318
308- // A new line to separate kssh output from ssh output
309- fmt .Printf ("\n " )
310-
311319 argumentList := []string {"-i" , keyPath , "-o" , "IdentitiesOnly=yes" }
312320 checkAndWarnOnUnspecifiedBehavior (useConfig , remainingArgs )
313321 if useConfig {
314322 argumentList = append (argumentList , "-F" , kssh .AlternateSSHConfigFile )
323+ log .WithField ("user" , user ).Debug ("Using default ssh user" )
315324 }
316325
317326 argumentList = append (argumentList , remainingArgs ... )
@@ -333,7 +342,7 @@ func checkAndWarnOnUnspecifiedBehavior(useConfig bool, arguments []string) {
333342 if useConfig {
334343 for _ , arg := range arguments {
335344 if arg == "-F" {
336- fmt . Println ("Warning: You passed a -F flag, but kssh also uses this argument in " +
345+ log . Warn ("Warning: You passed a -F flag, but kssh also uses this argument in " +
337346 "order to implement support for a default SSH username, which you're also using. " +
338347 "Either do not use the -F flag or run `kssh --clear-default-user` to reset the " +
339348 "default SSH user and delegate this to the running CA bot." )
0 commit comments