Jump to content

emby user failing to write to NAS drive (CIFS) - permissions are fine


feardamhan
 Share

Recommended Posts

feardamhan

Hi Folks

I'm having some weird problems.....hoping someone can help

  • I am running emby on dietpi.
  • My NAS only supports CIFS
  • Standard install of emby - running under 'emby'
  • emby user ID is 999
  • Have the following in my fstab file

//192.168.1.1/Infrastructure /mount/infrastructure cifs guest,iocharset=utf8,uid=999,file_mode=0770,dir_mode=0770,vers=3.1.1,_netdev,nofail,noauto,x-systemd.automount

  • File system is mounted, I can see all the content
  • I can touch a file when logged in as root
  • If I do 'sudo -u emby bash' I can also view all the files and touch new files under the emby user

However if I try to get emby to scrape information to nfo files or try to get the emby configuration backup utility to backup to the mounted nas, it fails with permission denied.

  • In the case of the backup utility it is able to create the directory for the backup (so the permissions must be ok) but it fails saving profile.txt (file is created but is 0 size)
  • When creating nfo files the nfo files is created, but is also 0 size

See error report below.

Any input welcome!

*** Error Report ***
	Version: 4.5.4.0
	Command line: /opt/emby-server/system/EmbyServer.dll -programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -restartexitcode 3 -updatepackage emby-server-deb_{version}_armhf.deb
	Operating system: Linux version 5.10.11-v7+ (dom@buildbot) (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1399
	Framework: .NET Core 3.1.8
	OS/Process: arm/arm
	Runtime: opt/emby-server/system/System.Private.CoreLib.dll
	Processor count: 4
	Data path: /var/lib/emby
	Application path: /opt/emby-server/system
	System.UnauthorizedAccessException: System.UnauthorizedAccessException: Access to the path '/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-17 23.10.0 - Auto/profile.txt' is denied.
	 ---> System.IO.IOException: Permission denied
	   --- End of inner exception stack trace ---
	   at System.IO.FileStream.WriteNative(ReadOnlySpan`1 source)
	   at System.IO.FileStream.FlushWriteBuffer()
	   at System.IO.FileStream.Dispose(Boolean disposing)
	   at System.IO.Stream.Close()
	   at System.IO.StreamWriter.CloseStreamFromDispose(Boolean disposing)
	   at System.IO.StreamWriter.Dispose(Boolean disposing)
	   at System.IO.TextWriter.Dispose()
	   at System.IO.File.WriteAllText(String path, String contents)
	   at Emby.Server.Implementations.IO.ManagedFileSystem.WriteAllText(String path, String text)
	   at MBBackup.ServerEntryPoint.ExecuteBackup(BackupProfile settings, CancellationToken cancellationToken, IProgress`1 progress, Boolean isAuto)
	   at MBBackup.Entities.ScheduledBackupTask.Execute(CancellationToken cancellationToken, IProgress`1 progress)
	   at Emby.Server.Implementations.ScheduledTasks.ScheduledTaskWorker.ExecuteInternal(TaskOptions options)
	Source: System.Private.CoreLib
	TargetSite: Void WriteNative(System.ReadOnlySpan`1[System.Byte])
	InnerException: System.IO.IOException: Permission denied
	Source: 

 

Link to comment
Share on other sites

Hi there, have you taken a look at our file permissions guide?

 

Link to comment
Share on other sites

feardamhan

Yep. Been through all that before bothering you guys. The permissions seem to be functioning correctly.

emby@dietpi-server5:/mount/infrastructure/emby_config $ ls
backups  linux  test
emby@dietpi-server5:/mount/infrastructure/emby_config $ cd test/
emby@dietpi-server5:/mount/infrastructure/emby_config/test $ ls -l
total 0
drwxrwxrwx 2 emby users 0 Feb 17 17:22 'Emby Backup - 2021-02-17 17.22.57 - Auto'
drwxrwxrwx 2 emby users 0 Feb 17 22:57 'Emby Backup - 2021-02-17 22.57.7 - Auto'
drwxrwxrwx 2 emby users 0 Feb 17 23:10 'Emby Backup - 2021-02-17 23.10.0 - Auto'
drwxrwxrwx 2 emby users 0 Feb 18 09:25 'Emby Backup - 2021-02-18 09.25.24 - Auto'
emby@dietpi-server5:/mount/infrastructure/emby_config/test $ touch test.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test $ ls -l
total 0
drwxrwxrwx 2 emby users 0 Feb 17 17:22 'Emby Backup - 2021-02-17 17.22.57 - Auto'
drwxrwxrwx 2 emby users 0 Feb 17 22:57 'Emby Backup - 2021-02-17 22.57.7 - Auto'
drwxrwxrwx 2 emby users 0 Feb 17 23:10 'Emby Backup - 2021-02-17 23.10.0 - Auto'
drwxrwxrwx 2 emby users 0 Feb 18 09:25 'Emby Backup - 2021-02-18 09.25.24 - Auto'
-rwxrwxrwx 1 emby users 0 Feb 18 09:29  test.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test $ rm test.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test $ ls -l
total 0
drwxrwxrwx 2 emby users 0 Feb 17 17:22 'Emby Backup - 2021-02-17 17.22.57 - Auto'
drwxrwxrwx 2 emby users 0 Feb 17 22:57 'Emby Backup - 2021-02-17 22.57.7 - Auto'
drwxrwxrwx 2 emby users 0 Feb 17 23:10 'Emby Backup - 2021-02-17 23.10.0 - Auto'
drwxrwxrwx 2 emby users 0 Feb 18 09:25 'Emby Backup - 2021-02-18 09.25.24 - Auto'
drwxrwxrwx 2 emby users 0 Feb 18 09:29 'Emby Backup - 2021-02-18 09.29.15 - Auto'
emby@dietpi-server5:/mount/infrastructure/emby_config/test $ cd 'Emby Backup - 2021-02-18 09.29.15 - Auto'
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 09.29.15 - Auto $ ls -l
total 0
-rwxrwxrwx 1 emby users 0 Feb 18 09:29 profile.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 09.29.15 - Auto $

As you can see above, I'm operating as emby. the permissions are set to emby, and are wide open (777). I can touch a file, and remove a file.

I have the backup plugin configured to point to the 'test' directory above. It is able to create the backup subdirectory in the test folder, but the backup fails, and results in just a profile.txt of 0 bytes

The backup plugin reports this

2021-02-18 09:29:15.129 Error TaskManager: Error
	*** Error Report ***
	Version: 4.5.4.0
	Command line: /opt/emby-server/system/EmbyServer.dll -programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -restartexitcode 3 -updatepackage emby-server-deb_{version}_armhf.deb
	Operating system: Linux version 5.10.11-v7+ (dom@buildbot) (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1399
	Framework: .NET Core 3.1.8
	OS/Process: arm/arm
	Runtime: opt/emby-server/system/System.Private.CoreLib.dll
	Processor count: 4
	Data path: /var/lib/emby
	Application path: /opt/emby-server/system
	System.UnauthorizedAccessException: System.UnauthorizedAccessException: Access to the path '/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 09.29.15 - Auto/profile.txt' is denied.
	 ---> System.IO.IOException: Permission denied
	   --- End of inner exception stack trace ---
	   at System.IO.FileStream.WriteNative(ReadOnlySpan`1 source)
	   at System.IO.FileStream.FlushWriteBuffer()
	   at System.IO.FileStream.Dispose(Boolean disposing)
	   at System.IO.Stream.Close()
	   at System.IO.StreamWriter.CloseStreamFromDispose(Boolean disposing)
	   at System.IO.StreamWriter.Dispose(Boolean disposing)
	   at System.IO.TextWriter.Dispose()
	   at System.IO.File.WriteAllText(String path, String contents)
	   at Emby.Server.Implementations.IO.ManagedFileSystem.WriteAllText(String path, String text)
	   at MBBackup.ServerEntryPoint.ExecuteBackup(BackupProfile settings, CancellationToken cancellationToken, IProgress`1 progress, Boolean isAuto)
	   at MBBackup.Entities.ScheduledBackupTask.Execute(CancellationToken cancellationToken, IProgress`1 progress)
	   at Emby.Server.Implementations.ScheduledTasks.ScheduledTaskWorker.ExecuteInternal(TaskOptions options)
	Source: System.Private.CoreLib
	TargetSite: Void WriteNative(System.ReadOnlySpan`1[System.Byte])
	InnerException: System.IO.IOException: Permission denied
	Source: 
	TargetSite:

I'm replicating the issue using the backup plugin as its a faster way of testing than scanning my library every time, but when I scan the library, nfo files are 0 size and the log is strewn with similar permission denied errors to the above.

Edited by feardamhan
Link to comment
Share on other sites

Q-Droid

Do you have the correct permissions on the server side of the CIFS share for guest(?) user?

Link to comment
Share on other sites

mastrmind11

Yeah, try changing your fstab to emby instead of guest.  Not sure who guest actually is but I'd bet that is your issue

Link to comment
Share on other sites

Q-Droid

Also - are you sure your NAS supports  SMB 3.1.1? You might be trying to use CIFS extensions not supported by the NAS. Find out what SMB/CIFS version it's running and set your mount command to match. 

Link to comment
Share on other sites

feardamhan

I can certainly change all that, but doesn't the fact that I can add/edit/delete files when logged in as the emby user prove that the permissions are correct?

Link to comment
Share on other sites

feardamhan
2 hours ago, Q-Droid said:

Do you have the correct permissions on the server side of the CIFS share for guest(?) user?

Yep. When the drive is mounted, I can add/edit/delete files as root/dietpi/emby user. So permissions on CIFS side are good.

Link to comment
Share on other sites

feardamhan

As expected, even after I altered the fstab entry from guest to emby user (there is an emby user with permissions on the nas side) the same behaviour is seen ie

  • I can add/modfiy/delete files on the share when logged in as root/dietpi/emby
  • emby-server backup process can create the directories in the backup directory
  • emby-server backup process cannot save txt files created by the backup
  • emby-server scraping cannot cannot save metadata to folder (see log snippet)
*** Error Report ***
	Version: 4.5.4.0
	Command line: /opt/emby-server/system/EmbyServer.dll -programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -restartexitcode 3 -updatepackage emby-server-deb_{version}_armhf.deb
	Operating system: Linux version 5.10.11-v7+ (dom@buildbot) (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1399
	Framework: .NET Core 3.1.8
	OS/Process: arm/arm
	Runtime: opt/emby-server/system/System.Private.CoreLib.dll
	Processor count: 4
	Data path: /var/lib/emby
	Application path: /opt/emby-server/system
	System.UnauthorizedAccessException: System.UnauthorizedAccessException: Access to the path '/mount/infrastructure/dummy_data/Movies/Gladiator (2000)/Gladiator (2000).nfo' is denied.
	 ---> System.IO.IOException: Permission denied
	   --- End of inner exception stack trace ---
	   at System.IO.FileStream.WriteNative(ReadOnlySpan`1 source)
	   at System.IO.FileStream.WriteSpan(ReadOnlySpan`1 source)
	   at System.IO.FileStream.Write(Byte[] array, Int32 offset, Int32 count)
	   at System.IO.MemoryStream.CopyTo(Stream destination, Int32 bufferSize)
	   at System.IO.Stream.CopyTo(Stream destination)
	   at NfoMetadata.Savers.BaseNfoSaver.SaveToFile(Stream stream, String path)
	   at NfoMetadata.Savers.BaseNfoSaver.Save(BaseItem item, CancellationToken cancellationToken)
	   at MediaBrowser.Providers.Manager.ProviderManager.SaveMetadata(BaseItem item, LibraryOptions libraryOptions, ItemUpdateType updateType, IMetadataSaver[] savers, CancellationToken cancellationToken)
	Source: System.Private.CoreLib
	TargetSite: Void WriteNative(System.ReadOnlySpan`1[System.Byte])
	InnerException: System.IO.IOException: Permission denied
	Source: 
	TargetSite: 

 

Edited by feardamhan
Link to comment
Share on other sites

Q-Droid

Have you tried operations like cp and mv as the emby user with files that have data (non-zero byte)?

Link to comment
Share on other sites

feardamhan

All works perfectly

emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.26.49 - Auto $ ls -l
total 0
-rwxrwx--- 1 emby users 0 Feb 18 15:26 profile.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.26.49 - Auto $ cp profile.txt copy_of_profile.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.26.49 - Auto $ ls -l
total 0
-rwxrwx--- 1 emby users 0 Feb 18  2021 copy_of_profile.txt
-rwxrwx--- 1 emby users 0 Feb 18 15:26 profile.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.26.49 - Auto $ mv profile.txt renamed_profile.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.26.49 - Auto $ ls -l
total 0
-rwxrwx--- 1 emby users 0 Feb 18 15:47 copy_of_profile.txt
-rwxrwx--- 1 emby users 0 Feb 18 15:26 renamed_profile.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.26.49 - Auto $

 

Link to comment
Share on other sites

Q-Droid

I'm stumped. From the OS it looks good.

Does DietPi have systemd sandboxing enabled?

 

Link to comment
Share on other sites

feardamhan

I can also edit the zero-byte files

emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.52.49 - Auto $ ls -l
total 0
-rwxrwx--- 1 emby users 0 Feb 18 15:52 profile.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.52.49 - Auto $ vi profile.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.52.49 - Auto $ ls -l
total 1024
-rwxrwx--- 1 emby users 12 Feb 18  2021 profile.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.52.49 - Auto $

I can also (to answer your original question.....as I misread it to be manipulation of zero-byte rather than non-zero-byte) - yes I can cp and mv files to that location as emby

emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.52.49 - Auto $ ls -l
total 1024
-rwxrwx--- 1 emby users 12 Feb 18 16:01 profile.txt
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.52.49 - Auto $ cp /mount/infrastructure/software/STBEditor_V1.7.2_652HD.exe ./
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.52.49 - Auto $ ls -l
total 2048
-rwxrwx--- 1 emby users     12 Feb 18 16:01 profile.txt
-rwxrwx--- 1 emby users 577536 Feb 18  2021 STBEditor_V1.7.2_652HD.exe
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.52.49 - Auto $ mv STBEditor_V1.7.2_652HD.exe renamed.exe
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.52.49 - Auto $ ls -l
total 2048
-rwxrwx--- 1 emby users     12 Feb 18 16:01 profile.txt
-rwxrwx--- 1 emby users 577536 Feb 18 16:02 renamed.exe
emby@dietpi-server5:/mount/infrastructure/emby_config/test/Emby Backup - 2021-02-18 15.52.49 - Auto $

 

Link to comment
Share on other sites

feardamhan
4 minutes ago, Q-Droid said:

I'm stumped. From the OS it looks good.

Does DietPi have systemd sandboxing enabled?

 

Honestly dont know anything about sandboxing, but happy to learn if it helps resolve. Can you point me at what I need to learn?

Edited by feardamhan
Link to comment
Share on other sites

Q-Droid

Google "Arch Linux emby", same basic concept for filesystem access. I don't know if dietpi needs the same. If so then adjust for your config. 

 

Link to comment
Share on other sites

feardamhan

Are you suggesting I should do something like this? 

/etc/systemd/system/emby-server.service.d/write-permissions.conf
[Service]
SupplementaryGroups=media
ReadWritePaths=/mnt/media_files
UMask=0002

Assuming I create new group called media?

Link to comment
Share on other sites

Q-Droid

You should be able to keep current runtime group, no supplemental entry and no need to change existing ownership. 

Adding the group would allow for multiuser group level permissions on new files. 

Try it, I don't have anything to test it myself. 

 

Link to comment
Share on other sites

feardamhan

Im not sure this really works with a mounted nas drive vs local storage. To get the permissions to change for the mount point I need to alter the fstab. So I think this just does the same as before except with the media group in place of the users group.

I'm puzzled. This all seems to have happened since some updates via dietpi. I'm troubleshooting if from that aspect too. I might try a basic raspbian deployment on the box and see if that behaves differently

 

Edited by feardamhan
Link to comment
Share on other sites

Q-Droid

Don't change permissions or ownership, just add the readwritepaths option and the umask. The goal is to allow systemd managed process to access the path, not change the existing attributes. 

It's possible that dietpi enabled sandboxing by default at some point. 

Link to comment
Share on other sites

feardamhan

I installed Raspberry Pi OS / cifs utils and emby - and its working fine.

So its something to do with dietpi!

I continue to dig.....

  • Like 1
Link to comment
Share on other sites

feardamhan

So I'm not exactly sure if this is relevant, but it feels like it might be

When emby is installed on dietpi, its entry in /etc/passwd looks like this

emby:x:999:1000:Emby Server:/var/lib/emby:/usr/sbin/nologin

Where 1000 is the dietpi group (/etc/group)

dietpi:x:1000:
lightdm:x:111:
mysql:x:113:
emby:x:995:emby

The user is part of the emby group, but its not its primary group

root@dietpi-server5:/mount# id emby
uid=999(emby) gid=1000(dietpi) groups=1000(dietpi),44(video),107(render),995(emby)

On a Raspberry Pi install, the emby user in /etc/passwd looks like this

emby:x:999:995:Emby Server:/var/lib/emby:/usr/bin/nologin

And the user looks like this

pi@raspberrypi:~ $ id emby
uid=999(emby) gid=995(emby) groups=995(emby),44(video),107(render)

 

Link to comment
Share on other sites

Q-Droid

Not likely to be relevant. The files were being created with emby:users ownership and you'll notice that neither includes "users", which is coming from the SMB/CIFS options.

Link to comment
Share on other sites

Mibok

This sound too familiar, i had a similar problem not long ago with my Centos server in the beta release, tried so many things and could not fix this. This was while i was transitioning to Ubuntu so ended up prioritizing the migration. In mi case is likely that a OS update broke something. I'm adding the link to that post in case that some of my test could help you. https://emby.media/community/index.php?/topic/93269-46010-not-downloading-metada-nor-images-in-media-folders/&tab=comments#comment-969970

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...