Repository navigation
feat(api): magic token authentication from syncthing browse - #10810
Conversation
|
Can you elaborate a bit more on what problem this actually solves? The thing I see is that we have authentication via HTTP Does that sound about right? If so, when does this "one-time" token expire then? |
|
Yep, that's indeed how it works and why this adds another type of token. The token is invalidated immediately when used, and expires in 10 seconds otherwise. This was inspired by how mitmproxy opens its web UI. |
|
I didn't actually check how mitmproxy does this before writing this PR. Just checked and it turns out that it generates a single random secret and makes no effort to remove it from browser history :P so this is basically cutting-edge security |
|
Thanks for the confirmation. I think this is a sane approach, but let's hear opininons from other @syncthing/maintainers. I have only glanced over the code, will take another thorough review once the goal is sanctioned and the code fixed to pass CI. |
ca7562c to
227605e
Compare
|
Build and lint fixed, PTAL |
syncthing browsesyncthing browse
acolomb
left a comment
There was a problem hiding this comment.
The code looks good, except for a few nits / clarifications.
Since this is a security-critical path, I definitely cannot vouch for it alone though. Need a second pair of eyes over it, with more Go and REST auth experience.
| } | ||
| u.Path = path.Join(u.Path, "rest/system/upgrade") | ||
| target := u.String() | ||
| r, _ := http.NewRequestWithContext(context.TODO(), http.MethodPost, target, nil) |
There was a problem hiding this comment.
What's the thing with context.TODO() here? If none is needed, then just use NewRequest() as before. What am I missing?
There was a problem hiding this comment.
Purely to shut up golangci-lint :P but i could write a //nolint instead.
There was a problem hiding this comment.
What does the linter think is wrong with not using a context? I'd rather have some linter complaining instead of introducing a non-actionable "TODO" in the code.
There was a problem hiding this comment.
The lint message is from https://github.com/sonatard/noctx and says net/http.NewRequest must not be called. use net/http.NewRequestWithContext XD
There was a problem hiding this comment.
Switching to //nolint, there are already a few //nolint:noctx in the codebase in fact
There was a problem hiding this comment.
I still don't get why that linter sees this as an anti-pattern. Not an expert on Go contexts, but it sounds like enforcing some kind of API convention for libraries onto something that is not a library. In this case, I see no value in the suggested "fix" and adding a nolint is a distraction which only indicates inconsiderate linter usage.
There was a problem hiding this comment.
Well, for this PR to pass CI I'll need to either add //nolint or modify the linter config to disable the lint, perhaps for a subsection of the codebase. That sounds something that would require extensive discussion, so I'll file a new issue, and leave this as //nolint for now.
(I was going to file it as a PR, but PR creation is disabled for me. Could I get onboarded as someone with permission to create PRs? I was expecting to send some follow up PRs for the magic token feature in particular.)
Edit: is github issues the right place for the discussion? it doesn't fit either of the allowed issue templates.
There was a problem hiding this comment.
It's fine to keep the //nolint comment for now. I'm just a bit allergic to over-eager linters with questionable opinions. :-)
I'd say discussion about the wider topic should happen on our forum. But don't take my opinion as requiring a change. Code policy is mainly decided by @calmh. Who can also onboard you as a contributor I suppose.
227605e to
ddb952d
Compare
Signed-off-by: tbodt <[email protected]>
|
Thanks for the fixes, but please make additional commits instead of squashing in the future. Makes for an easier incremental review. |
ddb952d to
e9b85da
Compare
|
Sorry, missed your comment before the last force push, will add commits in the future |
| // fork, and just execs, hence keep it in its own routine. | ||
| go func() { _ = openURL(cfgWrapper.GUI().URL()) }() | ||
| go func() { | ||
| cmd := browserCmd{Verify: true} |
There was a problem hiding this comment.
I see the desire to re-use existing code paths, but I guess there must have been a reason this previously used openURL directly? For one, we didn't have a "browser" subcommand as such on the CLI once upon a time...
Can you please explain why you think the extra steps taken in browserCmd.Run() (especially API verification) are harmless in contrast to the previous direct invocation? Of course this approach is needed for your auto-login addition, that's clear.
There was a problem hiding this comment.
Yes this is just to trigger the auto login code that's part of the browser command. The only extra step that this adds beyond that is verification, which to me seems harmless.
There was a problem hiding this comment.
...why is it harmless? Because the auth code is about to do more or less the same thing anyway...wait, the verification code will exit the process if it fails and the auth code will just end up logging an error, and that could be bad because the current process is running the server. Might as well switch verification to false.
Signed-off-by: tbodt <[email protected]>
Signed-off-by: tbodt <[email protected]>
|
What about the failing tests now? Just flaky, or is that pointing to a failure mode involving the changed timing, because they may not be using |
|
Looks like just a preexisting flake, the test in question has a comment about it: "This test needs a longer-than-default shutdown timeout to finish saving config changes when running on GitHub Actions". Pushed an empty commit and it all passes. |
|
LGTM. Thanks for keeping up with the review process! |
Signed-off-by: tbodt <[email protected]>
… someone decides to use Consume with other kinds of tokens! Signed-off-by: tbodt <[email protected]>
0a88ed8 to
699fa34
Compare
Signed-off-by: tbodt <[email protected]>
|
Just used github copilot to look for security bugs, and didn't find any, but it did inspire a few small fixes which I just pushed. |
|
Please don't force push. ;-) Thanks for the small fixes, looks good. |
|
@calmh OK to merge from my side. WDYT? |
* main: fix: invalid files on remote devices are not "available" (fixes syncthing#10943) (syncthing#10944) feat(api): magic token authentication from `syncthing browse` (syncthing#10810) chore(gui, man, authors): update docs, translations, and contributors fix(model): skip ignored folders when auto-accepting (fixes syncthing#10935) fix(model): properly compare blocks when reconciling receive-only (fixes syncthing#10928) (syncthing#10929)
Purpose
Syncthing's authentication options have seemed sort of lacking to me for a while. I can choose between no authentication (and now the admin interface is accessible to theoretically every website I visit), or password authentication (why do I need a password? it's all on one computer!). This PR adds magic tokens with which the
syncthing browseandsyncthing servecommands can magically log you in.I hope that adding this and refining it enough will make it eventually possible to change the default from "zero auth" to "token auth only".
Testing
Some unit tests, and manually tested using syncthing browser and syncthing serve, both of which create a token when they open the browser.
Documentation
TODO