|
|
Subscribe / Log in / New account

Syncing all the things

By Jonathan Corbet
July 9, 2021
Computing devices are wonderful; they surely must be, since so many of us have so many of them. The proliferation of computers leads directly to a familiar problem, though: the files we want are always on the wrong machine. One solution is synchronization services that keep a set of files up to date across a multitude of machines; a number of companies have created successful commercial offerings based on such services. Some of us, though, are stubbornly resistant to the idea of placing our data in the hands of corporations and their proprietary systems. For those of us who would rather stay in control of our data, systems like Syncthing offer a possible solution.

The core idea behind synchronization systems is essentially the same for all of them: given a list of directories and a list of systems, ensure that those directories have the same contents on each system. If a file is added on one, it is copied out to the rest; modifications and deletions are (usually) propagated as well. The trouble is always in the details, though; from fiddly setup procedures to data corruption and security problems, there are a lot of ways in which synchronization can go wrong. So users have to put a lot of trust in these systems; open source code is an important step toward that goal, but it is also necessary to believe that the developers involved have thought carefully through the issues.

Syncthing

[Syncthing management screen] When the northern-hemisphere summer sets in and fresh news becomes relatively scarce, the opportunity arises to finally get around to checking out an interesting software project or two. Your editor, thus, has been duly playing around with the Syncthing 1.17.0 release, obtained from the Fedora and CentOS (EPEL) repositories. Starting the system on Fedora is just a matter of running the syncthing command to start the synchronization daemon and trying to not be dismayed at the volume of log data generated. The EPEL package, instead, appears to install Syncthing as a systemd user service, meaning that all that was needed was to log into the system and the daemon started automatically.

The daemon is managed through an internal web server that shows up, by default, on port 8384; see the example image on the right. There is initially no authentication required; users will likely want to fix that as one of the first things they do. The web server is, by default, only accessible via the loopback interface; a change to a configuration file can make it available to the Internet as a whole, but that sounds like a daring thing to do even with authentication enabled. An alternative for gaining access to the web interface on a remote machine, as suggested in the documentation, is to set up an SSH tunnel from the local system.

When it starts for the first time, Syncthing generates a "device ID" identifying the local system; it looks like this:

    RS5RZ7K-CORJAP3-TZECYOH-IBLFDZM-KSFWOXB-VBEIYSB-F7MWECH-VQCGLAZ

Setting up synchronization between two machines resembles the Bluetooth pairing process; it is done by providing each side with the device ID belonging to the other. Use of copy-and-paste is advisable here. Alternatively, if both systems are on the same local net, they will discover each other through broadcasts and ask (through the management interface) whether a connection should be established.

After a connection between systems is made, users must tell Syncthing which directories should be synchronized; that is a matter of setting up folders and sharing them with any or all of the known remote systems (which Syncthing calls "devices"). Once the share has been accepted on the remote end, file changes will be propagated back and forth. When possible, Syncthing requests file-change notifications from the kernel; that leads to relatively fast propagation times.

There are a lot of options that can be set to control sharing. Sharing can be made one-way, for example, so that a particular system might create files and send them out without accepting changes from the other systems. One especially interesting (though new and "beta") feature is the ability to share files to specific systems in encrypted form. If one system is, for example, a cloud server that is used primarily for backup or distribution purposes, it can be given encrypted data that it cannot read. Any other system in the sharing network that has the correct password will be able to read those files, though. There are also various ways of handling versioning, which keeps older versions of files around when one system changes them.

It's worth noting that, while it is possible to configure a set of Syncthing clients all connected to a central server, nothing in Syncthing requires that sort of architecture. Systems can be connected in any way that seems to make sense. If a system finds that it needs files that have already propagated to multiple connected peers, it can receive the needed data in blocks, BitTorrent-style, from whichever system can provide it first.

Discovery and security

Interestingly, neither host names nor IP addresses are involved in any stage of the configuration process — by default, at least; the systems find each other based only on the device ID regardless of which networks they are attached to. This, clearly, requires some third-party help. The Syncthing project runs a set of "discovery" servers that will help systems find each other based on their device IDs. There is also a set of "relay servers" that can relay data in situations where the systems involved cannot reach each other directly — when they are both behind NAT firewalls, for example.

Some thought has clearly gone into the security implications of this architecture. Data only goes through relay servers if there is no alternative, for example, and it is encrypted at the endpoints. But there is still some information that a hostile discovery or relay server could obtain that might worry some users. For anybody who is truly worried, the code for both types of server is available; anybody can set up private servers and configure their Syncthing instances to use only those.

According to the documentation, device IDs need not be kept secret, since an affirmative action is required on both sides to set up a connection. One might wonder whether an attacker might try to set up a system with a target's device ID and thus gain access to the managed files. That ID, though, is essentially a public key, and the connection process involves proving possession of the associated private key, so such an attack should not be possible. This page describes device IDs in more detail.

Syncthing on the move

[Syncthing Android app] Perhaps the most common use of synchronization on today's net is copying photos from a phone handset to a central server. Since Android phones, at least, are Linux-based, one need only set up a normal shell environment on it and put Syncthing there to achieve this goal; the process shouldn't take more than a day or so. Or one could just install the Android app, which is available on F-Droid and the Google Play Store as well. This app, shown on the right, comes with a folder for the camera (set for send-only sharing) configured out of the box, so it is just a matter of setting up the peers. And, lest one worry about typing one of those device IDs with an on-screen keyboard, the app can read the QR code that the web interface will helpfully provide, easing that process considerably.

One slightly surprising behavior is that the app asks for location permission, which doesn't seem like something it would need. That permission is needed to determine which WiFi network (if any) the phone is on, which is useful for the feature configuring when synchronization should (and should not) be performed. Users of metered WiFi services may want to use this mechanism to avoid synchronization when it could cost them money. In the absence of this permission, the app will, by default, perform synchronization whenever it is connected to any WiFi network.

One need not look far to find complaints from users that the Android app drains the battery quickly. Your editor has not observed this behavior in a limited amount of testing; it is possible that the worst problems have already been fixed.

Closing thoughts

The project states that "security is one of the primary project goals", and the developers do appear to have put some thought into the issue. Encryption is used in the right places, certificates are verified, etc. A quick CVE search turns up two entries over the last four years, one of which enabled the overwriting of arbitrary files. Exploiting that vulnerability would require first gaining control of one of the machines in the sharing network, at which point the battle is likely lost anyway. It does not seem that any sort of formal security audit has been done, but the Syncthing developers are at least making the right kinds of noises.

With regard to reliability, it is not hard to search for (and find) various scary stories from users who have lost data with Syncthing. It seems that many of those problems are the result of operator error; if you set up a system and allow it to delete all your data, it may eventually conclude that you want it to do exactly that. Synchronization can be amazingly efficient at propagating mistakes. Use of versioning can help, as can avoiding the use of two-way synchronization whenever possible. Syncthing doesn't seem like it has a lot of data-losing bugs, but backups are always a good idea.

Syncthing has been syncing things since at least 2013, when the first commit appears in its Git repository; LWN looked at it in 2014. The project is written mostly in Go, and is distributed under the Mozilla Public License. The current Syncthing release is 1.18.0; it came out on July 6 — while this article was being written. The project shows a nearly monthly release cadence in the last year; 1.7.0 was released on July 7, 2020. There have been 728 non-merge commits to the Syncthing repository over the last year from 40 developers; the top three developers (Simon Frei, Jakob Borg, and Jesse Lucas) account for just over 76% of of those commits. The project is thus not swarming with developers, but it appears healthy enough for now.

A company called Kastelo offers support subscriptions for Syncthing and provides significant resources for Syncthing development. The company also is part of the Syncthing Foundation which, in turn, manages the project's infrastructure and makes grants for development projects.

All told, Syncthing leaves a favorable impression. The developers seem to have done the work to create a system that is capable, reliable, secure, and which performs reasonably well. But they have also done the work to make it all easy to set up and make use of — the place where a lot of free-software projects seem to fall down. It is an appealing tool for anybody wanting to take control of their data synchronization and replication needs.


to post comments

Syncing all the things

Posted Jul 9, 2021 15:34 UTC (Fri) by smurf (subscriber, #17840) [Link]

I can only agree. Syncthing does one job, and it does that job very well.

Figuring out why some device doesn't want to talk to some other device is a non-trivial process. That's hardly unique to synthing, though.

Syncing all the things

Posted Jul 9, 2021 19:16 UTC (Fri) by Cyberax (✭ supporter ✭, #52523) [Link]

Love syncthing! I'm using it on a btrfs disk to synchronize the most recent snapshot, so even if you manage to delete all the data, you simply need to roll back to an earlier version.

Syncing all the things

Posted Jul 10, 2021 2:56 UTC (Sat) by felixfix (subscriber, #242) [Link]

My Sync dir is a copy of files I want shared. Some are manually copied, some are automatically copied. I have a nightly cron job which tells me of any discrepancies, and they have always been files which I forgot to manually copy after editing. It's been incredibly reliable. My only problems have come from setting up new phones or computers; their terminology has caught me by surprise several times, but I finally wised up and made some notes, and it no longer surprises me after setup, only before :-)

Every once in a while, I marvel at how it works so smoothly that I almost forget it's running, and send a small contribution. I've thought once or twice of filing a bug report, that it doesn't have enough bugs to remind me of its existence, and they need to find that sweet spot of attracting just enough attention to garner more contributions.

Syncing all the things

Posted Jul 10, 2021 3:33 UTC (Sat) by jkingweb (subscriber, #113039) [Link]

I've been using Syncthing since version 0.12. It's come a really long way since then, and it's become one of my set-it-and-forget-it tools I just don't have to think about.

Sadly the relatively involved initial setup scares off a lot of people I know. There's no good way around that, though.

Syncing all the things

Posted Jul 10, 2021 15:05 UTC (Sat) by tau (subscriber, #79651) [Link] (2 responses)

Syncthing is great, thank you for reminding me to send them another donation. Do note, however, that synchronizing the contents of external storage on an Android device is a tremendous nuisance, though this is through no fault of Syncthing itself.

The issue is fully described in the links below but the gist of it (as I understand it, please correct me if I am wrong) is that recent versions of Android create separate isolated directories for each application on the device's external storage and do not allow access outside that directory using standard POSIX syscalls. If the application has a specific permission then an application can use a separate Java API to access the full external storage directory tree, but this presents integration difficulties for cross-platform applications.

The issue might also be limited to just Android 10, as the previous versions predate this policy and Android 11 supposedly has some mechanism that allows suitably privileged applications to restore POSIX access, but I am unable to verify that. If your device is stuck on Android 10 like mine is then you'll need to use a root backdoor with all the headaches that entails.

https://github.com/syncthing/syncthing-android/issues/29
https://forum.syncthing.net/t/android-11-all-files-access...

Syncing all the things

Posted Jul 11, 2021 12:10 UTC (Sun) by jkingweb (subscriber, #113039) [Link] (1 responses)

There have been complaints about Android filesystem access since Android 4.4 (when Syncthing ceased to be able to access "external" SD cards). Scoped storage is just an extra layer of hell on top of the existing difficulties.

Syncing all the things

Posted Jul 11, 2021 15:00 UTC (Sun) by smurf (subscriber, #17840) [Link]

Well, with 11 they finally seem to have arrived at an interface we can live with.

Yes it's ugly, but so is "any random app can silently exfiltrate basically all of your personal data and images".

Syncing all the things

Posted Jul 10, 2021 20:51 UTC (Sat) by bferrell (subscriber, #624) [Link]

"It just works" uPNP?! Really?!

Syncing all the things

Posted Jul 10, 2021 23:30 UTC (Sat) by tamara_schmitz (guest, #141258) [Link]

I found out today that the versioning mode I selected, didn't retain older revisions... Unfortunate but I fixed that now.

Yeah about that user experience. If the devs want to reach little bigger audience it could use more UX improvements to present you such options that you actually need.

But I've been using Syncthing for 4 years, ran a relay at some point and have always been happy with it.

Syncing all the things

Posted Jul 11, 2021 4:37 UTC (Sun) by alison (subscriber, #63752) [Link]

> Since Android phones, at least, are Linux-based, one need only set up a normal shell
> environment on it and put Syncthing there to achieve this goal; the process shouldn't take > more than a day or so.

Snort! I love LWN.

Syncing all the things

Posted Jul 12, 2021 11:49 UTC (Mon) by jezuch (subscriber, #52988) [Link] (3 responses)

> If one system is, for example, a cloud server that is used primarily for backup or distribution purposes

Is there an easy way to set up such a server?

Syncing all the things

Posted Jul 12, 2021 18:13 UTC (Mon) by smurf (subscriber, #17840) [Link] (2 responses)

> Is there an easy way to set up such a server?

You ssh to the server (tunneling port 8384), install syncthing, start it, open its web interface, and copy the server key-

On the local device you add a new device (the cloud system). Then you create a shared folder andshare the folder with the cloud system (this step allows you to set a password).

On the cloud system you accept the shared folder.

Done.

Frankly IMHO this is all as intuitive as it gets.

Syncing all the things

Posted Jul 13, 2021 10:24 UTC (Tue) by jezuch (subscriber, #52988) [Link] (1 responses)

I guess what I meant was: is there someone who provides a service like this so that I don't have to deal with the cloud providers myself? ;) I know I can set up an EC2 instance attached to some S3 storage, but... I really don't feel like it :)

Syncing all the things

Posted Jul 24, 2021 14:08 UTC (Sat) by vincent163 (guest, #153414) [Link]

"seedbox" is the term to search for. It's usually a cloud server with cheap storage and high bandwidth, and most managed seedboxes offer one-click installs for applications like Syncthing.

Syncing all the things

Posted Jul 16, 2021 23:17 UTC (Fri) by dilinger (subscriber, #2867) [Link] (4 responses)

I want to like syncthing, but I've been using it for a few years and it has been extremely unreliable. I use it to sync photos/videos between my phone (running LineageOS w/ syncthing from f-droid) and desktop (running Debian testing). It works seamlessly about 3/4 of the time when I take a picture and then go to my laptop to do something with the photo. The other 1/4 of the time, I end up needing to restart the syncthing daemon on my laptop, or on my phone. It's extremely irritating. Between f-droid and debian testing upgrades, I'm not sticking with a single version, so there could be any number of reasons for this instability; I never bothered to track it down. It's also pretty slow when syncing large videos, so my plan is just to migrate to something else at some point.

Syncing all the things

Posted Jul 19, 2021 19:17 UTC (Mon) by shane (subscriber, #3335) [Link] (3 responses)

Yeah I am pretty happy with Syncthing for desktops/servers, but I gave up on the Android port and now use Nextcloud for backing up photos/videos, which seems pretty reliable (although it is grumpy at a recent video I made that is more than 2 GByte....).

Syncing all the things

Posted Jul 21, 2021 18:25 UTC (Wed) by dilinger (subscriber, #2867) [Link] (2 responses)

Interesting, I'm glad to hear that Nextcloud's Android support is solid. I've been planning to try it out to replace my current setup, which is Syncthing for phone pics/videos and Seafile for file sharing with my family. I'd only delayed because I was worried about php and scalability, but it sounds like both Owncloud and Nextcloud have replaced bits of slow php code with Go and Rust, respectively.

Syncing all the things

Posted Jul 21, 2021 20:13 UTC (Wed) by smurf (subscriber, #17840) [Link] (1 responses)

Huh. Strange. I've been using Syncthing heavily for months now, including with encrypted folders, and haven't seen any problem. Nextcloud on the other hand eats my phone battery's contents for breakfast whenever I do something nontrivial.

Syncing all the things

Posted Aug 25, 2021 21:20 UTC (Wed) by dilinger (subscriber, #2867) [Link]

Perfect example today. Syncthing got an upgrade in f-droid, and I updated it yesterday on my phone. It was sitting around since then. No updates or changes on my laptop. Disk usage on my laptop is 95%. I take some pictures, come home, hours later - no sync. I restart both daemons - no sync. I finally fully shut down syncthing-gtk (after having clicked "restart daemon" earlier), and start it up again - it finally syncs.

This is a regular thing, except usually just restarting the daemon either on my phone or my laptop will make it realize that it should sync. I've got Nextcloud up and running in an LXC container, just need to set it up on my phone. I sure hope it behaves more reliably than this!

Syncing all the things

Posted Jul 24, 2021 12:45 UTC (Sat) by rolandog (subscriber, #151303) [Link] (1 responses)

One of the things I have found very useful is to configure Syncthing to have "sync only once" folders (it sends the file only one time).

In order to do that, I:

- Set a folders in a device to "send only".
- Set a folder in a different device to "receive only".
- Set the "Ignore delete" advanced option for the desired folders on *both* devices.

And that's it! I use it mainly to do some manual processing of the received photos and videos with Shotwell (*copying* and sorting my library into Year/Month/Day directories).

You may run into some issues where you may be promoted to "revert local additions" (I think on the receiver's end)... This mainly happens for two reasons:

- if you deleted a file on the receiver's "sync only once" folder
- if you use a single folder where there may be other incoming files from other synced folders.

It is best to avoid the latter scenario; a quick fix for the first one is to make sure to delete the media first in the sender's device's folder and afterwards delete it on the receiver's device's folder.

After that, you can click "revert local additions", and the message should go away.

Syncing all the things

Posted Jul 24, 2021 23:01 UTC (Sat) by monotux (guest, #130298) [Link]

> - Set the "Ignore delete" advanced option for the desired folders on *both* devices.

That was a very useful setting, thanks for taking the time to describe your workflow. I'm going to test a very similar setup on my phone as well.


Copyright © 2021, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds