Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-3243

Tools produce error about missing password after prompting for a password

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 100.7.0
    • Affects Version/s: None
    • Component/s: All Tools
    • None

      Problem Statement/Rationale

      From a Slack discussion:

      try and authentication with PLAIN mech and observe the error within the driver via the call to opts.ConnString.Validate() .
      $ ./bin/mongotop --host localhost --port 27017 --authenticationMechanism PLAIN --ssl --username admin 5
      Enter password for mongo user:

      2023-02-06T12:20:39.949-0500 error parsing command line options: password required for PLAIN
      2023-02-06T12:20:39.949-0500 try 'mongotop --help' for more information

      Steps to Reproduce

      See above

      Expected Results

      The password provided to the prompt should be used.

      Actual Results

      See above

      Additional Notes

      John proposed this patch:

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      diff --git a/common/options/options.go b/common/options/options.go
      index 3c8661e5..d5687b77 100644
      --- a/common/options/options.go
      +++ b/common/options/options.go
      @@ -668,6 +668,15 @@ func (opts *ToolOptions) setURIFromPositionalArg(args []string) ([]string, error
       // connection string. If a value is set on the connection string, but not the options,
       // that value is added to the options.
       func (opts *ToolOptions) NormalizeOptionsAndURI() error {
      +       // finalize auth options, filling in missing passwords
      +       if opts.Auth.ShouldAskForPassword() {
      +               pass, err := password.Prompt("mongo user")
      +               if err != nil {
      +                       return fmt.Errorf("error reading password: %v", err)
      +               }
      +               opts.Auth.Password = pass
      +       }
      +
              if opts.URI == nil || opts.URI.ConnectionString == "" {
                      // If URI not provided, get replica set name and generate connection string
                      _, opts.ReplicaSetName = util.SplitHostArg(opts.Host)
      @@ -687,15 +696,6 @@ func (opts *ToolOptions) NormalizeOptionsAndURI() error {
                      return err
              }
       
      -       // finalize auth options, filling in missing passwords
      -       if opts.Auth.ShouldAskForPassword() {
      -               pass, err := password.Prompt("mongo user")
      -               if err != nil {
      -                       return fmt.Errorf("error reading password: %v", err)
      -               }
      -               opts.Auth.Password = pass
      -       }
      -
              shouldAskForSSLPassword, err := opts.SSL.ShouldAskForPassword()
              if err != nil {
                      return fmt.Errorf("error determining whether client cert needs password: %v", err)}}
      

      But from discussion in Slack, this may not be right:

      I’m not sure it is [right]. We shouldn’t check if we need to prompt for the password before we parse the connstring. Otherwise we ignore passwords set in the connstring. I think the correct solution here is to set the password in the connstring as well as the opts once we get it from the prompt.

            Assignee:
            dave.rolsky@mongodb.com Dave Rolsky
            Reporter:
            dave.rolsky@mongodb.com Dave Rolsky
            Evgeni Dobranov, Tim Fogarty
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: