Skip to content

Provide a way to preset GUI credentials with password hashing #8021

Closed

Description

@acolomb

Syncthing's default configuration does not have GUI authentication set up. As noted on the forum and in SynoCommunity/spksrc#4875, it would be advisable to set a user / password combination before first starting Syncthing. Especially on headless systems (like NAS) which need to have a liberal GUI listen address and therefore just installing and starting Syncthing would open a big security hole without authentication.

Presetting the credentials is possible in principle through a barebones config.xml, but in practice turning a password into a bcrypt hash is not always easy. Neither should any external tooling depend on Syncthing's internal config XML structure.

The suggestion is to add a new syncthing cli command, or a separate binary altogether, which accepts a user name and password from the command line or standard input. It then patches that into a specified config.xml file, re-using the internal configuration handling code. Ideally it should also indicate through its exit code whether the config file is valid and normalize it when writing.

The existing method through the REST API cannot be used for this, as it needs to happen before the background service is started. At least with the SPK packages for a Synology NAS, possibly also in other deployment scenarios.

Activity

  1. added
    enhancement
    needs-triage
    on Oct 26, 2021
  2. bt90 commented on Oct 26, 2021

    @bt90
    Contributor

    Could we introduce a commandline flag for the regular syncthing binary like e.g -force-gui-auth ?

    If the flag is present and authentication has not been setup previously, syncthing should create new credentials and persist them in the config.

    As the config only contains the hash, we would need to provide the cleartext password somehow. The question is if we can simply log the created credentials.

  3. acolomb commented on Oct 26, 2021

    @acolomb
    MemberAuthor

    Good idea about the flag to prevent the security hole. But I think the user experience is really bad if the user doesn't supply the password, but has to find an automatically generated one, then log in and change it. At least on SynoCommunity, there are many packages asking for credentials during setup to protect some software's admin GUI. I'd like to stick to that pattern, so the only missing component in that case is the bcrypt hashing and (offline) config.xml manipulation. I wouldn't know how to display the generated credentials to the user after the service has been started for the first time -- that happens after setup.

  4. bt90 commented on Oct 26, 2021

    @bt90
    Contributor

    A web based setup triggered via commandline flag would be the best solution for the user. e.g https://10.0.0.2:8384/setup

    This is also what Nextcloud offers with their web installer.

  5. acolomb commented on Oct 26, 2021

    @acolomb
    MemberAuthor

    What environment / workflow do you have in mind for this?

    I can speak for Synology's DSM that it would be much more difficult than what I am working on, where this issue would be the last missing puzzle piece.

  6. calmh commented on Oct 26, 2021

    @calmh
    Member

    There is a syncthing [serve] --generate which probably should be syncthing generate and which could take --gui-auth-user user --gui-auth-password password type things.

  7. acolomb commented on Oct 26, 2021

    @acolomb
    MemberAuthor

    There is a syncthing [serve] --generate which probably should be syncthing generate and which could take --gui-auth-user user --gui-auth-password password type things.

    Right, that sounds like a useful extension. What does it do if the config is already there? Will it overwrite existing certificates? I don't intend to use it on upgrades, only installation. But better safe than sorry when it comes to losing keys.

  8. calmh commented on Oct 26, 2021

    @calmh
    Member
    jb@kvin:~ % syncthing --generate tmp/foo
    14:03:50 INFO: Device ID: CB3XYZC-LU3GLEE-RCB36VE-ROAC7LJ-PM25V6Q-ORNWXTD-DWM7LEU-WQCZKAQ
    14:03:50 INFO: Default folder created and/or linked to new config
    jb@kvin:~ % syncthing --generate tmp/foo
    14:03:51 WARNING: Key exists; will not overwrite.
    14:03:51 INFO: Device ID: CB3XYZC-LU3GLEE-RCB36VE-ROAC7LJ-PM25V6Q-ORNWXTD-DWM7LEU-WQCZKAQ
    14:03:51 WARNING: Config exists; will not overwrite.
    jb@kvin:~ %
    

    Though if it gains parameters it might make sense to make the config step a read-modify-write to apply those parameters. That would also make it a password reset / recover utility.

  9. acolomb commented on Oct 26, 2021

    @acolomb
    MemberAuthor

    Great idea, I think I would manage to implement such an addition. Thanks for the pointer.

    Should we also do the rename from a flag to a subcommand then?

  10. calmh commented on Oct 26, 2021

    @calmh
    Member

    Yeah, I'd break it out into a sub command. Bonus points, if it's easy, to retain the current switch as an alias for compatibility, but not if it's not easy.

  11. acolomb commented on Oct 26, 2021

    @acolomb
    MemberAuthor

    I'm a bit confused about the different subcommand implementations. There's alecthomas/kong being used mainly, but also urfave/cli for the cli subcommand (probably because kong does not play well with auto-generated options). I assume integration with kong is easier, but if you prefer urfave/cli for future additions, I will comply. And I suppose a separate package is not needed, like for decrypt?

  12. calmh commented on Oct 26, 2021

    @calmh
    Member

    kong is the thing. cli uses something else for historical reasons as it (vastly) predates subcommands in Syncthing and also kong itself. I'd put it in a separate package like decrypt so that all non-serve subcommands live in separate packages under cmd/syncthing.

  13. acolomb commented on Oct 26, 2021

    @acolomb
    MemberAuthor

    Thanks, will do. This is the draft structure then:

    acolomb@barnov:~/src/syncthing/bin$ ./syncthing --help generate
    Usage: syncthing generate
    
    Generate key and config, then exit
    
    Flags:
      -h, --help                   Show context-sensitive help.
    
          --no-console             Hide console window
          --config=PATH            Set configuration directory (config and keys)
          --home=PATH              Set configuration and data directory
          --no-default-folder      Don't create the "default" folder on first startup ($STNODEFAULTFOLDER)
          --gui-user=STRING        Override GUI authentication user name
          --gui-password=STRING    Override GUI authentication password (use - to read from standard input)
    

    This reuses the common --home and --config parameters for consistency, and uses the default location if none is supplied. We could converge on only --config here as compatibility doesn't matter, but user habit may be enough reason?

  14. acolomb commented on Oct 26, 2021

    @acolomb
    MemberAuthor

    Sorry, one more technical question about Go packages: If I want to use a common options structure from the cmd/syncthing main package within cmd/syncthing/generate, how to do that without an import cycle? Same goes for the convenience function ensureDir(). Copy it? Factor out to own package? Right now it seems a separate package brings much more headaches than just another struct in main.go...

    Logging is another pain point: decrypt uses log directly, while serve has its fancy logger which is used e. g. in ensureDir() so that's not easily moved to a utility package.

  15. 3 remaining items

  16. AudriusButkevicius commented on Oct 30, 2021

    @AudriusButkevicius
    Member

    I'd be wary of passing passwords on the commandline, given things like bash history etc. Reading it from stdin would be better.

  17. acolomb commented on Oct 30, 2021

    @acolomb
    MemberAuthor

    I'd be wary of passing passwords on the commandline, given things like bash history etc. Reading it from stdin would be better.

    That is a first-class consideration I have already implemented in my prototype. Will make a PR when it's cleaned up.

  18. acolomb commented on Oct 31, 2021

    @acolomb
    MemberAuthor

    I'm a little bit stuck in my implementation when trying to actually modify the config. If there is no file yet, syncthing.DefaultConfig() gives us a config.Wrapper. I would do the same when it does exist by calling config.Load(). But that wrapper doesn't really work for modifications unless I start its Serve() method with a new context etc. That seems overly complicated all in all, just to open an XML file, modify two tags, and write it back. Note this subcommand is just a simple, single-threaded script context where there are no services running and thus no Committers to take care of.

    Do you think using the ReadXML() / WriteXML() functions directly for the generate subcommand would suffice? Or is there a simpler way to actually make use of the config.Wrapper?

  19. calmh commented on Nov 1, 2021

    @calmh
    Member

    Getting a wrapper, stating it's serve method and doing modification seem the cleanest solution to me.

  20. self-assigned this
    on Nov 8, 2021
  21. removed
    needs-triage
    on Nov 8, 2021
  22. acolomb commented on Nov 8, 2021

    @acolomb
    MemberAuthor

    I'm waiting on #8028 to get merged so I can rebase my branch for this and make a PR. Any chance that can happen before .rc1?

  23. added a commit that references this issue on Nov 18, 2021
    100870e
  24. added 2 commits that reference this issue on Nov 22, 2021
    d1a36c2
    a9c9fb1
  25. added this to the v1.18.5 milestone on Nov 23, 2021
  26. added
    frozen-due-to-age
    on Mar 10, 2023
  27. locked and limited conversation to collaborators on Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementfrozen-due-to-age

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions