You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a way to preset GUI credentials with password hashing #8021
enhancementNew features or improvements of some kind, as opposed to a problem (bug)frozen-due-to-ageIssues closed and untouched for a long time, together with being locked for discussion
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.
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.
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.
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.
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.
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.
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.
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.
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?
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.
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?
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.
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?
enhancementNew features or improvements of some kind, as opposed to a problem (bug)frozen-due-to-ageIssues closed and untouched for a long time, together with being locked for discussion
Activity
bt90 commentedon Oct 26, 2021
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.
acolomb commentedon Oct 26, 2021
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.xmlmanipulation. 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.bt90 commentedon Oct 26, 2021
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.
acolomb commentedon Oct 26, 2021
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.
calmh commentedon Oct 26, 2021
There is a
syncthing [serve] --generatewhich probably should besyncthing generateand which could take--gui-auth-user user --gui-auth-password passwordtype things.acolomb commentedon Oct 26, 2021
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.
calmh commentedon Oct 26, 2021
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.
acolomb commentedon Oct 26, 2021
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?
calmh commentedon Oct 26, 2021
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.
acolomb commentedon Oct 26, 2021
I'm a bit confused about the different subcommand implementations. There's
alecthomas/kongbeing used mainly, but alsourfave/clifor theclisubcommand (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?calmh commentedon Oct 26, 2021
kongis the thing.cliuses something else for historical reasons as it (vastly) predates subcommands in Syncthing and alsokongitself. I'd put it in a separate package likedecryptso that all non-servesubcommands live in separate packages undercmd/syncthing.acolomb commentedon Oct 26, 2021
Thanks, will do. This is the draft structure then:
This reuses the common
--homeand--configparameters for consistency, and uses the default location if none is supplied. We could converge on only--confighere as compatibility doesn't matter, but user habit may be enough reason?acolomb commentedon Oct 26, 2021
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 inmain.go...Logging is another pain point:
decryptuseslogdirectly, whileservehas its fancy logger which is used e. g. inensureDir()so that's not easily moved to a utility package.3 remaining items
AudriusButkevicius commentedon Oct 30, 2021
I'd be wary of passing passwords on the commandline, given things like bash history etc. Reading it from stdin would be better.
acolomb commentedon Oct 30, 2021
That is a first-class consideration I have already implemented in my prototype. Will make a PR when it's cleaned up.
acolomb commentedon Oct 31, 2021
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 aconfig.Wrapper. I would do the same when it does exist by callingconfig.Load(). But that wrapper doesn't really work for modifications unless I start itsServe()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 theconfig.Wrapper?calmh commentedon Nov 1, 2021
Getting a wrapper, stating it's serve method and doing modification seem the cleanest solution to me.
acolomb commentedon Nov 8, 2021
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?
cmd/syncthing: Implement generate as a subcommand with optional API c…
Merge branch 'main' into ioutil
Merge branch 'main' into conn-test