Skip to content

Files “created” by Syncthing ignore UMask (.stfolder and .stversions) #9626

Closed

Description

@xitoshi

What happened?

I am using Syncthing as a systemd service on a Raspberry Pi with Raspbian. I have set it up so it’s run by a syncthing user, but to keep access to all users in the group I’ve set the UMask parameter to 0002 in the [email protected] and for good measure in the .bash_rc, .bash_pofile and .profile files for that user.

Setting umask in the service file works correctly for synchronization, but Syncthing seems to ignore it when the files are “created” by Syncthing itself and not synchronized. I’ve noticed this happening both in .stfolder and subfiles (when a new synchronization folder is created) and the .stversions and subfolders (only directories, not files).

E.g.: Creating a new, still unshared folder through the web GUI:

pi@raspberrypi:/media/data/Sync $ ls TEST/ -ld
drwxrwsr-x 3 syncthing drive-users 4096 Aug  3 00:10 TEST/
pi@raspberrypi:/media/data/Sync $ ls TEST/ -lAR
TEST/:
total 4
drwxr-sr-x 2 syncthing drive-users 4096 Aug  3 00:10 .stfolder

TEST/.stfolder:
total 4
-rw-r--r-- 1 syncthing drive-users 117 Aug  3 00:10 syncthing-folder-ccaee1.txt

As for .stversions, I use “Simple” file versioning, and when I remove files the .stversions folder and any subfolders are created without group writing permissions, seemingly ignoring the umask. The files keep the writing permission, but without the folder writing permission I can’t delete them.

E.g.: Note that in this folder I have turned on “Ignore Permissions”. Also, in this case .stfolder has group write permission set manually.

pi@raspberrypi:/media/data/Sync/Linux-Documents $ ls -lAR
.:
total 8
drwxrwsr-x 2 syncthing drive-users 4096 Aug  2 23:54 'New Folder'
drwxrwsr-x 2 syncthing drive-users 4096 May  7 22:56  .stfolder

'./New Folder':
total 4
-rw-rw-r-- 1 syncthing drive-users 2 Aug  2 23:54 'Text File.txt'

./.stfolder:
total 0
pi@raspberrypi:/media/data/Sync/Linux-Documents $ ls -lAR
.:
total 8
drwxrwsr-x 2 syncthing drive-users 4096 May  7 22:56 .stfolder
drwxr-sr-x 3 syncthing drive-users 4096 Aug  2 23:55 .stversions

./.stfolder:
total 0

./.stversions:
total 4
drwxr-sr-x 2 syncthing drive-users 4096 Aug  2 23:55 'New Folder'

'./.stversions/New Folder':
total 4
-rw-rw-r-- 1 syncthing drive-users 2 Aug  2 23:54 'Text File~20240802-235507.txt'
pi@raspberrypi:/media/data/Sync/Linux-Documents $ rm .stversions/New\ Folder/Text\ File~20240802-235507.txt
rm: cannot remove '.stversions/New Folder/Text File~20240802-235507.txt': Permission denied

For more information, here is my service file:

$ cat /lib/systemd/system/[email protected] 
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %I
Documentation=man:syncthing(1)
After=network.target

[Service]
User=%i
ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
UMask=0002

# Hardening
ProtectSystem=full
PrivateTmp=true
SystemCallArchitectures=native
MemoryDenyWriteExecute=true
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

I have brought up this problem on the forum as well, where @calmh identified it as a bug:

You’re right, mkdirs in the versioner code use 0755 as the base permissions, so umask won’t help there (to get group write). Please feel free to file an issue on this, and perhaps a fix :slight_smile:

Probably the real fix would be to grab the permissions from the corresponding directory in the synced folder.

Syncthing version

syncthing v1.27.9 "Gold Grasshopper" (go1.22.4 linux-arm) [email protected] 2024-07-01 03:45:16 UTC [noupgrade]

Platform & operating system

Raspbian GNU/Linux 11 (bullseye)

Browser version

No response

Relevant log output

No response

Activity

  1. added
    bug
    needs-triage
    on Aug 4, 2024
  2. removed
    needs-triage
    on Aug 4, 2024
  3. thegasta commented on Apr 5, 2025

    @thegasta

    Same problem in my debian 12 server.
    Syncthing version seems to be indifferent, I'm still facing this issue on 1.29.4.
    I'm using the default systemd unit file shipped with syncthing.

    Default folder settings:
    Image

    From now on, all actions/commands are done with syncthing user.
    Syncthing data folder permissions and ACL (let's call it datadir):
    (reminder: with getfacl -t capital letter means 'not effective')

    drwxrwx---+ 56 root      root       56 Apr  5 12:32 .
    
    > getfacl -t .
    # file: .
    USER   root       rwx  rwx
    user   syncthing  rwx  rwx
    GROUP  root       r-x  r-x
    group  syncthing  r-x  r-x
    mask              rwx  rwx
    other             ---  ---
    

    When creating a dir from the console (datadir/test-from-console) or from the GUI (datadir/test-from-gui) everything works, in particular you can see that mask is kept as rwx.
    When creating the folder from another Syncthing device (datadir/test-from-other-device, shared by default with the server), the mask is set to ---.
    Same happens with (datadir/test-from-other-device-no-ignore-perm, shared by default with the server), to do this test I disabled Ignore permissions in default folder settings.

    drwxrwx---+  2 syncthing syncthing   2 Apr  5 13:55 test-from-console
    drwxrwx---+  3 syncthing syncthing   3 Apr  5 13:05 test-from-gui
    drwx------+  3 syncthing syncthing   4 Apr  5 13:10 test-from-other-device
    
    root@pve1:/pve1-raidz/pve1-data1# getfacl -t test-from-*
    # file: test-from-console
    USER   syncthing  rwx  rwx
    user   syncthing  rwx  rwx
    GROUP  syncthing  r-x  r-x
    group  syncthing  r-x  r-x
    mask              rwx  rwx
    other             ---  ---
    
    # file: test-from-gui1
    USER   syncthing  rwx  rwx
    user   syncthing  rwx  rwx
    GROUP  syncthing  r-x  r-x
    group  syncthing  r-x  r-x
    mask              rwx  rwx
    other             ---  ---
    
    # file: test-from-other-device
    USER   syncthing  rwx  rwx
    user   syncthing  RWX  rwx                  << capital letter means 'not effective'
    GROUP  syncthing  R-X  r-x
    group  syncthing  R-X  r-x
    mask              ---  rwx                  << notice the mask not following default
    other             ---  ---
    
    # file: from-other-device-no-ignore-perm
    USER   syncthing  rwx  rwx
    user   syncthing  RWX  rwx
    GROUP  syncthing  R-X  r-x
    group  syncthing  R-X  r-x
    mask              ---  rwx
    other             ---  ---
    

    In the same way I tried with files, from-*.txt file names indicate from where they were created.
    Below the details within the problematic folder:

    > getfacl -tR test-from-other-device
    # dir omitted, just shown above
    
    # file: test-from-other-device/.stfolder
    USER   syncthing  rwx  rwx
    user   syncthing  rWx  rwx
    GROUP  syncthing  r-x  r-x
    group  syncthing  r-x  r-x
    mask              r-x  rwx
    other             ---  ---
    
    # file: test-from-other-device/.stfolder/syncthing-folder-181db0.txt
    USER   syncthing  rw-     
    user   syncthing  rWX     
    GROUP  syncthing  r-X     
    group  syncthing  r-X     
    mask              r--     
    other             ---     
    
    # file: test-from-other-device/.stignore
    USER   syncthing  rw-     
    user   syncthing  RWX     
    GROUP  syncthing  R-X     
    group  syncthing  R-X     
    mask              ---     
    other             ---     
    
    # file: test-from-other-device/from-console.txt
    USER   syncthing  rw-     
    user   syncthing  rwX     
    GROUP  syncthing  r-X     
    group  syncthing  r-X     
    mask              rw-     
    other             ---     
    
    # file: test-from-other-device/from-console-root.txt
    USER   root       rw-     
    user   syncthing  rwX     
    GROUP  root       r-X     
    group  syncthing  r-X     
    mask              rw-     
    other             ---     
    
    # file: test-from-other-device/from-other-device.txt
    USER   syncthing  rw-     
    user   syncthing  rwX     
    GROUP  syncthing  r-X     
    group  syncthing  r-X     
    mask              rw-     
    other             ---     
    

    Conclusion:
    the problem seems to be related only to folders received (auto-accepted or not).

  4. added a commit that references this issue on May 12, 2025
    db699a6
  5. added a commit that references this issue on May 24, 2025
    1a131a5
  6. added 2 commits that reference this issue on May 25, 2025
    39d6692
    59a84b4
  7. added a commit that references this issue on Jun 8, 2025
    8b3462a
  8. added
    frozen-due-to-age
    on Jul 1, 2026
  9. locked and limited conversation to collaborators on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfrozen-due-to-age

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions