alexbelgium / hassio-addons

My homeassistant addons
MIT License
1.58k stars 226 forks source link

🐛 [.templates/92-local_mounts.sh] Mounting ext4 with invalid options (gid,uid) #755

Closed pmtk closed 1 year ago

pmtk commented 1 year ago

Which addon?

Describe the bug

92-local_mounts.sh tries to mount ext4 with invalid options which results in error and failure to mount the device and start the container (following is an output where I modified the script to hardcode sda1 as localdevice and add set -x before mount):

root@db21ed7f-qbittorrent:/tmp$ ./92-local_mounts.sh
Local Disks mounting...
[09:20:17] INFO: Mounting sda1 of type ext4
Using PUID 0 and PGID 0
++ mount -t auto /dev/sda1 /mnt/sda1 -o nosuid,relatime,noexec,uid=0,gid=0
mount: mounting /dev/sda1 on /mnt/sda1 failed: Invalid argument
++ bashio::log.fatal 'Unable to mount local drives! Please check the name.'
...

if I remove uid and gid it runs successfully:

root@db21ed7f-qbittorrent:/tmp$ mount -t auto /dev/sda1 /mnt/sda1 -o nosuid,relatime,noexec
root@db21ed7f-qbittorrent:/tmp$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0   1.8T  0 disk 
└─sda1        8:1    0   1.8T  0 part /mnt/sda1

https://man7.org/linux/man-pages/man5/ext4.5.html does not list gid or uid as a possible options (similar thing for xfs)

To Reproduce

Configure any (?) addon to try mounting ext4 disk with localdisks stanza

Full addon log

[migrations] started
[migrations] no migrations found
cont-init: info: running /etc/cont-init.d/00-banner.sh
-----------------------------------------------------------
 Add-on: Qbittorrent
 qBittorrent is a bittorrent client
-----------------------------------------------------------
───────────────────────────────────────
      ██╗     ███████╗██╗ ██████╗ 
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║      
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝ 
   Brought to you by linuxserver.io
───────────────────────────────────────
To support LSIO projects visit:
https://www.linuxserver.io/donate/
───────────────────────────────────────
GID/UID
───────────────────────────────────────
User UID:    0
User GID:    0
───────────────────────────────────────
 Add-on version: 4.5.2-r0-ls250-2
 You are running the latest version of this add-on.
 System: Home Assistant OS 9.5  (amd64 / generic-x86-64)
 Home Assistant Core: 2023.3.3
 Home Assistant Supervisor: 2023.03.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums
 https://github.com/alexbelgium/hassio-addons
-----------------------------------------------------------
cont-init: info: /etc/cont-init.d/00-banner.sh exited 0
cont-init: info: running /etc/cont-init.d/00-folders.sh
cont-init: info: /etc/cont-init.d/00-folders.sh exited 0
cont-init: info: running /etc/cont-init.d/01-custom_script.sh
[09:34:24] INFO: Execute /config/addons_autoscripts/qbittorrent.sh if existing
[09:34:24] INFO: ... no script found
cont-init: info: /etc/cont-init.d/01-custom_script.sh exited 0
cont-init: info: running /etc/cont-init.d/30-nginx.sh
cont-init: info: /etc/cont-init.d/30-nginx.sh exited 0
cont-init: info: running /etc/cont-init.d/90-dns_set.sh
[09:34:25] INFO: DNS SERVERS set to 1.1.1.1 8.8.8.8 
cont-init: info: /etc/cont-init.d/90-dns_set.sh exited 0
cont-init: info: running /etc/cont-init.d/91-qbittorrent_configuration.sh
sed: unmatched '='
[09:34:25] INFO: Downloads can be found in /share/qBittorrent
[09:34:25] INFO: Whitelisted subsets will not require a password : localhost,127.0.0.1,172.30.0.0/16,192.168.0.0/16
[09:34:25] INFO: WEBUI username set to admin
[09:34:25] INFO: Alternate UI enabled : vuetorrent. If webui don't work, disable this option
[09:34:26] INFO: Default username/password : admin/adminadmin
[09:34:26] INFO: Configuration can be found in /config/addons_config/qBittorrent
cont-init: info: /etc/cont-init.d/91-qbittorrent_configuration.sh exited 0
cont-init: info: running /etc/cont-init.d/92-local_mounts.sh
Local Disks mounting...
[09:34:27] INFO: Mounting sda1 of type ext4
Using PUID 0 and PGID 0
mount: mounting /dev/sda1 on /mnt/sda1 failed: Invalid argument
[09:34:27] FATAL: Unable to mount local drives! Please check the name.
[09:34:27] INFO: List of available labels (@dianlight)
---------------------------------------------------
[09:34:27] INFO: Available Disk Labels:
[09:34:27] INFO:    ssd_2tb_data[
ext4
squashfs]
---------------------------------------------------

Full addon config

DNS_server: 8.8.8.8,1.1.1.1
PGID: "0"
PUID: "0"
SavePath: /share/qBittorrent
Username: admin
certfile: fullchain.pem
customUI: vuetorrent
keyfile: privkey.pem
ssl: false
whitelist: localhost,127.0.0.1,172.30.0.0/16,192.168.0.0/16
localdisks: sda1

System

Home Assistant 2023.3.3
Supervisor 2023.03.1
Operating System 9.5
alexbelgium commented 1 year ago

Thanks for the bug report and very detailed analysis. Actually that's strange as I mount it in the same configuration, and with the same system config. I'll investigate what could be the cause.

Action list :

alexbelgium commented 1 year ago

I can't replicate the sed: unmatched '=' on my system, would you have a = somewhere in your addon options? Perhaps I need to sanitize my code to avoid interference, thanks

Crazy thing is that I can't replicate the error message on ext4 either, but you are fully right about uid/gid not being supported

alexbelgium commented 1 year ago

For the sed error I've understood and modified

pmtk commented 1 year ago

Thanks for quick response!

About the sed issue, it happens for me when I restart the addon, e.g.:

First start, config is created

[migrations] started
[migrations] no migrations found
cont-init: info: running /etc/cont-init.d/00-banner.sh
-----------------------------------------------------------
 Add-on: Qbittorrent
 qBittorrent is a bittorrent client
-----------------------------------------------------------
───────────────────────────────────────
      ██╗     ███████╗██╗ ██████╗ 
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║      
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝ 
   Brought to you by linuxserver.io
───────────────────────────────────────
To support LSIO projects visit:
https://www.linuxserver.io/donate/
───────────────────────────────────────
GID/UID
───────────────────────────────────────
User UID:    0
User GID:    0
───────────────────────────────────────
 Add-on version: 4.5.2-r0-ls250-3
 You are running the latest version of this add-on.
 System: Home Assistant OS 9.5  (amd64 / generic-x86-64)
 Home Assistant Core: 2023.3.3
 Home Assistant Supervisor: 2023.03.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums
 https://github.com/alexbelgium/hassio-addons
-----------------------------------------------------------
cont-init: info: /etc/cont-init.d/00-banner.sh exited 0
cont-init: info: running /etc/cont-init.d/00-folders.sh
cont-init: info: /etc/cont-init.d/00-folders.sh exited 0
cont-init: info: running /etc/cont-init.d/01-custom_script.sh
[12:44:21] INFO: Execute /config/addons_autoscripts/qbittorrent.sh if existing
[12:44:21] INFO: ... no script found
cont-init: info: /etc/cont-init.d/01-custom_script.sh exited 0
cont-init: info: running /etc/cont-init.d/30-nginx.sh
cont-init: info: /etc/cont-init.d/30-nginx.sh exited 0
cont-init: info: running /etc/cont-init.d/90-dns_set.sh
[12:44:22] INFO: DNS SERVERS set to 1.1.1.1 8.8.8.8 
cont-init: info: /etc/cont-init.d/90-dns_set.sh exited 0
cont-init: info: running /etc/cont-init.d/91-qbittorrent_configuration.sh
[12:44:22] INFO: Downloads can be found in /share/qBittorrent
[12:44:22] INFO: Whitelisted subsets will not require a password : localhost,127.0.0.1,172.30.0.0/16,192.168.0.0/16
[12:44:22] INFO: WEBUI username set to admin
[12:44:22] INFO: Alternate UI enabled : vuetorrent. If webui don't work, disable this option
[12:44:24] INFO: Default username/password : admin/adminadmin
[12:44:24] INFO: Configuration can be found in /config/addons_config/qBittorrent
cont-init: info: /etc/cont-init.d/91-qbittorrent_configuration.sh exited 0
cont-init: info: running /etc/cont-init.d/92-local_mounts.sh
cont-init: info: /etc/cont-init.d/92-local_mounts.sh exited 0
cont-init: info: running /etc/cont-init.d/92-smb_mounts.sh
cont-init: info: /etc/cont-init.d/92-smb_mounts.sh exited 0
cont-init: info: running /etc/cont-init.d/93-openvpn.sh
[12:44:25] INFO: Direct connection without VPN enabled
cont-init: info: /etc/cont-init.d/93-openvpn.sh exited 0
[custom-init] No custom files found, skipping...
WebUI will be started shortly after internal preparations. Please wait...
services-up: info: copying legacy longrun nginx (no readiness notification)
[ls.io-init] done.
[12:44:26] INFO: Starting NGinx...

After addon restart

[migrations] started
[migrations] no migrations found
cont-init: info: running /etc/cont-init.d/00-banner.sh
-----------------------------------------------------------
 Add-on: Qbittorrent
 qBittorrent is a bittorrent client
-----------------------------------------------------------
───────────────────────────────────────
      ██╗     ███████╗██╗ ██████╗ 
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║      
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝ 
   Brought to you by linuxserver.io
───────────────────────────────────────
To support LSIO projects visit:
https://www.linuxserver.io/donate/
───────────────────────────────────────
GID/UID
───────────────────────────────────────
User UID:    0
User GID:    0
───────────────────────────────────────
 Add-on version: 4.5.2-r0-ls250-3
 You are running the latest version of this add-on.
 System: Home Assistant OS 9.5  (amd64 / generic-x86-64)
 Home Assistant Core: 2023.3.3
 Home Assistant Supervisor: 2023.03.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums
 https://github.com/alexbelgium/hassio-addons
-----------------------------------------------------------
cont-init: info: /etc/cont-init.d/00-banner.sh exited 0
cont-init: info: running /etc/cont-init.d/00-folders.sh
cont-init: info: /etc/cont-init.d/00-folders.sh exited 0
cont-init: info: running /etc/cont-init.d/01-custom_script.sh
[12:45:01] INFO: Execute /config/addons_autoscripts/qbittorrent.sh if existing
[12:45:01] INFO: ... no script found
cont-init: info: /etc/cont-init.d/01-custom_script.sh exited 0
cont-init: info: running /etc/cont-init.d/30-nginx.sh
cont-init: info: /etc/cont-init.d/30-nginx.sh exited 0
cont-init: info: running /etc/cont-init.d/90-dns_set.sh
[12:45:01] INFO: DNS SERVERS set to 1.1.1.1 8.8.8.8 
cont-init: info: /etc/cont-init.d/90-dns_set.sh exited 0
cont-init: info: running /etc/cont-init.d/91-qbittorrent_configuration.sh
sed: unmatched '='
cont-init: info: /etc/cont-init.d/91-qbittorrent_configuration.sh exited 1
cont-init: info: running /etc/cont-init.d/92-local_mounts.sh
cont-init: info: /etc/cont-init.d/92-local_mounts.sh exited 0
cont-init: info: running /etc/cont-init.d/92-smb_mounts.sh
cont-init: info: /etc/cont-init.d/92-smb_mounts.sh exited 0
cont-init: info: running /etc/cont-init.d/93-openvpn.sh
[12:45:02] INFO: Direct connection without VPN enabled
cont-init: info: /etc/cont-init.d/93-openvpn.sh exited 0
cont-init: warning: some scripts exited nonzero
s6-rc: warning: unable to start service legacy-cont-init: command exited 1
/run/s6/basedir/scripts/rc.init: warning: s6-rc failed to properly bring all the services up! Check your logs (in /run/uncaught-logs/current if you have in-container logging) for more information.
prog: fatal: stopping the container

qBittorrent.conf

[AutoRun]
Session\DefaultSavePath=/share/qBittorrent
enabled=false
program=

[BitTorrent]
Session\DefaultSavePath=/share/qBittorrent
Session\Port=59595
Session\QueueingSystemEnabled=true
Session\TempPath=/share/qBittorrentincomplete/

[LegalNotice]
Accepted=true
WebUI\Address=*
WebUI\AlternativeUIEnabled=true
WebUI\AuthSubnetWhitelist=localhost, 127.0.0.1, 172.30.0.0/16, 192.168.0.0/16
WebUI\AuthSubnetWhitelistEnabled=true
WebUI\CSRFProtection=false
WebUI\ClickjackingProtection=false
WebUI\HostHeaderValidation=false
WebUI\RootFolder=/webui/vuetorrent/vuetorrent
WebUI\Username=admin

[Meta]
MigrationVersion=4

[Network]
Cookies=@Invalid()
PortForwardingEnabled=false

[Preferences]
Connection\PortRangeMin=59595
Connection\UPnP=false
Downloads\SavePath=/share/qBittorrent
Downloads\TempPath=/share/qBittorrentincomplete/
WebUI\Address=*
WebUI\LocalHostAuth=false
WebUI\Port=8080
WebUI\ServerDomains=*
alexbelgium commented 1 year ago

I must say I can't replicate even with your qBittorrent.conf file so it's hard to solve. I've pushed a new version with updated sed code, could you please check ? Thanks

pmtk commented 1 year ago

It works now, thank you very much! :)

alexbelgium commented 1 year ago

Thanks for helping improve the code